Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
authorunc0rr
Tue, 16 Oct 2012 00:05:58 +0400
changeset 7757 c20e6c80e249
parent 7756 b89bd0ffb8aa
child 7758 a225cc45513e
Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game.
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/HWProtoInRoomState.hs
gameServer/NetRoutines.hs
--- a/gameServer/Actions.hs	Mon Oct 15 10:10:54 2012 -0400
+++ b/gameServer/Actions.hs	Tue Oct 16 00:05:58 2012 +0400
@@ -55,6 +55,7 @@
     | RemoveClientTeams ClientIndex
     | ModifyClient (ClientInfo -> ClientInfo)
     | ModifyClient2 ClientIndex (ClientInfo -> ClientInfo)
+    | ModifyRoomClients (ClientInfo -> ClientInfo)
     | ModifyRoom (RoomInfo -> RoomInfo)
     | ModifyServerInfo (ServerInfo -> ServerInfo)
     | AddRoom B.ByteString B.ByteString
@@ -182,6 +183,12 @@
     io $ modifyClient rnc f ci
     return ()
 
+processAction (ModifyRoomClients f) = do
+    rnc <- gets roomsClients
+    ri <- clientRoomA
+    roomClIDs <- io $ roomClientsIndicesM rnc ri
+    io $ mapM_ (modifyClient rnc f) roomClIDs
+
 
 processAction (ModifyRoom f) = do
     rnc <- gets roomsClients
@@ -315,9 +322,11 @@
     roomPlayers <- roomClientsS ri
     roomClIDs <- io $ roomClientsIndicesM rnc ri
     pr <- client's clientProto
-    processAction $ AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr (map nick roomPlayers)
-    io $ mapM_ (modifyClient rnc (\cl -> cl{isReady = False})) roomClIDs
-    processAction $ ModifyRoom (\r -> r{readyPlayers = 0})
+    mapM_ processAction [
+        AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr (map nick roomPlayers)
+        , ModifyRoomClients (\cl -> cl{isReady = False})
+        , ModifyRoom (\r -> r{readyPlayers = 0})
+        ]
     where
         notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks
 
--- a/gameServer/CoreTypes.hs	Mon Oct 15 10:10:54 2012 -0400
+++ b/gameServer/CoreTypes.hs	Tue Oct 16 00:05:58 2012 +0400
@@ -34,6 +34,7 @@
         pingsQueue :: !Word,
         isMaster :: Bool,
         isReady :: !Bool,
+        isInGame :: Bool,
         isAdministrator :: Bool,
         clientClan :: Maybe B.ByteString,
         teamsInGame :: Word
--- a/gameServer/HWProtoInRoomState.hs	Mon Oct 15 10:10:54 2012 -0400
+++ b/gameServer/HWProtoInRoomState.hs	Tue Oct 16 00:05:58 2012 +0400
@@ -181,8 +181,9 @@
                     (\r -> r{
                         gameInfo = Just $ newGameInfo (teams rm) (length $ teams rm) allPlayersRegistered (mapParams rm) (params rm)
                         }
-                    ),
-                AnswerClients chans ["RUN_GAME"]
+                    )
+                , AnswerClients chans ["RUN_GAME"]
+                , ModifyRoomClients (\c -> c{isInGame = True})
                 ]
             else
             return [Warning "Less than two clans!"]
@@ -206,17 +207,20 @@
 
 
 handleCmd_inRoom ["ROUNDFINISHED", correctly] = do
-    clId <- asks fst
     cl <- thisClient
     rm <- thisRoom
     let clTeams = map teamname . filter (\t -> teamowner t == nick cl) . teams $ rm
 
-    if isJust $ gameInfo rm then
-        if (isMaster cl && isCorrect) then
-            return [FinishGame]
-            else return $ map SendTeamRemovalMessage clTeams
+    if isInGame cl then
+        if isJust $ gameInfo rm then
+            if (isMaster cl && isCorrect) then
+                return [ModifyClient (\c -> c{isInGame = False}), FinishGame]
+                else
+                return $ (ModifyClient (\c -> c{isInGame = False})) : map SendTeamRemovalMessage clTeams
+            else
+            return [ModifyClient (\c -> c{isInGame = False})]
         else
-        return []
+        return [] -- don't accept this message twice
     where
         isCorrect = correctly == "1"
 
--- a/gameServer/NetRoutines.hs	Mon Oct 15 10:10:54 2012 -0400
+++ b/gameServer/NetRoutines.hs	Tue Oct 16 00:05:58 2012 +0400
@@ -41,6 +41,7 @@
                     False
                     False
                     False
+                    False
                     Nothing
                     0
                     )