gameServer/ServerState.hs
branchexperimental3D
changeset 4812 f924be23ffb4
parent 4347 0ddb100fea61
parent 4811 3edc0cdcfe03
child 4814 e19791f08443
equal deleted inserted replaced
4347:0ddb100fea61 4812:f924be23ffb4
     1 module ServerState
       
     2     (
       
     3     module RoomsAndClients,
       
     4     clientRoomA,
       
     5     ServerState(..),
       
     6     client's,
       
     7     allClientsS,
       
     8     roomClientsS
       
     9     ) where
       
    10 
       
    11 import Control.Monad.State.Strict
       
    12 import Data.Set as Set
       
    13 ----------------------
       
    14 import RoomsAndClients
       
    15 import CoreTypes
       
    16 
       
    17 data ServerState = ServerState {
       
    18         clientIndex :: !(Maybe ClientIndex),
       
    19         serverInfo :: !ServerInfo,
       
    20         removedClients :: !(Set.Set ClientIndex),
       
    21         roomsClients :: !MRnC
       
    22     }
       
    23 
       
    24 
       
    25 clientRoomA :: StateT ServerState IO RoomIndex
       
    26 clientRoomA = do
       
    27     (Just ci) <- gets clientIndex
       
    28     rnc <- gets roomsClients
       
    29     liftIO $ clientRoomM rnc ci
       
    30 
       
    31 client's :: (ClientInfo -> a) -> StateT ServerState IO a
       
    32 client's f = do
       
    33     (Just ci) <- gets clientIndex
       
    34     rnc <- gets roomsClients
       
    35     liftIO $ client'sM rnc f ci
       
    36 
       
    37 allClientsS :: StateT ServerState IO [ClientInfo]
       
    38 allClientsS = gets roomsClients >>= liftIO . clientsM
       
    39 
       
    40 roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
       
    41 roomClientsS ri = do
       
    42     rnc <- gets roomsClients
       
    43     liftIO $ roomClientsM rnc ri