Allow only one query per session
authorunc0rr
Mon, 28 Dec 2015 09:06:29 +0300
changeset 11464 a9957113404a
parent 11463 fe46826de291
child 11465 0ae2e4c13bd1
Allow only one query per session
gameServer/CoreTypes.hs
gameServer/HWProtoLobbyState.hs
gameServer/NetRoutines.hs
--- a/gameServer/CoreTypes.hs	Mon Dec 28 08:43:38 2015 +0300
+++ b/gameServer/CoreTypes.hs	Mon Dec 28 09:06:29 2015 +0300
@@ -126,32 +126,33 @@
 data ClientInfo =
     ClientInfo
     {
-        clUID :: Unique,
-        sendChan :: ClientChan,
-        clientSocket :: Socket,
-        host :: B.ByteString,
-        connectTime :: UTCTime,
-        nick :: B.ByteString,
-        webPassword :: B.ByteString,
-        serverSalt :: B.ByteString,
-        logonPassed :: Bool,
-        isVisible :: Bool,
+        clUID :: !Unique,
+        sendChan :: !ClientChan,
+        clientSocket :: !Socket,
+        host :: !B.ByteString,
+        connectTime :: !UTCTime,
+        nick :: !B.ByteString,
+        webPassword :: !B.ByteString,
+        serverSalt :: !B.ByteString,
+        logonPassed :: !Bool,
+        isVisible :: !Bool,
         clientProto :: !Word16,
         pingsQueue :: !Word,
-        isMaster :: Bool,
+        isMaster :: !Bool,
         isReady :: !Bool,
-        isInGame :: Bool,
-        isAdministrator :: Bool,
-        isChecker :: Bool,
-        isContributor :: Bool,
-        isKickedFromServer :: Bool,
-        isJoinedMidGame :: Bool,
+        isInGame :: !Bool,
+        isAdministrator :: !Bool,
+        isChecker :: !Bool,
+        isContributor :: !Bool,
+        isKickedFromServer :: !Bool,
+        isJoinedMidGame :: !Bool,
+        hasAskedList :: !Bool,
         clientClan :: !(Maybe B.ByteString),
-        checkInfo :: Maybe CheckInfo,
+        checkInfo :: !(Maybe CheckInfo),
         eiLobbyChat,
         eiEM,
-        eiJoin :: EventsInfo,
-        teamsInGame :: Word
+        eiJoin :: !EventsInfo,
+        teamsInGame :: !Word
     }
 
 instance Eq ClientInfo where
@@ -164,17 +165,17 @@
 data TeamInfo =
     TeamInfo
     {
-        teamowner :: B.ByteString,
-        teamname :: B.ByteString,
-        teamcolor :: B.ByteString,
-        teamgrave :: B.ByteString,
-        teamfort :: B.ByteString,
-        teamvoicepack :: B.ByteString,
-        teamflag :: B.ByteString,
-        isOwnerRegistered :: Bool,
-        difficulty :: Int,
-        hhnum :: Int,
-        hedgehogs :: [HedgehogInfo]
+        teamowner :: !B.ByteString,
+        teamname :: !B.ByteString,
+        teamcolor :: !B.ByteString,
+        teamgrave :: !B.ByteString,
+        teamfort :: !B.ByteString,
+        teamvoicepack :: !B.ByteString,
+        teamflag :: !B.ByteString,
+        isOwnerRegistered :: !Bool,
+        difficulty :: !Int,
+        hhnum :: !Int,
+        hedgehogs :: ![HedgehogInfo]
     }
     deriving (Show, Read)
 
@@ -214,26 +215,26 @@
 data RoomInfo =
     RoomInfo
     {
-        masterID :: Maybe ClientIndex,
-        name :: B.ByteString,
-        password :: B.ByteString,
-        roomProto :: Word16,
-        teams :: [TeamInfo],
-        gameInfo :: Maybe GameInfo,
+        masterID :: !(Maybe ClientIndex),
+        name :: !B.ByteString,
+        password :: !B.ByteString,
+        roomProto :: !Word16,
+        teams :: ![TeamInfo],
+        gameInfo :: !(Maybe GameInfo),
         playersIn :: !Int,
         readyPlayers :: !Int,
-        isRestrictedJoins :: Bool,
-        isRestrictedTeams :: Bool,
-        isRegisteredOnly :: Bool,
-        isSpecial :: Bool,
-        defaultHedgehogsNumber :: Int,
-        teamsNumberLimit :: Int,
-        greeting :: B.ByteString,
-        voting :: Maybe Voting,
+        isRestrictedJoins :: !Bool,
+        isRestrictedTeams :: !Bool,
+        isRegisteredOnly :: !Bool,
+        isSpecial :: !Bool,
+        defaultHedgehogsNumber :: !Int,
+        teamsNumberLimit :: !Int,
+        greeting :: !B.ByteString,
+        voting :: !(Maybe Voting),
         roomBansList :: ![B.ByteString],
-        mapParams :: Map.Map B.ByteString B.ByteString,
-        params :: Map.Map B.ByteString [B.ByteString],
-        roomSaves :: Map.Map B.ByteString (Map.Map B.ByteString B.ByteString, Map.Map B.ByteString [B.ByteString])
+        mapParams :: !(Map.Map B.ByteString B.ByteString),
+        params :: !(Map.Map B.ByteString [B.ByteString]),
+        roomSaves :: !(Map.Map B.ByteString (Map.Map B.ByteString B.ByteString, Map.Map B.ByteString [B.ByteString]))
     }
 
 newRoom :: RoomInfo
--- a/gameServer/HWProtoLobbyState.hs	Mon Dec 28 08:43:38 2015 +0300
+++ b/gameServer/HWProtoLobbyState.hs	Mon Dec 28 09:06:29 2015 +0300
@@ -34,7 +34,14 @@
 handleCmd_lobby :: CmdHandler
 
 
-handleCmd_lobby ["LIST"] = return []
+handleCmd_lobby ["LIST"] = do
+    (ci, irnc) <- ask
+    let cl = irnc `client` ci
+    rooms <- allRoomInfos
+    let roomsInfoList = concatMap (\r -> roomInfo (clientProto cl) (maybeNick . liftM (client irnc) $ masterID r) r) . filter (\r -> (roomProto r == clientProto cl))
+    return $ if hasAskedList cl then [] else
+        [ ModifyClient (\c -> c{hasAskedList = True})
+        , AnswerClients [sendChan cl] ("ROOMS" : roomsInfoList rooms)]
 
 handleCmd_lobby ["CHAT", msg] = do
     n <- clientNick
--- a/gameServer/NetRoutines.hs	Mon Dec 28 08:43:38 2015 +0300
+++ b/gameServer/NetRoutines.hs	Mon Dec 28 09:06:29 2015 +0300
@@ -72,6 +72,7 @@
                     False
                     False
                     False
+                    False
                     Nothing
                     Nothing
                     newEventsInfo