gameServer/ServerState.hs
author unc0rr
Sun, 06 Jun 2010 19:03:06 +0000
changeset 3501 a3159a410e5c
parent 3458 11cd56019f00
child 3502 ad38c653b7d9
permissions -rw-r--r--
Reimplement more core actions
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,
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     4
    clientRoomA,
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     5
    ServerState(..),
3501
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
     6
    client's,
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
     7
    allClientsS
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     8
    ) where
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
     9
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    10
import Control.Monad.State
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    11
----------------------
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    12
import RoomsAndClients
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    13
import CoreTypes
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    14
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    15
data ServerState = ServerState {
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    16
        clientIndex :: Maybe ClientIndex,
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    17
        serverInfo :: ServerInfo,
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    18
        roomsClients :: MRnC
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    19
    }
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    20
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    21
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    22
clientRoomA :: StateT ServerState IO RoomIndex
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    23
clientRoomA = do
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    24
    (Just ci) <- gets clientIndex
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    25
    rnc <- gets roomsClients
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    26
    liftIO $ clientRoomM rnc ci
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    27
3501
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    28
client's :: (ClientInfo -> a) -> StateT ServerState IO a
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    29
client's f = do
3458
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    30
    (Just ci) <- gets clientIndex
11cd56019f00 Make some more protocol commands work
unc0rr
parents:
diff changeset
    31
    rnc <- gets roomsClients
3501
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    32
    liftIO $ client'sM rnc f ci
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    33
    
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    34
allClientsS :: StateT ServerState IO [ClientInfo]
a3159a410e5c Reimplement more core actions
unc0rr
parents: 3458
diff changeset
    35
allClientsS = gets roomsClients >>= liftIO . clientsM