netserver/Miscutils.hs
changeset 1492 2da1fe033f23
parent 1491 0b1f44751509
child 1493 1e422bc5d863
equal deleted inserted replaced
1491:0b1f44751509 1492:2da1fe033f23
     6 import Data.Char
     6 import Data.Char
     7 import Data.List
     7 import Data.List
     8 import Maybe (fromJust)
     8 import Maybe (fromJust)
     9 import qualified Data.Map as Map
     9 import qualified Data.Map as Map
    10 import Data.Time
    10 import Data.Time
       
    11 import Network
    11 
    12 
    12 data ClientInfo =
    13 data ClientInfo =
    13  ClientInfo
    14  ClientInfo
    14 	{
    15 	{
    15 		chan :: TChan [String],
    16 		chan :: TChan [String],
    56 		readyPlayers :: Int,
    57 		readyPlayers :: Int,
    57 		isRestrictedJoins :: Bool,
    58 		isRestrictedJoins :: Bool,
    58 		isRestrictedTeams :: Bool,
    59 		isRestrictedTeams :: Bool,
    59 		params :: Map.Map String [String]
    60 		params :: Map.Map String [String]
    60 	}
    61 	}
    61 createRoom = (RoomInfo "" "" 0 [] "+rnd+" False 1 0 False False Map.empty)
    62 createRoom = (
       
    63 	RoomInfo
       
    64 		""
       
    65 		""
       
    66 		0
       
    67 		[]
       
    68 		"+rnd+"
       
    69 		False
       
    70 		1
       
    71 		0
       
    72 		False
       
    73 		False
       
    74 		Map.empty
       
    75 	)
    62 
    76 
    63 data ServerInfo =
    77 data ServerInfo =
    64 	ServerInfo
    78 	ServerInfo
    65 	{
    79 	{
    66 		message :: String
    80 		isDedicated :: Bool,
       
    81 		serverMessage :: String,
       
    82 		listenPort :: PortNumber
    67 	}
    83 	}
       
    84 newServerInfo = (
       
    85 	ServerInfo
       
    86 		True
       
    87 		"<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>"
       
    88 		46631
       
    89 	)
    68 
    90 
    69 type ClientsTransform = [ClientInfo] -> [ClientInfo]
    91 type ClientsTransform = [ClientInfo] -> [ClientInfo]
    70 type RoomsTransform = [RoomInfo] -> [RoomInfo]
    92 type RoomsTransform = [RoomInfo] -> [RoomInfo]
    71 type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [Handle]
    93 type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [Handle]
    72 type Answer = (HandlesSelector, [String])
    94 type Answer = ServerInfo -> (HandlesSelector, [String])
    73 type CmdHandler = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientsTransform, RoomsTransform, [Answer])
    95 type CmdHandler = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientsTransform, RoomsTransform, [Answer])
    74 
    96 
    75 
    97 
    76 roomByName :: String -> [RoomInfo] -> RoomInfo
    98 roomByName :: String -> [RoomInfo] -> RoomInfo
    77 roomByName roomName rooms = fromJust $ find (\room -> roomName == name room) rooms
    99 roomByName roomName rooms = fromJust $ find (\room -> roomName == name room) rooms