gameServer/ServerState.hs
changeset 4975 31da8979e5b1
parent 4622 8bdc879ee6b2
child 4989 4771fed9272e
equal deleted inserted replaced
4974:078cd026a7b1 4975:31da8979e5b1
    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 = ServerState {
    18 data ServerState c = ServerState {
    19         clientIndex :: !(Maybe ClientIndex),
    19         clientIndex :: !(Maybe ClientIndex),
    20         serverInfo :: !ServerInfo,
    20         serverInfo :: !(ServerInfo c),
    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 IO RoomIndex
    26 clientRoomA :: StateT (ServerState c) 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 IO a
    32 client's :: (ClientInfo -> a) -> StateT (ServerState c) 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 IO [ClientInfo]
    38 allClientsS :: StateT (ServerState c) IO [ClientInfo]
    39 allClientsS = gets roomsClients >>= liftIO . clientsM
    39 allClientsS = gets roomsClients >>= liftIO . clientsM
    40 
    40 
    41 roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
    41 roomClientsS :: RoomIndex -> StateT (ServerState c) 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 IO a
    46 io :: IO a -> StateT (ServerState c) IO a
    47 io = liftIO
    47 io = liftIO