gameServer/CoreTypes.hs
author unc0rr
Mon, 23 Feb 2009 20:39:31 +0000
changeset 1835 a55d16c645a1
parent 1833 e901ec5644b4
child 1839 5dd4cb7fd7e5
permissions -rw-r--r--
Update Italian translation (and compile other translations)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     1
module CoreTypes where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     2
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     3
import System.IO
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     4
import Control.Concurrent.Chan
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     5
import Control.Concurrent.STM
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     6
import Data.Word
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     7
import qualified Data.Map as Map
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     8
import qualified Data.IntMap as IntMap
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     9
import qualified Data.IntSet as IntSet
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    10
import Data.Sequence(Seq, empty)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    11
import Network
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    12
1833
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
    13
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    14
data ClientInfo =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    15
 ClientInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    16
	{
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    17
		clientUID :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    18
		sendChan :: Chan [String],
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    19
		clientHandle :: Handle,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
		host :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
		nick :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    22
		clientProto :: Word16,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    23
		roomID :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    24
		isMaster :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    25
		isReady :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    26
		forceQuit :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    27
		partRoom :: Bool
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    28
	}
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    29
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    30
instance Show ClientInfo where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    31
	show ci = show $ clientUID ci
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    32
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    33
instance Eq ClientInfo where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    34
	a1 == a2 = clientHandle a1 == clientHandle a2
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    35
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    36
data HedgehogInfo =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    37
	HedgehogInfo String String
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    38
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    39
data TeamInfo =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    40
	TeamInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    41
	{
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    42
		teamowner :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    43
		teamname :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    44
		teamcolor :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    45
		teamgrave :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    46
		teamfort :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    47
		teamvoicepack :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    48
		difficulty :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    49
		hhnum :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    50
		hedgehogs :: [HedgehogInfo]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    51
	}
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    52
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    53
data RoomInfo =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    54
	RoomInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    55
	{
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    56
		roomUID :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    57
		name :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    58
		password :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    59
		roomProto :: Word16,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    60
		teams :: [TeamInfo],
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    61
		gameinprogress :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    62
		playersIn :: !Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    63
		readyPlayers :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    64
		playersIDs :: IntSet.IntSet,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    65
		isRestrictedJoins :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    66
		isRestrictedTeams :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    67
		roundMsgs :: Seq String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    68
		leftTeams :: [String],
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    69
		teamsAtStart :: [TeamInfo],
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    70
		params :: Map.Map String [String]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    71
	}
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    72
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    73
instance Show RoomInfo where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    74
	show ri = (show $ roomUID ri)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    75
			++ ", players ids: " ++ (show $ IntSet.size $ playersIDs ri)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    76
			++ ", players: " ++ (show $ playersIn ri)
1824
fbe1fa777d68 More verbose dump
unc0rr
parents: 1804
diff changeset
    77
			++ ", ready: " ++ (show $ readyPlayers ri)
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    78
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    79
instance Eq RoomInfo where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    80
	a1 == a2 = roomUID a1 == roomUID a2
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    81
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    82
newRoom = (
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    83
	RoomInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    84
		0
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    85
		""
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    86
		""
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    87
		0
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    88
		[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    89
		False
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    90
		0
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    91
		0
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    92
		IntSet.empty
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    93
		False
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    94
		False
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    95
		Data.Sequence.empty
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    96
		[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    97
		[]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    98
		(Map.singleton "MAP" ["+rnd+"])
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    99
	)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   100
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   101
data StatisticsInfo =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   102
	StatisticsInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   103
	{
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   104
		playersNumber :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   105
		roomsNumber :: Int
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   106
	}
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   107
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   108
data ServerInfo =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   109
	ServerInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   110
	{
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   111
		isDedicated :: Bool,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   112
		serverMessage :: String,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   113
		listenPort :: PortNumber,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   114
		loginsNumber :: Int,
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   115
		nextRoomID :: Int,
1832
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1824
diff changeset
   116
		dbHost :: String,
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1824
diff changeset
   117
		dbLogin :: String,
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1824
diff changeset
   118
		dbPassword :: String,
1833
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
   119
		stats :: TMVar StatisticsInfo,
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
   120
		dbQueries :: Chan DBQuery
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   121
	}
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   122
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   123
instance Show ServerInfo where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   124
	show si = "Logins: " ++ (show $ loginsNumber si)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   125
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   126
newServerInfo = (
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   127
	ServerInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   128
		True
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   129
		"<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>"
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   130
		46631
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   131
		0
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   132
		0
1832
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1824
diff changeset
   133
		""
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1824
diff changeset
   134
		""
1fb61a53a2c2 Add options for database access
unc0rr
parents: 1824
diff changeset
   135
		""
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   136
	)
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   137
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   138
data CoreMessage =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   139
	Accept ClientInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   140
	| ClientMessage (Int, [String])
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   141
	-- | CoreMessage String
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   142
	-- | TimerTick
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   143
1833
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
   144
data DBQuery =
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
   145
	HasRegistered String
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
   146
	| CheckPassword String
e901ec5644b4 Add options for configuring database access
unc0rr
parents: 1832
diff changeset
   147
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   148
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   149
type Clients = IntMap.IntMap ClientInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   150
type Rooms = IntMap.IntMap RoomInfo
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   151
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   152
--type ClientsTransform = [ClientInfo] -> [ClientInfo]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   153
--type RoomsTransform = [RoomInfo] -> [RoomInfo]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   154
--type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [ClientInfo]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   155
--type Answer = ServerInfo -> (HandlesSelector, [String])
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   156
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
   157
type ClientsSelector = Clients -> Rooms -> [Int]