author | Xeli |
Fri, 27 Apr 2012 23:17:11 +0200 | |
changeset 6942 | 11f52445e8cd |
parent 6541 | 08ed346ed341 |
child 8371 | 0551b5c3de9a |
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, |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
9 |
sameProtoClientsS, |
4601 | 10 |
io |
3458 | 11 |
) where |
12 |
||
3741
73246d25dfe1
Add some more strictness, use unsafeThaw and unsafeFreeze functions which work at O(1)
unc0rr
parents:
3645
diff
changeset
|
13 |
import Control.Monad.State.Strict |
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
14 |
import Data.Set as Set(Set) |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
15 |
import Data.Word |
3458 | 16 |
---------------------- |
17 |
import RoomsAndClients |
|
18 |
import CoreTypes |
|
19 |
||
4989 | 20 |
data ServerState = ServerState { |
3807 | 21 |
clientIndex :: !(Maybe ClientIndex), |
4989 | 22 |
serverInfo :: !ServerInfo, |
3807 | 23 |
removedClients :: !(Set.Set ClientIndex), |
24 |
roomsClients :: !MRnC |
|
3458 | 25 |
} |
26 |
||
27 |
||
4989 | 28 |
clientRoomA :: StateT ServerState IO RoomIndex |
3458 | 29 |
clientRoomA = do |
30 |
(Just ci) <- gets clientIndex |
|
31 |
rnc <- gets roomsClients |
|
4622 | 32 |
io $ clientRoomM rnc ci |
3458 | 33 |
|
4989 | 34 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a |
3501 | 35 |
client's f = do |
3458 | 36 |
(Just ci) <- gets clientIndex |
37 |
rnc <- gets roomsClients |
|
4622 | 38 |
io $ client'sM rnc f ci |
3645 | 39 |
|
4989 | 40 |
allClientsS :: StateT ServerState IO [ClientInfo] |
3502 | 41 |
allClientsS = gets roomsClients >>= liftIO . clientsM |
42 |
||
4989 | 43 |
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo] |
3502 | 44 |
roomClientsS ri = do |
45 |
rnc <- gets roomsClients |
|
4622 | 46 |
io $ roomClientsM rnc ri |
4601 | 47 |
|
6541
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
48 |
sameProtoClientsS :: Word16 -> StateT ServerState IO [ClientInfo] |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
49 |
sameProtoClientsS p = liftM f allClientsS |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
50 |
where |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
51 |
f = filter (\c -> clientProto c == p) |
08ed346ed341
Send full room info on room add and update events. Less(?) traffic, but current frontend doesn't behave good with this change to server.
unc0rr
parents:
4989
diff
changeset
|
52 |
|
4989 | 53 |
io :: IO a -> StateT ServerState IO a |
4601 | 54 |
io = liftIO |