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
|
3566
|
12 |
import Data.Set as Set
|
3458
|
13 |
----------------------
|
|
14 |
import RoomsAndClients
|
|
15 |
import CoreTypes
|
|
16 |
|
|
17 |
data ServerState = ServerState {
|
|
18 |
clientIndex :: Maybe ClientIndex,
|
|
19 |
serverInfo :: ServerInfo,
|
3566
|
20 |
removedClients :: Set.Set ClientIndex,
|
3458
|
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 |
|
3501
|
31 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a
|
|
32 |
client's f = do
|
3458
|
33 |
(Just ci) <- gets clientIndex
|
|
34 |
rnc <- gets roomsClients
|
3501
|
35 |
liftIO $ client'sM rnc f ci
|
3645
|
36 |
|
3501
|
37 |
allClientsS :: StateT ServerState IO [ClientInfo]
|
3502
|
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
|