gameServer/RoomsAndClients.hs
author unc0rr
Tue, 31 Dec 2013 00:17:58 +0400
changeset 9882 8efe8d4deba9
parent 8452 170afc3ac39f
child 10215 26fc5502ba22
permissions -rw-r--r--
Not a thing which is needed in release tarball
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
     1
{-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving #-}
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
     2
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     3
module RoomsAndClients(
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     4
    RoomIndex(),
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     5
    ClientIndex(),
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     6
    MRoomsAndClients(),
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     7
    IRoomsAndClients(),
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     8
    newRoomsAndClients,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
     9
    addRoom,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    10
    addClient,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    11
    removeRoom,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    12
    removeClient,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    13
    modifyRoom,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    14
    modifyClient,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    15
    lobbyId,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    16
    moveClientToLobby,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    17
    moveClientToRoom,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    18
    clientRoomM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    19
    clientExists,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    20
    client,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    21
    room,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    22
    client'sM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    23
    room'sM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    24
    allClientsM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    25
    clientsM,
8452
170afc3ac39f Also rooms per version stats
unc0rr
parents: 6805
diff changeset
    26
    roomsM,
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    27
    roomClientsM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    28
    roomClientsIndicesM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    29
    withRoomsAndClients,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    30
    allRooms,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    31
    allClients,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    32
    clientRoom,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    33
    showRooms,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    34
    roomClients
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    35
    ) where
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    36
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    37
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    38
import Store
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    39
import Control.Monad
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    40
import Control.DeepSeq
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    41
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    42
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    43
data Room r = Room {
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    44
    roomClients' :: ![ClientIndex],
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    45
    room' :: !r
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    46
    }
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    47
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    48
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    49
data Client c = Client {
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    50
    clientRoom' :: !RoomIndex,
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    51
    client' :: !c
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    52
    }
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    53
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    54
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    55
newtype RoomIndex = RoomIndex ElemIndex
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    56
    deriving (Eq, NFData)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    57
newtype ClientIndex = ClientIndex ElemIndex
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    58
    deriving (Eq, Show, Read, Ord, NFData)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    59
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    60
instance Show RoomIndex where
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    61
    show (RoomIndex i) = 'r' : show i
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    62
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    63
unRoomIndex :: RoomIndex -> ElemIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    64
unRoomIndex (RoomIndex r) = r
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    65
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    66
unClientIndex :: ClientIndex -> ElemIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    67
unClientIndex (ClientIndex c) = c
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    68
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    69
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    70
newtype MRoomsAndClients r c = MRoomsAndClients (MStore (Room r), MStore (Client c))
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    71
newtype IRoomsAndClients r c = IRoomsAndClients (IStore (Room r), IStore (Client c))
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    72
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    73
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    74
lobbyId :: RoomIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    75
lobbyId = RoomIndex firstIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    76
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    77
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    78
newRoomsAndClients :: r -> IO (MRoomsAndClients r c)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    79
newRoomsAndClients r = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    80
    rooms <- newStore
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    81
    clients <- newStore
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    82
    let rnc = MRoomsAndClients (rooms, clients)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    83
    ri <- addRoom rnc r
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    84
    when (ri /= lobbyId) $ error "Empty struct inserts not at firstIndex index"
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    85
    return rnc
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    86
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    87
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    88
roomAddClient :: ClientIndex -> Room r -> Room r
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    89
roomAddClient cl rm = let cls = cl : roomClients' rm; nr = rm{roomClients' = cls} in cls `deepseq` nr
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    90
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    91
roomRemoveClient :: ClientIndex -> Room r -> Room r
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    92
roomRemoveClient cl rm = let cls = filter (/= cl) $ roomClients' rm; nr = rm{roomClients' = cls} in cls `deepseq` nr
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    93
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    94
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    95
addRoom :: MRoomsAndClients r c -> r -> IO RoomIndex
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    96
addRoom (MRoomsAndClients (rooms, _)) rm = do
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    97
    i <- addElem rooms (Room  [] rm)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    98
    return $ RoomIndex i
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    99
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   100
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   101
addClient :: MRoomsAndClients r c -> c -> IO ClientIndex
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   102
addClient (MRoomsAndClients (rooms, clients)) cl = do
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   103
    i <- addElem clients (Client lobbyId cl)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   104
    modifyElem rooms (roomAddClient (ClientIndex i)) (unRoomIndex lobbyId)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   105
    return $ ClientIndex i
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   106
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   107
removeRoom :: MRoomsAndClients r c -> RoomIndex -> IO ()
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   108
removeRoom rnc@(MRoomsAndClients (rooms, _)) rm@(RoomIndex ri)
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   109
    | rm == lobbyId = error "Cannot delete lobby"
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   110
    | otherwise = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   111
        clIds <- liftM roomClients' $ readElem rooms ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   112
        forM_ clIds (moveClientToLobby rnc)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   113
        removeElem rooms ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   114
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   115
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   116
removeClient :: MRoomsAndClients r c -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   117
removeClient (MRoomsAndClients (rooms, clients)) cl@(ClientIndex ci) = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   118
    RoomIndex ri <- liftM clientRoom' $ readElem clients ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   119
    modifyElem rooms (roomRemoveClient cl) ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   120
    removeElem clients ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   121
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   122
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   123
modifyRoom :: MRoomsAndClients r c -> (r -> r) -> RoomIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   124
modifyRoom (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = modifyElem rooms (\r -> r{room' = f $ room' r}) ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   125
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   126
modifyClient :: MRoomsAndClients r c -> (c -> c) -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   127
modifyClient (MRoomsAndClients (_, clients)) f (ClientIndex ci) = modifyElem clients (\c -> c{client' = f $ client' c}) ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   128
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   129
moveClientInRooms :: MRoomsAndClients r c -> RoomIndex -> RoomIndex -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   130
moveClientInRooms (MRoomsAndClients (rooms, clients)) (RoomIndex riFrom) rt@(RoomIndex riTo) cl@(ClientIndex ci) = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   131
    modifyElem rooms (roomRemoveClient cl) riFrom
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   132
    modifyElem rooms (roomAddClient cl) riTo
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   133
    modifyElem clients (\c -> c{clientRoom' = rt}) ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   134
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   135
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   136
moveClientToLobby :: MRoomsAndClients r c -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   137
moveClientToLobby rnc ci = do
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   138
    rm <- clientRoomM rnc ci
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   139
    moveClientInRooms rnc rm lobbyId ci
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   140
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   141
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   142
moveClientToRoom :: MRoomsAndClients r c -> RoomIndex -> ClientIndex -> IO ()
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   143
moveClientToRoom rnc = moveClientInRooms rnc lobbyId
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   144
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   145
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   146
clientExists :: MRoomsAndClients r c -> ClientIndex -> IO Bool
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   147
clientExists (MRoomsAndClients (_, clients)) (ClientIndex ci) = elemExists clients ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   148
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   149
clientRoomM :: MRoomsAndClients r c -> ClientIndex -> IO RoomIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   150
clientRoomM (MRoomsAndClients (_, clients)) (ClientIndex ci) = liftM clientRoom' (clients `readElem` ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   151
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   152
client'sM :: MRoomsAndClients r c -> (c -> a) -> ClientIndex -> IO a
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   153
client'sM (MRoomsAndClients (_, clients)) f (ClientIndex ci) = liftM (f . client') (clients `readElem` ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   154
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   155
room'sM :: MRoomsAndClients r c -> (r -> a) -> RoomIndex -> IO a
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   156
room'sM (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = liftM (f . room') (rooms `readElem` ri)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   157
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   158
allClientsM :: MRoomsAndClients r c -> IO [ClientIndex]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   159
allClientsM (MRoomsAndClients (_, clients)) = liftM (map ClientIndex) $ indicesM clients
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   160
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   161
clientsM :: MRoomsAndClients r c -> IO [c]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   162
clientsM (MRoomsAndClients (_, clients)) = indicesM clients >>= mapM (liftM client' . readElem clients)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   163
8452
170afc3ac39f Also rooms per version stats
unc0rr
parents: 6805
diff changeset
   164
roomsM :: MRoomsAndClients r c -> IO [r]
170afc3ac39f Also rooms per version stats
unc0rr
parents: 6805
diff changeset
   165
roomsM (MRoomsAndClients (rooms, _)) = indicesM rooms >>= mapM (liftM room' . readElem rooms)
170afc3ac39f Also rooms per version stats
unc0rr
parents: 6805
diff changeset
   166
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   167
roomClientsIndicesM :: MRoomsAndClients r c -> RoomIndex -> IO [ClientIndex]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   168
roomClientsIndicesM (MRoomsAndClients (rooms, _)) (RoomIndex ri) = liftM roomClients' (rooms `readElem` ri)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   169
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   170
roomClientsM :: MRoomsAndClients r c -> RoomIndex -> IO [c]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   171
roomClientsM (MRoomsAndClients (rooms, clients)) (RoomIndex ri) = liftM roomClients' (rooms `readElem` ri) >>= mapM (\(ClientIndex ci) -> liftM client' $ readElem clients ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   172
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   173
withRoomsAndClients :: MRoomsAndClients r c -> (IRoomsAndClients r c -> a) -> IO a
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   174
withRoomsAndClients (MRoomsAndClients (rooms, clients)) f =
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   175
    withIStore2 rooms clients (\r c -> f $ IRoomsAndClients (r, c))
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   176
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   177
----------------------------------------
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   178
----------- IRoomsAndClients -----------
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   179
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   180
showRooms :: (Show r, Show c) => IRoomsAndClients r c -> String
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   181
showRooms rnc@(IRoomsAndClients (rooms, clients)) = concatMap showRoom (allRooms rnc)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   182
    where
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   183
    showRoom r = unlines $ (show r ++ ": " ++ (show . room' $ rooms ! unRoomIndex r)) : map showClient (roomClients' $ rooms ! unRoomIndex r)
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   184
    showClient c = "    " ++ show c ++ ": " ++ (show . client' $ clients ! unClientIndex c)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   185
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   186
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   187
allRooms :: IRoomsAndClients r c -> [RoomIndex]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   188
allRooms (IRoomsAndClients (rooms, _)) = map RoomIndex $ indices rooms
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   189
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   190
allClients :: IRoomsAndClients r c -> [ClientIndex]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   191
allClients (IRoomsAndClients (_, clients)) = map ClientIndex $ indices clients
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   192
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   193
clientRoom :: IRoomsAndClients r c -> ClientIndex -> RoomIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   194
clientRoom (IRoomsAndClients (_, clients)) (ClientIndex ci) = clientRoom' (clients ! ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   195
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   196
client :: IRoomsAndClients r c -> ClientIndex -> c
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   197
client (IRoomsAndClients (_, clients)) (ClientIndex ci) = client' (clients ! ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   198
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   199
room :: IRoomsAndClients r c -> RoomIndex -> r
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   200
room (IRoomsAndClients (rooms, _)) (RoomIndex ri) = room' (rooms ! ri)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   201
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   202
roomClients :: IRoomsAndClients r c -> RoomIndex -> [ClientIndex]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   203
roomClients (IRoomsAndClients (rooms, _)) (RoomIndex ri) = roomClients' (rooms ! ri)