gameServer/ServerState.hs
changeset 4588 5ef5415c4ee1
parent 4529 467ab0685890
parent 4586 4ba4f021070f
child 4647 20b982afbe6e
equal deleted inserted replaced
4529:467ab0685890 4588:5ef5415c4ee1
     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