gameServer/ServerState.hs
branchhedgeroid
changeset 15510 7030706266df
parent 11046 47a8c19ecb60
child 15983 2c92499daa67
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 module ServerState
    19 module ServerState
     2     (
    20     (
     3     module RoomsAndClients,
    21     module RoomsAndClients,
       
    22     module JoinsMonitor,
     4     clientRoomA,
    23     clientRoomA,
     5     ServerState(..),
    24     ServerState(..),
     6     client's,
    25     client's,
     7     allClientsS,
    26     allClientsS,
       
    27     allRoomsS,
     8     roomClientsS,
    28     roomClientsS,
     9     sameProtoClientsS,
    29     sameProtoClientsS,
    10     io
    30     io
    11     ) where
    31     ) where
    12 
    32 
    14 import Data.Set as Set(Set)
    34 import Data.Set as Set(Set)
    15 import Data.Word
    35 import Data.Word
    16 ----------------------
    36 ----------------------
    17 import RoomsAndClients
    37 import RoomsAndClients
    18 import CoreTypes
    38 import CoreTypes
       
    39 import JoinsMonitor
    19 
    40 
    20 data ServerState = ServerState {
    41 data ServerState = ServerState {
    21         clientIndex :: !(Maybe ClientIndex),
    42         clientIndex :: !(Maybe ClientIndex),
    22         serverInfo :: !ServerInfo,
    43         serverInfo :: !ServerInfo,
    23         removedClients :: !(Set.Set ClientIndex),
    44         removedClients :: !(Set.Set ClientIndex),
    24         roomsClients :: !MRnC
    45         roomsClients :: !MRnC,
       
    46         joinsMonitor :: !JoinsMonitor
    25     }
    47     }
    26 
    48 
    27 
    49 
    28 clientRoomA :: StateT ServerState IO RoomIndex
    50 clientRoomA :: StateT ServerState IO RoomIndex
    29 clientRoomA = do
    51 clientRoomA = do
    38     io $ client'sM rnc f ci
    60     io $ client'sM rnc f ci
    39 
    61 
    40 allClientsS :: StateT ServerState IO [ClientInfo]
    62 allClientsS :: StateT ServerState IO [ClientInfo]
    41 allClientsS = gets roomsClients >>= liftIO . clientsM
    63 allClientsS = gets roomsClients >>= liftIO . clientsM
    42 
    64 
       
    65 allRoomsS :: StateT ServerState IO [RoomInfo]
       
    66 allRoomsS = gets roomsClients >>= liftIO . roomsM
       
    67 
    43 roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
    68 roomClientsS :: RoomIndex -> StateT ServerState IO [ClientInfo]
    44 roomClientsS ri = do
    69 roomClientsS ri = do
    45     rnc <- gets roomsClients
    70     rnc <- gets roomsClients
    46     io $ roomClientsM rnc ri
    71     io $ roomClientsM rnc ri
    47 
    72 
    48 sameProtoClientsS :: Word16 -> StateT ServerState IO [ClientInfo]
    73 sameProtoClientsS :: Word16 -> StateT ServerState IO [ClientInfo]
    49 sameProtoClientsS p = liftM f allClientsS
    74 sameProtoClientsS p = liftM f allClientsS
    50     where
    75     where
    51         f = filter (\c -> clientProto c == p)
    76         f = filter (\c -> clientProto c == p)
    52     
    77 
    53 io :: IO a -> StateT ServerState IO a
    78 io :: IO a -> StateT ServerState IO a
    54 io = liftIO
    79 io = liftIO