# HG changeset patch # User unc0rr # Date 1350331558 -14400 # Node ID c20e6c80e249c6f76be8238891474a482cd9667a # Parent b89bd0ffb8aa70fbc12e58ffabeb233c5c2e8b4f Don't accept ROUNDFINISHED message twice. Fixes game hangs when half of teams quit game. diff -r b89bd0ffb8aa -r c20e6c80e249 gameServer/Actions.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 diff -r b89bd0ffb8aa -r c20e6c80e249 gameServer/CoreTypes.hs --- 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 diff -r b89bd0ffb8aa -r c20e6c80e249 gameServer/HWProtoInRoomState.hs --- 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" diff -r b89bd0ffb8aa -r c20e6c80e249 gameServer/NetRoutines.hs --- 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 )