gameServer/ServerState.hs
changeset 4989 4771fed9272e
parent 4975 31da8979e5b1
child 6541 08ed346ed341
equal deleted inserted replaced
4988:bd540ba66599 4989:4771fed9272e
    13 import Data.Set as Set
    13 import Data.Set as Set
    14 ----------------------
    14 ----------------------
    15 import RoomsAndClients
    15 import RoomsAndClients
    16 import CoreTypes
    16 import CoreTypes
    17 
    17 
    18 data ServerState c = ServerState {
    18 data ServerState = ServerState {
    19         clientIndex :: !(Maybe ClientIndex),
    19         clientIndex :: !(Maybe ClientIndex),
    20         serverInfo :: !(ServerInfo c),
    20         serverInfo :: !ServerInfo,
    21         removedClients :: !(Set.Set ClientIndex),
    21         removedClients :: !(Set.Set ClientIndex),
    22         roomsClients :: !MRnC
    22         roomsClients :: !MRnC
    23     }
    23     }
    24 
    24 
    25 
    25 
    26 clientRoomA :: StateT (ServerState c) IO RoomIndex
    26 clientRoomA :: StateT ServerState IO RoomIndex
    27 clientRoomA = do
    27 clientRoomA = do
    28     (Just ci) <- gets clientIndex
    28     (Just ci) <- gets clientIndex
    29     rnc <- gets roomsClients
    29     rnc <- gets roomsClients
    30     io $ clientRoomM rnc ci
    30     io $ clientRoomM rnc ci
    31 
    31 
    32 client's :: (ClientInfo -> a) -> StateT (ServerState c) IO a
    32 client's :: (ClientInfo -> a) -> StateT ServerState IO a
    33 client's f = do
    33 client's f = do
    34     (Just ci) <- gets clientIndex
    34     (Just ci) <- gets clientIndex
    35     rnc <- gets roomsClients
    35     rnc <- gets roomsClients
    36     io $ client'sM rnc f ci
    36     io $ client'sM rnc f ci
    37 
    37 
    38 allClientsS :: StateT (ServerState c) IO [ClientInfo]
    38 allClientsS :: StateT ServerState IO [ClientInfo]
    39 allClientsS = gets roomsClients >>= liftIO . clientsM
    39 allClientsS = gets roomsClients >>= liftIO . clientsM
    40 
    40 
    41 roomClientsS :: RoomIndex -> StateT (ServerState c) IO [ClientInfo]
    41 roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
    42 roomClientsS ri = do
    42 roomClientsS ri = do
    43     rnc <- gets roomsClients
    43     rnc <- gets roomsClients
    44     io $ roomClientsM rnc ri
    44     io $ roomClientsM rnc ri
    45 
    45 
    46 io :: IO a -> StateT (ServerState c) IO a
    46 io :: IO a -> StateT ServerState IO a
    47 io = liftIO
    47 io = liftIO