gameServer/Actions.hs
changeset 7124 cfee05712896
parent 7120 9257cf8e7af2
child 7126 8daa5c8e84c0
equal deleted inserted replaced
7122:fa2d09868ac6 7124:cfee05712896
   310 processAction FinishGame = do
   310 processAction FinishGame = do
   311     rnc <- gets roomsClients
   311     rnc <- gets roomsClients
   312     ri <- clientRoomA
   312     ri <- clientRoomA
   313     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   313     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   314     clNick <- client's nick
   314     clNick <- client's nick
   315     answerRemovedTeams <- io $ 
       
   316          room'sM rnc (map (\t -> AnswerClients thisRoomChans ["REMOVE_TEAM", t]) . leftTeams . fromJust . gameInfo) ri
       
   317     
   315     
   318     mapM_ processAction $ SaveReplay
   316     mapM_ processAction [
   319         : ModifyRoom
   317         SaveReplay
       
   318         , ModifyRoom
   320             (\r -> r{
   319             (\r -> r{
   321                 gameInfo = Nothing,
   320                 gameInfo = Nothing,
   322                 readyPlayers = 0
   321                 readyPlayers = 0
   323                 }
   322                 }
   324             )
   323             )
   325         : UnreadyRoomClients
   324         , UnreadyRoomClients
   326         : answerRemovedTeams
   325         ]
   327 
   326 
   328         
   327         
   329 processAction (SendTeamRemovalMessage teamName) = do
   328 processAction (SendTeamRemovalMessage teamName) = do
   330     chans <- othersChans
   329     chans <- othersChans
   331     mapM_ processAction [
   330     mapM_ processAction [
   332         AnswerClients chans ["EM", rmTeamMsg],
   331         AnswerClients chans ["EM", rmTeamMsg],
   333         ModifyRoom (\r -> r{
   332         ModifyRoom (\r -> r{
   334                 gameInfo = liftM (\g -> g{
   333                 gameInfo = liftM (\g -> g{
   335                 teamsInGameNumber = teamsInGameNumber g - 1
   334                     teamsInGameNumber = teamsInGameNumber g - 1
   336                 , roundMsgs = roundMsgs g Seq.|> rmTeamMsg
   335                     , roundMsgs = roundMsgs g Seq.|> rmTeamMsg
   337                 , leftTeams = teamName : leftTeams g
       
   338                 }) $ gameInfo r
   336                 }) $ gameInfo r
   339             })
   337             })
   340         ]
   338         ]
   341         
   339         
   342     rnc <- gets roomsClients
   340     rnc <- gets roomsClients
   351 processAction (RemoveTeam teamName) = do
   349 processAction (RemoveTeam teamName) = do
   352     rnc <- gets roomsClients
   350     rnc <- gets roomsClients
   353     ri <- clientRoomA
   351     ri <- clientRoomA
   354     inGame <- io $ room'sM rnc (isJust . gameInfo) ri
   352     inGame <- io $ room'sM rnc (isJust . gameInfo) ri
   355     chans <- othersChans
   353     chans <- othersChans
   356     if not $ inGame then
   354     mapM_ processAction $ 
   357             mapM_ processAction [
   355         ModifyRoom (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r})
   358                 ModifyRoom (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r})
   356         : AnswerClients chans ["REMOVE_TEAM", teamName]
   359                 , AnswerClients chans ["REMOVE_TEAM", teamName]
   357         : [SendTeamRemovalMessage teamName | inGame]
   360                 ]
       
   361         else
       
   362             mapM_ processAction [
       
   363                 ModifyRoom (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r})
       
   364                 , SendTeamRemovalMessage teamName
       
   365                 ]
       
   366 
   358 
   367 
   359 
   368 processAction (RemoveClientTeams clId) = do
   360 processAction (RemoveClientTeams clId) = do
   369     rnc <- gets roomsClients
   361     rnc <- gets roomsClients
   370 
   362