gameServer/HWProtoInRoomState.hs
changeset 5996 2c72fe81dd37
parent 5931 184057074257
child 6012 6bac93097da3
equal deleted inserted replaced
5994:3c578f531cc1 5996:2c72fe81dd37
    56                 [Warning "too many teams"]
    56                 [Warning "too many teams"]
    57             else if canAddNumber rm <= 0 then
    57             else if canAddNumber rm <= 0 then
    58                 [Warning "too many hedgehogs"]
    58                 [Warning "too many hedgehogs"]
    59             else if isJust $ findTeam rm then
    59             else if isJust $ findTeam rm then
    60                 [Warning "There's already a team with same name in the list"]
    60                 [Warning "There's already a team with same name in the list"]
    61             else if gameinprogress rm then
    61             else if isJust $ gameInfo rm then
    62                 [Warning "round in progress"]
    62                 [Warning "round in progress"]
    63             else if isRestrictedTeams rm then
    63             else if isRestrictedTeams rm then
    64                 [Warning "restricted"]
    64                 [Warning "restricted"]
    65             else
    65             else
    66                 [ModifyRoom (\r -> r{teams = teams r ++ [newTeam ci clNick r]}),
    66                 [ModifyRoom (\r -> r{teams = teams r ++ [newTeam ci clNick r]}),
   168 handleCmd_inRoom ["START_GAME"] = do
   168 handleCmd_inRoom ["START_GAME"] = do
   169     cl <- thisClient
   169     cl <- thisClient
   170     rm <- thisRoom
   170     rm <- thisRoom
   171     chans <- roomClientsChans
   171     chans <- roomClientsChans
   172 
   172 
   173     if isMaster cl && playersIn rm == readyPlayers rm && not (gameinprogress rm) then
   173     if isMaster cl && playersIn rm == readyPlayers rm && not (isJust $ gameInfo rm) then
   174         if enoughClans rm then
   174         if enoughClans rm then
   175             return [
   175             return [
   176                 ModifyRoom
   176                 ModifyRoom
   177                     (\r -> r{
   177                     (\r -> r{
   178                         gameinprogress = True,
   178                         gameInfo = Just $ newGameInfo False
   179                         roundMsgs = empty,
   179                         }
   180                         leftTeams = [],
       
   181                         teamsAtStart = teams r}
       
   182                     ),
   180                     ),
   183                 AnswerClients chans ["RUN_GAME"]
   181                 AnswerClients chans ["RUN_GAME"]
   184                 ]
   182                 ]
   185             else
   183             else
   186             return [Warning "Less than two clans!"]
   184             return [Warning "Less than two clans!"]
   193 handleCmd_inRoom ["EM", msg] = do
   191 handleCmd_inRoom ["EM", msg] = do
   194     cl <- thisClient
   192     cl <- thisClient
   195     rm <- thisRoom
   193     rm <- thisRoom
   196     chans <- roomOthersChans
   194     chans <- roomOthersChans
   197 
   195 
   198     if teamsInGame cl > 0 && gameinprogress rm && isLegal then
   196     if teamsInGame cl > 0 && (isJust $ gameInfo rm) && isLegal then
   199         return $ AnswerClients chans ["EM", msg] : [ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}) | not isKeepAlive]
   197         return $ AnswerClients chans ["EM", msg] : [ModifyRoom (\r -> r{gameInfo = liftM (\g -> g{roundMsgs = roundMsgs g |> msg}) $ gameInfo r}) | not isKeepAlive]
   200         else
   198         else
   201         return []
   199         return []
   202     where
   200     where
   203         (isLegal, isKeepAlive) = checkNetCmd msg
   201         (isLegal, isKeepAlive) = checkNetCmd msg
   204 
   202 
   205 
   203 
   206 handleCmd_inRoom ["ROUNDFINISHED", _] = do
   204 handleCmd_inRoom ["ROUNDFINISHED", correctly] = do
   207     cl <- thisClient
   205     cl <- thisClient
   208     rm <- thisRoom
   206     rm <- thisRoom
   209     chans <- roomClientsChans
   207     chans <- roomClientsChans
   210 
   208 
   211     if isMaster cl && gameinprogress rm then
   209     if isMaster cl && (isJust $ gameInfo rm) then
   212         return $ 
   210         return $ 
   213             ModifyRoom
   211             ModifyRoom
   214                 (\r -> r{
   212                 (\r -> r{
   215                     gameinprogress = False,
   213                     gameInfo = Nothing,
   216                     readyPlayers = 0,
   214                     readyPlayers = 0
   217                     roundMsgs = empty,
   215                     }
   218                     leftTeams = [],
       
   219                     teamsAtStart = []}
       
   220                 )
   216                 )
   221             : UnreadyRoomClients
   217             : UnreadyRoomClients
   222             : answerRemovedTeams chans rm
   218             : answerRemovedTeams chans rm
   223         else
   219         else
   224         return []
   220         return []
   225     where
   221     where
   226         answerRemovedTeams chans = map (\t -> AnswerClients chans ["REMOVE_TEAM", t]) . leftTeams
   222         answerRemovedTeams chans = map (\t -> AnswerClients chans ["REMOVE_TEAM", t]) . leftTeams . fromJust . gameInfo
       
   223         isCorrect = correctly == "1"
   227 
   224 
   228 -- compatibility with clients with protocol < 38
   225 -- compatibility with clients with protocol < 38
   229 handleCmd_inRoom ["ROUNDFINISHED"] =
   226 handleCmd_inRoom ["ROUNDFINISHED"] =
   230     handleCmd_inRoom ["ROUNDFINISHED", "1"]
   227     handleCmd_inRoom ["ROUNDFINISHED", "1"]
   231 
   228