gameServer/Actions.hs
changeset 5996 2c72fe81dd37
parent 5426 109e9b5761c2
child 6012 6bac93097da3
equal deleted inserted replaced
5994:3c578f531cc1 5996:2c72fe81dd37
    15 import qualified Data.ByteString.Char8 as B
    15 import qualified Data.ByteString.Char8 as B
    16 import Control.DeepSeq
    16 import Control.DeepSeq
    17 import Data.Unique
    17 import Data.Unique
    18 import Control.Arrow
    18 import Control.Arrow
    19 import Control.Exception
    19 import Control.Exception
    20 import OfficialServer.GameReplayStore
       
    21 import System.Process
    20 import System.Process
    22 import Network.Socket
    21 import Network.Socket
    23 -----------------------------
    22 -----------------------------
       
    23 import OfficialServer.GameReplayStore
    24 import CoreTypes
    24 import CoreTypes
    25 import Utils
    25 import Utils
    26 import ClientIO
    26 import ClientIO
    27 import ServerState
    27 import ServerState
    28 import Consts
    28 import Consts
   204 
   204 
   205 processAction (MoveToLobby msg) = do
   205 processAction (MoveToLobby msg) = do
   206     (Just ci) <- gets clientIndex
   206     (Just ci) <- gets clientIndex
   207     ri <- clientRoomA
   207     ri <- clientRoomA
   208     rnc <- gets roomsClients
   208     rnc <- gets roomsClients
   209     (gameProgress, playersNum) <- io $ room'sM rnc (gameinprogress &&& playersIn) ri
   209     (gameProgress, playersNum) <- io $ room'sM rnc ((isJust . gameInfo) &&& playersIn) ri
   210     ready <- client's isReady
   210     ready <- client's isReady
   211     master <- client's isMaster
   211     master <- client's isMaster
   212 --    client <- client's id
   212 --    client <- client's id
   213     clNick <- client's nick
   213     clNick <- client's nick
   214     chans <- othersChans
   214     chans <- othersChans
   296 
   296 
   297 
   297 
   298 processAction (RemoveTeam teamName) = do
   298 processAction (RemoveTeam teamName) = do
   299     rnc <- gets roomsClients
   299     rnc <- gets roomsClients
   300     ri <- clientRoomA
   300     ri <- clientRoomA
   301     inGame <- io $ room'sM rnc gameinprogress ri
   301     inGame <- io $ room'sM rnc (isJust . gameInfo) ri
   302     chans <- othersChans
   302     chans <- othersChans
   303     if not $ inGame then
   303     if not $ inGame then
   304             mapM_ processAction [
   304             mapM_ processAction [
   305                 AnswerClients chans ["REMOVE_TEAM", teamName],
   305                 AnswerClients chans ["REMOVE_TEAM", teamName],
   306                 ModifyRoom (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r})
   306                 ModifyRoom (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r})
   308         else
   308         else
   309             mapM_ processAction [
   309             mapM_ processAction [
   310                 AnswerClients chans ["EM", rmTeamMsg],
   310                 AnswerClients chans ["EM", rmTeamMsg],
   311                 ModifyRoom (\r -> r{
   311                 ModifyRoom (\r -> r{
   312                     teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r,
   312                     teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r,
   313                     leftTeams = teamName : leftTeams r,
   313                         gameInfo = liftM (\g -> g{
   314                     roundMsgs = roundMsgs r Seq.|> rmTeamMsg
   314                         leftTeams = teamName : leftTeams g,
       
   315                         roundMsgs = roundMsgs g Seq.|> rmTeamMsg
       
   316                         }) $ gameInfo r
   315                     })
   317                     })
   316                 ]
   318                 ]
   317     where
   319     where
   318         rmTeamMsg = toEngineMsg $ 'F' `B.cons` teamName
   320         rmTeamMsg = toEngineMsg $ 'F' `B.cons` teamName
   319 
   321