author | Henek |
Fri, 12 Nov 2010 21:37:12 +0100 | |
changeset 4269 | 945f2d104268 |
parent 3807 | 7e4f7ed41790 |
child 4601 | 08ae94dd4c0d |
permissions | -rw-r--r-- |
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 |
||
3741
73246d25dfe1
Add some more strictness, use unsafeThaw and unsafeFreeze functions which work at O(1)
unc0rr
parents:
3645
diff
changeset
|
11 |
import Control.Monad.State.Strict |
3566 | 12 |
import Data.Set as Set |
3458 | 13 |
---------------------- |
14 |
import RoomsAndClients |
|
15 |
import CoreTypes |
|
16 |
||
17 |
data ServerState = ServerState { |
|
3807 | 18 |
clientIndex :: !(Maybe ClientIndex), |
19 |
serverInfo :: !ServerInfo, |
|
20 |
removedClients :: !(Set.Set ClientIndex), |
|
21 |
roomsClients :: !MRnC |
|
3458 | 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 |