gameServer/Actions.hs
changeset 4975 31da8979e5b1
parent 4973 53411a26df7e
child 4989 4771fed9272e
equal deleted inserted replaced
4974:078cd026a7b1 4975:31da8979e5b1
    20 import Utils
    20 import Utils
    21 import ClientIO
    21 import ClientIO
    22 import ServerState
    22 import ServerState
    23 import Consts
    23 import Consts
    24 
    24 
    25 data Action =
    25 data Action c =
    26     AnswerClients ![ClientChan] ![B.ByteString]
    26     AnswerClients ![ClientChan] ![B.ByteString]
    27     | SendServerMessage
    27     | SendServerMessage
    28     | SendServerVars
    28     | SendServerVars
    29     | MoveToRoom RoomIndex
    29     | MoveToRoom RoomIndex
    30     | MoveToLobby B.ByteString
    30     | MoveToLobby B.ByteString
    42     | ChangeMaster
    42     | ChangeMaster
    43     | RemoveClientTeams ClientIndex
    43     | RemoveClientTeams ClientIndex
    44     | ModifyClient (ClientInfo -> ClientInfo)
    44     | ModifyClient (ClientInfo -> ClientInfo)
    45     | ModifyClient2 ClientIndex (ClientInfo -> ClientInfo)
    45     | ModifyClient2 ClientIndex (ClientInfo -> ClientInfo)
    46     | ModifyRoom (RoomInfo -> RoomInfo)
    46     | ModifyRoom (RoomInfo -> RoomInfo)
    47     | ModifyServerInfo (ServerInfo -> ServerInfo)
    47     | ModifyServerInfo (ServerInfo c -> ServerInfo c)
    48     | AddRoom B.ByteString B.ByteString
    48     | AddRoom B.ByteString B.ByteString
    49     | CheckRegistered
    49     | CheckRegistered
    50     | ClearAccountsCache
    50     | ClearAccountsCache
    51     | ProcessAccountInfo AccountInfo
    51     | ProcessAccountInfo AccountInfo
    52     | AddClient ClientInfo
    52     | AddClient ClientInfo
    54     | PingAll
    54     | PingAll
    55     | StatsAction
    55     | StatsAction
    56     | RestartServer Bool
    56     | RestartServer Bool
    57 
    57 
    58 
    58 
    59 type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
    59 type CmdHandler c = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action c]
    60 
    60 
    61 instance NFData Action where
    61 instance NFData (Action c) where
    62     rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` ()
    62     rnf (AnswerClients chans msg) = chans `deepseq` msg `deepseq` ()
    63     rnf a = a `seq` ()
    63     rnf a = a `seq` ()
    64 
    64 
    65 instance NFData B.ByteString
    65 instance NFData B.ByteString
    66 instance NFData (Chan a)
    66 instance NFData (Chan a)
    67 
    67 
    68 
    68 
    69 othersChans :: StateT ServerState IO [ClientChan]
    69 othersChans :: StateT (ServerState c) IO [ClientChan]
    70 othersChans = do
    70 othersChans = do
    71     cl <- client's id
    71     cl <- client's id
    72     ri <- clientRoomA
    72     ri <- clientRoomA
    73     liftM (map sendChan . filter (/= cl)) $ roomClientsS ri
    73     liftM (map sendChan . filter (/= cl)) $ roomClientsS ri
    74 
    74 
    75 processAction :: Action -> StateT ServerState IO ()
    75 processAction :: Action c -> StateT (ServerState c) IO ()
    76 
    76 
    77 
    77 
    78 processAction (AnswerClients chans msg) =
    78 processAction (AnswerClients chans msg) =
    79     io $ mapM_ (`writeChan` (msg `deepseq` msg)) (chans `deepseq` chans)
    79     io $ mapM_ (`writeChan` (msg `deepseq` msg)) (chans `deepseq` chans)
    80 
    80