gameServer/ServerState.hs
author nemo
Sun, 09 Mar 2014 20:53:11 -0400
changeset 10188 e8f2dbabd01b
parent 9973 7589978c9912
child 10460 8dcea9087d75
permissions -rw-r--r--
as suggested, precompute to avoid use of double
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     1
module ServerState
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     2
    (
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     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
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     5
    clientRoomA,
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     6
    ServerState(..),
3501
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
     7
    client's,
3502
ad38c653b7d9 Some more progress
unc0rr
parents: 3501
diff changeset
     8
    allClientsS,
8452
170afc3ac39f Also rooms per version stats
unc0rr
parents: 8371
diff changeset
     9
    allRoomsS,
4601
08ae94dd4c0d io = liftIO
unc0rr
parents: 3807
diff changeset
    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
08ae94dd4c0d io = liftIO
unc0rr
parents: 3807
diff changeset
    12
    io
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    13
    ) where
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    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
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    18
----------------------
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    19
import RoomsAndClients
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    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
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    22
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    23
data ServerState = ServerState {
3807
7e4f7ed41790 zero span is undefined, use -1 instead
unc0rr
parents: 3741
diff changeset
    24
        clientIndex :: !(Maybe ClientIndex),
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    25
        serverInfo :: !ServerInfo,
3807
7e4f7ed41790 zero span is undefined, use -1 instead
unc0rr
parents: 3741
diff changeset
    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
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    29
    }
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    30
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    31
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    32
clientRoomA :: StateT ServerState IO RoomIndex
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    33
clientRoomA = do
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    34
    (Just ci) <- gets clientIndex
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    35
    rnc <- gets roomsClients
4622
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4601
diff changeset
    36
    io $ clientRoomM rnc ci
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    37
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    38
client's :: (ClientInfo -> a) -> StateT ServerState IO a
3501
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    39
client's f = do
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    40
    (Just ci) <- gets clientIndex
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    41
    rnc <- gets roomsClients
4622
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4601
diff changeset
    42
    io $ client'sM rnc f ci
3645
c0b3f1bb9316 Reimplement REMOVE_TEAM
unc0rr
parents: 3566
diff changeset
    43
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    44
allClientsS :: StateT ServerState IO [ClientInfo]
3502
ad38c653b7d9 Some more progress
unc0rr
parents: 3501
diff changeset
    45
allClientsS = gets roomsClients >>= liftIO . clientsM
ad38c653b7d9 Some more progress
unc0rr
parents: 3501
diff changeset
    46
8452
170afc3ac39f Also rooms per version stats
unc0rr
parents: 8371
diff changeset
    47
allRoomsS :: StateT ServerState IO [RoomInfo]
170afc3ac39f Also rooms per version stats
unc0rr
parents: 8371
diff changeset
    48
allRoomsS = gets roomsClients >>= liftIO . roomsM
170afc3ac39f Also rooms per version stats
unc0rr
parents: 8371
diff changeset
    49
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    50
roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
3502
ad38c653b7d9 Some more progress
unc0rr
parents: 3501
diff changeset
    51
roomClientsS ri = do
ad38c653b7d9 Some more progress
unc0rr
parents: 3501
diff changeset
    52
    rnc <- gets roomsClients
4622
8bdc879ee6b2 Implement room delegation when admin lefts it
unc0rr
parents: 4601
diff changeset
    53
    io $ roomClientsM rnc ri
4601
08ae94dd4c0d io = liftIO
unc0rr
parents: 3807
diff changeset
    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
0551b5c3de9a - Start work on checker
unc0rr
parents: 6541
diff changeset
    59
4989
4771fed9272e - Write server config into .ini file on change
unc0rr
parents: 4975
diff changeset
    60
io :: IO a -> StateT ServerState IO a
4601
08ae94dd4c0d io = liftIO
unc0rr
parents: 3807
diff changeset
    61
io = liftIO