--- a/gameServer/HWProtoNEState.hs Fri Sep 04 07:04:27 2009 +0000
+++ b/gameServer/HWProtoNEState.hs Fri Sep 04 12:48:44 2009 +0000
@@ -26,22 +26,20 @@
where
client = clients IntMap.! clID
haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients
- checkPassword = if clientProto client /= 0 then [CheckRegistered] else []
+ checkPassword = [CheckRegistered | clientProto client /= 0]
-handleCmd_NotEntered clID clients _ ["PROTO", protoNum] =
- if clientProto client > 0 then
- [ProtocolError "Protocol already known"]
- else if parsedProto == 0 then
- [ProtocolError "Bad number"]
- else
- [ModifyClient (\c -> c{clientProto = parsedProto}),
+handleCmd_NotEntered clID clients _ ["PROTO", protoNum]
+ | clientProto client > 0 = [ProtocolError "Protocol already known"]
+ | parsedProto == 0 = [ProtocolError "Bad number"]
+ | otherwise =
+ [ModifyClient (\ c -> c{clientProto = parsedProto}),
AnswerThisClient ["PROTO", show parsedProto]]
++ checkPassword
where
client = clients IntMap.! clID
parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16)
- checkPassword = if (not . null) (nick client) then [CheckRegistered] else []
+ checkPassword = [CheckRegistered | (not . null) (nick client)]
handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] =
@@ -52,7 +50,7 @@
[ByeClient "Authentication failed"]
where
client = clients IntMap.! clID
- adminNotice = if isAdministrator client then [AnswerThisClient ["ADMIN_ACCESS"]] else []
+ adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client]
--handleCmd_NotEntered _ _ _ ["DUMP"] =
--- a/gameServer/ServerCore.hs Fri Sep 04 07:04:27 2009 +0000
+++ b/gameServer/ServerCore.hs Fri Sep 04 12:48:44 2009 +0000
@@ -17,7 +17,7 @@
timerLoop :: Int -> Chan CoreMessage -> IO()
-timerLoop tick messagesChan = threadDelay (30 * 10^6) >> (writeChan messagesChan $ TimerAction tick) >> timerLoop (tick + 1) messagesChan
+timerLoop tick messagesChan = threadDelay (30 * 10^6) >> writeChan messagesChan (TimerAction tick) >> timerLoop (tick + 1) messagesChan
firstAway (_, a, b, c) = (a, b, c)
@@ -31,7 +31,7 @@
(newServerInfo, mClients, mRooms) <-
case r of
- Accept ci -> do
+ Accept ci ->
liftM firstAway $ processAction
(clientUID ci, serverInfo, clients, rooms) (AddClient ci)
@@ -57,7 +57,7 @@
TimerAction tick ->
liftM firstAway $
foldM processAction (0, serverInfo, clients, rooms) $
- PingAll : if even tick then [StatsAction] else []
+ PingAll : [StatsAction | even tick]
{- let hadRooms = (not $ null rooms) && (null mrooms)
@@ -80,7 +80,7 @@
forkIO $ timerLoop 0 $ coreChan serverInfo
- startDBConnection $ serverInfo
+ startDBConnection serverInfo
forkIO $ mainLoop serverInfo IntMap.empty (IntMap.singleton 0 newRoom)
--- a/gameServer/Utils.hs Fri Sep 04 07:04:27 2009 +0000
+++ b/gameServer/Utils.hs Fri Sep 04 12:48:44 2009 +0000
@@ -12,6 +12,7 @@
import Network.Socket
import System.IO
import qualified Data.List as List
+import Control.Monad
import Maybe
-------------------------------------------------
import qualified Codec.Binary.Base64 as Base64
@@ -30,7 +31,7 @@
toEngineMsg msg = Base64.encode (fromIntegral (length msg) : (UTF8.encode msg))
fromEngineMsg :: String -> Maybe String
-fromEngineMsg msg = Base64.decode msg >>= removeLength >>= return . (map w2c)
+fromEngineMsg msg = liftM (map w2c) (Base64.decode msg >>= removeLength)
where
removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing
removeLength _ = Nothing
@@ -43,7 +44,7 @@
test (Just (m:ms)) = m `Set.member` legalMessages
test _ = False
legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghb12345" ++ slotMessages
- slotMessages = ['\128', '\129', '\130', '\131', '\132', '\133', '\134', '\135', '\136', '\137', '\138']
+ slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"
maybeRead :: Read a => String -> Maybe a
maybeRead s = case reads s of
@@ -74,7 +75,7 @@
t : replaceTeam team teams
illegalName :: String -> Bool
-illegalName str = all isSpace str
+illegalName = all isSpace
protoNumber2ver :: Word16 -> String
protoNumber2ver 17 = "0.9.7-dev"
--- a/gameServer/hedgewars-server.hs Fri Sep 04 07:04:27 2009 +0000
+++ b/gameServer/hedgewars-server.hs Fri Sep 04 12:48:44 2009 +0000
@@ -53,5 +53,5 @@
Exception.bracket
(Network.listenOn $ Network.PortNumber $ listenPort serverInfo)
- (sClose)
+ sClose
(startServer serverInfo)