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