gameServer/RoomsAndClients.hs
author unc0rr
Fri, 25 May 2012 00:06:42 +0400
changeset 7124 cfee05712896
parent 6805 097289be7200
child 8452 170afc3ac39f
permissions -rw-r--r--
- Restore pre-r9257cf8e7af2 behavior - Get rid of leftTeams, send REMOVE_TEAM immediately instead
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,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    26
    roomClientsM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    27
    roomClientsIndicesM,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    28
    withRoomsAndClients,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    29
    allRooms,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    30
    allClients,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    31
    clientRoom,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    32
    showRooms,
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    33
    roomClients
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    34
    ) where
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    35
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    36
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    37
import Store
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    38
import Control.Monad
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    39
import Control.DeepSeq
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    40
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    41
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    42
data Room r = Room {
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    43
    roomClients' :: ![ClientIndex],
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    44
    room' :: !r
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    45
    }
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
data Client c = Client {
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    49
    clientRoom' :: !RoomIndex,
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    50
    client' :: !c
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    51
    }
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
newtype RoomIndex = RoomIndex ElemIndex
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    55
    deriving (Eq, NFData)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    56
newtype ClientIndex = ClientIndex ElemIndex
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    57
    deriving (Eq, Show, Read, Ord, NFData)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    58
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    59
instance Show RoomIndex where
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    60
    show (RoomIndex i) = 'r' : show i
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    61
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    62
unRoomIndex :: RoomIndex -> ElemIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    63
unRoomIndex (RoomIndex r) = r
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    64
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    65
unClientIndex :: ClientIndex -> ElemIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    66
unClientIndex (ClientIndex c) = c
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    67
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    68
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    69
newtype MRoomsAndClients r c = MRoomsAndClients (MStore (Room r), MStore (Client c))
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    70
newtype IRoomsAndClients r c = IRoomsAndClients (IStore (Room r), IStore (Client c))
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    71
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    72
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    73
lobbyId :: RoomIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    74
lobbyId = RoomIndex firstIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    75
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    76
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    77
newRoomsAndClients :: r -> IO (MRoomsAndClients r c)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    78
newRoomsAndClients r = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    79
    rooms <- newStore
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    80
    clients <- newStore
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    81
    let rnc = MRoomsAndClients (rooms, clients)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    82
    ri <- addRoom rnc r
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    83
    when (ri /= lobbyId) $ error "Empty struct inserts not at firstIndex index"
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    84
    return rnc
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    85
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    86
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    87
roomAddClient :: ClientIndex -> Room r -> Room r
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    88
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
    89
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    90
roomRemoveClient :: ClientIndex -> Room r -> Room r
6805
097289be7200 Add more strictness in hope it will help with space leak
unc0rr
parents: 4932
diff changeset
    91
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
    92
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    93
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    94
addRoom :: MRoomsAndClients r c -> r -> IO RoomIndex
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    95
addRoom (MRoomsAndClients (rooms, _)) rm = do
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
    96
    i <- addElem rooms (Room  [] rm)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    97
    return $ RoomIndex i
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    98
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
    99
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   100
addClient :: MRoomsAndClients r c -> c -> IO ClientIndex
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   101
addClient (MRoomsAndClients (rooms, clients)) cl = do
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   102
    i <- addElem clients (Client lobbyId cl)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   103
    modifyElem rooms (roomAddClient (ClientIndex i)) (unRoomIndex lobbyId)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   104
    return $ ClientIndex i
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   105
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   106
removeRoom :: MRoomsAndClients r c -> RoomIndex -> IO ()
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   107
removeRoom rnc@(MRoomsAndClients (rooms, _)) rm@(RoomIndex ri)
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   108
    | rm == lobbyId = error "Cannot delete lobby"
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   109
    | otherwise = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   110
        clIds <- liftM roomClients' $ readElem rooms ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   111
        forM_ clIds (moveClientToLobby rnc)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   112
        removeElem rooms ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   113
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   114
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   115
removeClient :: MRoomsAndClients r c -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   116
removeClient (MRoomsAndClients (rooms, clients)) cl@(ClientIndex ci) = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   117
    RoomIndex ri <- liftM clientRoom' $ readElem clients ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   118
    modifyElem rooms (roomRemoveClient cl) ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   119
    removeElem clients ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   120
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   121
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   122
modifyRoom :: MRoomsAndClients r c -> (r -> r) -> RoomIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   123
modifyRoom (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = modifyElem rooms (\r -> r{room' = f $ room' r}) ri
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   124
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   125
modifyClient :: MRoomsAndClients r c -> (c -> c) -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   126
modifyClient (MRoomsAndClients (_, clients)) f (ClientIndex ci) = modifyElem clients (\c -> c{client' = f $ client' c}) ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   127
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   128
moveClientInRooms :: MRoomsAndClients r c -> RoomIndex -> RoomIndex -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   129
moveClientInRooms (MRoomsAndClients (rooms, clients)) (RoomIndex riFrom) rt@(RoomIndex riTo) cl@(ClientIndex ci) = do
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   130
    modifyElem rooms (roomRemoveClient cl) riFrom
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   131
    modifyElem rooms (roomAddClient cl) riTo
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   132
    modifyElem clients (\c -> c{clientRoom' = rt}) ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   133
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   134
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   135
moveClientToLobby :: MRoomsAndClients r c -> ClientIndex -> IO ()
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   136
moveClientToLobby rnc ci = do
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   137
    rm <- clientRoomM rnc ci
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   138
    moveClientInRooms rnc rm lobbyId ci
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   139
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   140
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   141
moveClientToRoom :: MRoomsAndClients r c -> RoomIndex -> ClientIndex -> IO ()
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   142
moveClientToRoom rnc = moveClientInRooms rnc lobbyId
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   143
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   144
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   145
clientExists :: MRoomsAndClients r c -> ClientIndex -> IO Bool
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   146
clientExists (MRoomsAndClients (_, clients)) (ClientIndex ci) = elemExists clients ci
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   147
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   148
clientRoomM :: MRoomsAndClients r c -> ClientIndex -> IO RoomIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   149
clientRoomM (MRoomsAndClients (_, clients)) (ClientIndex ci) = liftM clientRoom' (clients `readElem` ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   150
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   151
client'sM :: MRoomsAndClients r c -> (c -> a) -> ClientIndex -> IO a
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   152
client'sM (MRoomsAndClients (_, clients)) f (ClientIndex ci) = liftM (f . client') (clients `readElem` ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   153
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   154
room'sM :: MRoomsAndClients r c -> (r -> a) -> RoomIndex -> IO a
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   155
room'sM (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = liftM (f . room') (rooms `readElem` ri)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   156
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   157
allClientsM :: MRoomsAndClients r c -> IO [ClientIndex]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   158
allClientsM (MRoomsAndClients (_, clients)) = liftM (map ClientIndex) $ indicesM clients
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   159
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   160
clientsM :: MRoomsAndClients r c -> IO [c]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   161
clientsM (MRoomsAndClients (_, clients)) = indicesM clients >>= mapM (liftM client' . readElem clients)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   162
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   163
roomClientsIndicesM :: MRoomsAndClients r c -> RoomIndex -> IO [ClientIndex]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   164
roomClientsIndicesM (MRoomsAndClients (rooms, _)) (RoomIndex ri) = liftM roomClients' (rooms `readElem` ri)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   165
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   166
roomClientsM :: MRoomsAndClients r c -> RoomIndex -> IO [c]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   167
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
   168
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   169
withRoomsAndClients :: MRoomsAndClients r c -> (IRoomsAndClients r c -> a) -> IO a
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   170
withRoomsAndClients (MRoomsAndClients (rooms, clients)) f =
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   171
    withIStore2 rooms clients (\r c -> f $ IRoomsAndClients (r, c))
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   172
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   173
----------------------------------------
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   174
----------- IRoomsAndClients -----------
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   175
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   176
showRooms :: (Show r, Show c) => IRoomsAndClients r c -> String
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   177
showRooms rnc@(IRoomsAndClients (rooms, clients)) = concatMap showRoom (allRooms rnc)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   178
    where
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   179
    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
   180
    showClient c = "    " ++ show c ++ ": " ++ (show . client' $ clients ! unClientIndex c)
4905
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   181
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   182
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   183
allRooms :: IRoomsAndClients r c -> [RoomIndex]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   184
allRooms (IRoomsAndClients (rooms, _)) = map RoomIndex $ indices rooms
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   185
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   186
allClients :: IRoomsAndClients r c -> [ClientIndex]
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   187
allClients (IRoomsAndClients (_, clients)) = map ClientIndex $ indices clients
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   188
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   189
clientRoom :: IRoomsAndClients r c -> ClientIndex -> RoomIndex
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   190
clientRoom (IRoomsAndClients (_, clients)) (ClientIndex ci) = clientRoom' (clients ! ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   191
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   192
client :: IRoomsAndClients r c -> ClientIndex -> c
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   193
client (IRoomsAndClients (_, clients)) (ClientIndex ci) = client' (clients ! ci)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   194
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   195
room :: IRoomsAndClients r c -> RoomIndex -> r
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   196
room (IRoomsAndClients (rooms, _)) (RoomIndex ri) = room' (rooms ! ri)
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   197
7842d085acf4 Fix merge :D
unc0rr
parents:
diff changeset
   198
roomClients :: IRoomsAndClients r c -> RoomIndex -> [ClientIndex]
4932
f11d80bac7ed - Take into account hlint suggestions
unc0rr
parents: 4905
diff changeset
   199
roomClients (IRoomsAndClients (rooms, _)) (RoomIndex ri) = roomClients' (rooms ! ri)