author | jose1711 |
Sat, 05 Feb 2011 15:36:02 +0100 | |
changeset 4919 | 2ba6a2315838 |
parent 4622 | 8bdc879ee6b2 |
child 4975 | 31da8979e5b1 |
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 |
||
18 |
data ServerState = ServerState { |
|
3807 | 19 |
clientIndex :: !(Maybe ClientIndex), |
20 |
serverInfo :: !ServerInfo, |
|
21 |
removedClients :: !(Set.Set ClientIndex), |
|
22 |
roomsClients :: !MRnC |
|
3458 | 23 |
} |
24 |
||
25 |
||
26 |
clientRoomA :: StateT ServerState IO RoomIndex |
|
27 |
clientRoomA = do |
|
28 |
(Just ci) <- gets clientIndex |
|
29 |
rnc <- gets roomsClients |
|
4622 | 30 |
io $ clientRoomM rnc ci |
3458 | 31 |
|
3501 | 32 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a |
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 |
|
3501 | 38 |
allClientsS :: StateT ServerState IO [ClientInfo] |
3502 | 39 |
allClientsS = gets roomsClients >>= liftIO . clientsM |
40 |
||
41 |
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo] |
|
42 |
roomClientsS ri = do |
|
43 |
rnc <- gets roomsClients |
|
4622 | 44 |
io $ roomClientsM rnc ri |
4601 | 45 |
|
46 |
io :: IO a -> StateT ServerState IO a |
|
47 |
io = liftIO |