3458
|
1 |
module ServerState
|
|
2 |
(
|
|
3 |
module RoomsAndClients,
|
|
4 |
clientRoomA,
|
|
5 |
ServerState(..),
|
3501
|
6 |
client's,
|
3502
|
7 |
allClientsS,
|
|
8 |
roomClientsS
|
3458
|
9 |
) where
|
|
10 |
|
|
11 |
import Control.Monad.State
|
|
12 |
----------------------
|
|
13 |
import RoomsAndClients
|
|
14 |
import CoreTypes
|
|
15 |
|
|
16 |
data ServerState = ServerState {
|
|
17 |
clientIndex :: Maybe ClientIndex,
|
|
18 |
serverInfo :: ServerInfo,
|
|
19 |
roomsClients :: MRnC
|
|
20 |
}
|
|
21 |
|
|
22 |
|
|
23 |
clientRoomA :: StateT ServerState IO RoomIndex
|
|
24 |
clientRoomA = do
|
|
25 |
(Just ci) <- gets clientIndex
|
|
26 |
rnc <- gets roomsClients
|
|
27 |
liftIO $ clientRoomM rnc ci
|
|
28 |
|
3501
|
29 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a
|
|
30 |
client's f = do
|
3458
|
31 |
(Just ci) <- gets clientIndex
|
|
32 |
rnc <- gets roomsClients
|
3501
|
33 |
liftIO $ client'sM rnc f ci
|
|
34 |
|
|
35 |
allClientsS :: StateT ServerState IO [ClientInfo]
|
3502
|
36 |
allClientsS = gets roomsClients >>= liftIO . clientsM
|
|
37 |
|
|
38 |
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
|
|
39 |
roomClientsS ri = do
|
|
40 |
rnc <- gets roomsClients
|
|
41 |
liftIO $ roomClientsM rnc ri
|
|
42 |
|