author | nemo |
Fri, 05 Aug 2011 14:15:19 -0400 | |
changeset 5501 | 0ba2dca673e6 |
parent 4989 | 4771fed9272e |
child 6541 | 08ed346ed341 |
permissions | -rw-r--r-- |
3458 | 1 |
module ServerState |
2 |
( |
|
3 |
module RoomsAndClients, |
|
4 |
clientRoomA, |
|
5 |
ServerState(..), |
|
3501 | 6 |
client's, |
3502 | 7 |
allClientsS, |
4601 | 8 |
roomClientsS, |
9 |
io |
|
3458 | 10 |
) where |
11 |
||
3741
73246d25dfe1
Add some more strictness, use unsafeThaw and unsafeFreeze functions which work at O(1)
unc0rr
parents:
3645
diff
changeset
|
12 |
import Control.Monad.State.Strict |
3566 | 13 |
import Data.Set as Set |
3458 | 14 |
---------------------- |
15 |
import RoomsAndClients |
|
16 |
import CoreTypes |
|
17 |
||
4989 | 18 |
data ServerState = ServerState { |
3807 | 19 |
clientIndex :: !(Maybe ClientIndex), |
4989 | 20 |
serverInfo :: !ServerInfo, |
3807 | 21 |
removedClients :: !(Set.Set ClientIndex), |
22 |
roomsClients :: !MRnC |
|
3458 | 23 |
} |
24 |
||
25 |
||
4989 | 26 |
clientRoomA :: StateT ServerState IO RoomIndex |
3458 | 27 |
clientRoomA = do |
28 |
(Just ci) <- gets clientIndex |
|
29 |
rnc <- gets roomsClients |
|
4622 | 30 |
io $ clientRoomM rnc ci |
3458 | 31 |
|
4989 | 32 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a |
3501 | 33 |
client's f = do |
3458 | 34 |
(Just ci) <- gets clientIndex |
35 |
rnc <- gets roomsClients |
|
4622 | 36 |
io $ client'sM rnc f ci |
3645 | 37 |
|
4989 | 38 |
allClientsS :: StateT ServerState IO [ClientInfo] |
3502 | 39 |
allClientsS = gets roomsClients >>= liftIO . clientsM |
40 |
||
4989 | 41 |
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo] |
3502 | 42 |
roomClientsS ri = do |
43 |
rnc <- gets roomsClients |
|
4622 | 44 |
io $ roomClientsM rnc ri |
4601 | 45 |
|
4989 | 46 |
io :: IO a -> StateT ServerState IO a |
4601 | 47 |
io = liftIO |