author | unc0rr |
Fri, 28 Jan 2011 22:21:29 +0300 | |
branch | server_refactor |
changeset 4606 | 4c521c4ab2b6 |
parent 4601 | 08ae94dd4c0d |
child 4622 | 8bdc879ee6b2 |
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 |
|
30 |
liftIO $ clientRoomM rnc ci |
|
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 |
|
3501 | 36 |
liftIO $ 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 |
|
44 |
liftIO $ roomClientsM rnc ri |
|
4601 | 45 |
|
46 |
io :: IO a -> StateT ServerState IO a |
|
47 |
io = liftIO |