author | sheepluva |
Fri, 07 Feb 2014 10:11:10 +0100 | |
changeset 10118 | 788703011d20 |
parent 9973 | 7589978c9912 |
child 10460 | 8dcea9087d75 |
permissions | -rw-r--r-- |
3458 | 1 |
module ServerState |
2 |
( |
|
3 |
module RoomsAndClients, |
|
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
4 |
module JoinsMonitor, |
3458 | 5 |
clientRoomA, |
6 |
ServerState(..), |
|
3501 | 7 |
client's, |
3502 | 8 |
allClientsS, |
8452 | 9 |
allRoomsS, |
4601 | 10 |
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
|
11 |
sameProtoClientsS, |
4601 | 12 |
io |
3458 | 13 |
) where |
14 |
||
3741
73246d25dfe1
Add some more strictness, use unsafeThaw and unsafeFreeze functions which work at O(1)
unc0rr
parents:
3645
diff
changeset
|
15 |
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
|
16 |
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
|
17 |
import Data.Word |
3458 | 18 |
---------------------- |
19 |
import RoomsAndClients |
|
20 |
import CoreTypes |
|
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
21 |
import JoinsMonitor |
3458 | 22 |
|
4989 | 23 |
data ServerState = ServerState { |
3807 | 24 |
clientIndex :: !(Maybe ClientIndex), |
4989 | 25 |
serverInfo :: !ServerInfo, |
3807 | 26 |
removedClients :: !(Set.Set ClientIndex), |
9973
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
27 |
roomsClients :: !MRnC, |
7589978c9912
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
unc0rr
parents:
8452
diff
changeset
|
28 |
joinsMonitor :: !JoinsMonitor |
3458 | 29 |
} |
30 |
||
31 |
||
4989 | 32 |
clientRoomA :: StateT ServerState IO RoomIndex |
3458 | 33 |
clientRoomA = do |
34 |
(Just ci) <- gets clientIndex |
|
35 |
rnc <- gets roomsClients |
|
4622 | 36 |
io $ clientRoomM rnc ci |
3458 | 37 |
|
4989 | 38 |
client's :: (ClientInfo -> a) -> StateT ServerState IO a |
3501 | 39 |
client's f = do |
3458 | 40 |
(Just ci) <- gets clientIndex |
41 |
rnc <- gets roomsClients |
|
4622 | 42 |
io $ client'sM rnc f ci |
3645 | 43 |
|
4989 | 44 |
allClientsS :: StateT ServerState IO [ClientInfo] |
3502 | 45 |
allClientsS = gets roomsClients >>= liftIO . clientsM |
46 |
||
8452 | 47 |
allRoomsS :: StateT ServerState IO [RoomInfo] |
48 |
allRoomsS = gets roomsClients >>= liftIO . roomsM |
|
49 |
||
4989 | 50 |
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo] |
3502 | 51 |
roomClientsS ri = do |
52 |
rnc <- gets roomsClients |
|
4622 | 53 |
io $ roomClientsM rnc ri |
4601 | 54 |
|
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
f = filter (\c -> clientProto c == p) |
8371 | 59 |
|
4989 | 60 |
io :: IO a -> StateT ServerState IO a |
4601 | 61 |
io = liftIO |