gameServer/RoomsAndClients.hs
branchhedgeroid
changeset 15510 7030706266df
parent 11046 47a8c19ecb60
equal deleted inserted replaced
7861:bc7b6aa5d67a 15510:7030706266df
       
     1 {-
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
       
    17  \-}
       
    18 
     1 {-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving #-}
    19 {-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving #-}
     2 
    20 
     3 module RoomsAndClients(
    21 module RoomsAndClients(
     4     RoomIndex(),
    22     RoomIndex(),
     5     ClientIndex(),
    23     ClientIndex(),
    20     client,
    38     client,
    21     room,
    39     room,
    22     client'sM,
    40     client'sM,
    23     room'sM,
    41     room'sM,
    24     allClientsM,
    42     allClientsM,
       
    43     allRoomsM,
    25     clientsM,
    44     clientsM,
       
    45     roomsM,
    26     roomClientsM,
    46     roomClientsM,
    27     roomClientsIndicesM,
    47     roomClientsIndicesM,
    28     withRoomsAndClients,
    48     withRoomsAndClients,
    29     allRooms,
    49     allRooms,
    30     allClients,
    50     allClients,
   155 room'sM (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = liftM (f . room') (rooms `readElem` ri)
   175 room'sM (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = liftM (f . room') (rooms `readElem` ri)
   156 
   176 
   157 allClientsM :: MRoomsAndClients r c -> IO [ClientIndex]
   177 allClientsM :: MRoomsAndClients r c -> IO [ClientIndex]
   158 allClientsM (MRoomsAndClients (_, clients)) = liftM (map ClientIndex) $ indicesM clients
   178 allClientsM (MRoomsAndClients (_, clients)) = liftM (map ClientIndex) $ indicesM clients
   159 
   179 
       
   180 allRoomsM :: MRoomsAndClients r c -> IO [RoomIndex]
       
   181 allRoomsM (MRoomsAndClients (rooms, _)) = liftM (map RoomIndex) $ indicesM rooms
       
   182 
   160 clientsM :: MRoomsAndClients r c -> IO [c]
   183 clientsM :: MRoomsAndClients r c -> IO [c]
   161 clientsM (MRoomsAndClients (_, clients)) = indicesM clients >>= mapM (liftM client' . readElem clients)
   184 clientsM (MRoomsAndClients (_, clients)) = indicesM clients >>= mapM (liftM client' . readElem clients)
       
   185 
       
   186 roomsM :: MRoomsAndClients r c -> IO [r]
       
   187 roomsM (MRoomsAndClients (rooms, _)) = indicesM rooms >>= mapM (liftM room' . readElem rooms)
   162 
   188 
   163 roomClientsIndicesM :: MRoomsAndClients r c -> RoomIndex -> IO [ClientIndex]
   189 roomClientsIndicesM :: MRoomsAndClients r c -> RoomIndex -> IO [ClientIndex]
   164 roomClientsIndicesM (MRoomsAndClients (rooms, _)) (RoomIndex ri) = liftM roomClients' (rooms `readElem` ri)
   190 roomClientsIndicesM (MRoomsAndClients (rooms, _)) (RoomIndex ri) = liftM roomClients' (rooms `readElem` ri)
   165 
   191 
   166 roomClientsM :: MRoomsAndClients r c -> RoomIndex -> IO [c]
   192 roomClientsM :: MRoomsAndClients r c -> RoomIndex -> IO [c]