gameServer/HWProtoInRoomState.hs
changeset 5996 2c72fe81dd37
parent 5931 184057074257
child 6012 6bac93097da3
--- a/gameServer/HWProtoInRoomState.hs	Fri Sep 23 09:58:41 2011 +0200
+++ b/gameServer/HWProtoInRoomState.hs	Sat Sep 24 00:00:57 2011 +0400
@@ -58,7 +58,7 @@
                 [Warning "too many hedgehogs"]
             else if isJust $ findTeam rm then
                 [Warning "There's already a team with same name in the list"]
-            else if gameinprogress rm then
+            else if isJust $ gameInfo rm then
                 [Warning "round in progress"]
             else if isRestrictedTeams rm then
                 [Warning "restricted"]
@@ -170,15 +170,13 @@
     rm <- thisRoom
     chans <- roomClientsChans
 
-    if isMaster cl && playersIn rm == readyPlayers rm && not (gameinprogress rm) then
+    if isMaster cl && playersIn rm == readyPlayers rm && not (isJust $ gameInfo rm) then
         if enoughClans rm then
             return [
                 ModifyRoom
                     (\r -> r{
-                        gameinprogress = True,
-                        roundMsgs = empty,
-                        leftTeams = [],
-                        teamsAtStart = teams r}
+                        gameInfo = Just $ newGameInfo False
+                        }
                     ),
                 AnswerClients chans ["RUN_GAME"]
                 ]
@@ -195,35 +193,34 @@
     rm <- thisRoom
     chans <- roomOthersChans
 
-    if teamsInGame cl > 0 && gameinprogress rm && isLegal then
-        return $ AnswerClients chans ["EM", msg] : [ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}) | not isKeepAlive]
+    if teamsInGame cl > 0 && (isJust $ gameInfo rm) && isLegal then
+        return $ AnswerClients chans ["EM", msg] : [ModifyRoom (\r -> r{gameInfo = liftM (\g -> g{roundMsgs = roundMsgs g |> msg}) $ gameInfo r}) | not isKeepAlive]
         else
         return []
     where
         (isLegal, isKeepAlive) = checkNetCmd msg
 
 
-handleCmd_inRoom ["ROUNDFINISHED", _] = do
+handleCmd_inRoom ["ROUNDFINISHED", correctly] = do
     cl <- thisClient
     rm <- thisRoom
     chans <- roomClientsChans
 
-    if isMaster cl && gameinprogress rm then
+    if isMaster cl && (isJust $ gameInfo rm) then
         return $ 
             ModifyRoom
                 (\r -> r{
-                    gameinprogress = False,
-                    readyPlayers = 0,
-                    roundMsgs = empty,
-                    leftTeams = [],
-                    teamsAtStart = []}
+                    gameInfo = Nothing,
+                    readyPlayers = 0
+                    }
                 )
             : UnreadyRoomClients
             : answerRemovedTeams chans rm
         else
         return []
     where
-        answerRemovedTeams chans = map (\t -> AnswerClients chans ["REMOVE_TEAM", t]) . leftTeams
+        answerRemovedTeams chans = map (\t -> AnswerClients chans ["REMOVE_TEAM", t]) . leftTeams . fromJust . gameInfo
+        isCorrect = correctly == "1"
 
 -- compatibility with clients with protocol < 38
 handleCmd_inRoom ["ROUNDFINISHED"] =