author | unc0rr |
Sun, 24 May 2009 12:53:46 +0000 | |
changeset 2103 | 451a87cc6500 |
parent 2004 | f7944d5adc5f |
child 2104 | b2c50a7480ea |
permissions | -rw-r--r-- |
1804 | 1 |
module CoreTypes where |
2 |
||
3 |
import System.IO |
|
4 |
import Control.Concurrent.Chan |
|
5 |
import Control.Concurrent.STM |
|
6 |
import Data.Word |
|
7 |
import qualified Data.Map as Map |
|
8 |
import qualified Data.IntMap as IntMap |
|
9 |
import qualified Data.IntSet as IntSet |
|
10 |
import Data.Sequence(Seq, empty) |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
11 |
import Data.Time |
1804 | 12 |
import Network |
13 |
||
1833 | 14 |
|
1804 | 15 |
data ClientInfo = |
16 |
ClientInfo |
|
17 |
{ |
|
2004 | 18 |
clientUID :: !Int, |
1804 | 19 |
sendChan :: Chan [String], |
20 |
clientHandle :: Handle, |
|
21 |
host :: String, |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
22 |
connectTime :: UTCTime, |
1804 | 23 |
nick :: String, |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
24 |
webPassword :: String, |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
25 |
logonPassed :: Bool, |
2004 | 26 |
clientProto :: !Word16, |
27 |
roomID :: !Int, |
|
28 |
pingsQueue :: !Word, |
|
1804 | 29 |
isMaster :: Bool, |
30 |
isReady :: Bool, |
|
2004 | 31 |
isAdministrator :: Bool |
1804 | 32 |
} |
33 |
||
34 |
instance Show ClientInfo where |
|
2004 | 35 |
show ci = (show $ clientUID ci) |
36 |
++ " nick: " ++ (nick ci) |
|
37 |
++ " host: " ++ (host ci) |
|
1804 | 38 |
|
39 |
instance Eq ClientInfo where |
|
40 |
a1 == a2 = clientHandle a1 == clientHandle a2 |
|
41 |
||
42 |
data HedgehogInfo = |
|
43 |
HedgehogInfo String String |
|
44 |
||
45 |
data TeamInfo = |
|
46 |
TeamInfo |
|
47 |
{ |
|
48 |
teamowner :: String, |
|
49 |
teamname :: String, |
|
50 |
teamcolor :: String, |
|
51 |
teamgrave :: String, |
|
52 |
teamfort :: String, |
|
53 |
teamvoicepack :: String, |
|
54 |
difficulty :: Int, |
|
55 |
hhnum :: Int, |
|
56 |
hedgehogs :: [HedgehogInfo] |
|
57 |
} |
|
58 |
||
59 |
data RoomInfo = |
|
60 |
RoomInfo |
|
61 |
{ |
|
2004 | 62 |
roomUID :: !Int, |
1804 | 63 |
name :: String, |
64 |
password :: String, |
|
65 |
roomProto :: Word16, |
|
66 |
teams :: [TeamInfo], |
|
67 |
gameinprogress :: Bool, |
|
68 |
playersIn :: !Int, |
|
2004 | 69 |
readyPlayers :: !Int, |
1804 | 70 |
playersIDs :: IntSet.IntSet, |
71 |
isRestrictedJoins :: Bool, |
|
72 |
isRestrictedTeams :: Bool, |
|
73 |
roundMsgs :: Seq String, |
|
74 |
leftTeams :: [String], |
|
75 |
teamsAtStart :: [TeamInfo], |
|
76 |
params :: Map.Map String [String] |
|
77 |
} |
|
78 |
||
79 |
instance Show RoomInfo where |
|
80 |
show ri = (show $ roomUID ri) |
|
81 |
++ ", players ids: " ++ (show $ IntSet.size $ playersIDs ri) |
|
82 |
++ ", players: " ++ (show $ playersIn ri) |
|
1824 | 83 |
++ ", ready: " ++ (show $ readyPlayers ri) |
1804 | 84 |
|
85 |
instance Eq RoomInfo where |
|
86 |
a1 == a2 = roomUID a1 == roomUID a2 |
|
87 |
||
88 |
newRoom = ( |
|
89 |
RoomInfo |
|
90 |
0 |
|
91 |
"" |
|
92 |
"" |
|
93 |
0 |
|
94 |
[] |
|
95 |
False |
|
96 |
0 |
|
97 |
0 |
|
98 |
IntSet.empty |
|
99 |
False |
|
100 |
False |
|
101 |
Data.Sequence.empty |
|
102 |
[] |
|
103 |
[] |
|
104 |
(Map.singleton "MAP" ["+rnd+"]) |
|
105 |
) |
|
106 |
||
107 |
data StatisticsInfo = |
|
108 |
StatisticsInfo |
|
109 |
{ |
|
110 |
playersNumber :: Int, |
|
111 |
roomsNumber :: Int |
|
112 |
} |
|
113 |
||
114 |
data ServerInfo = |
|
115 |
ServerInfo |
|
116 |
{ |
|
117 |
isDedicated :: Bool, |
|
118 |
serverMessage :: String, |
|
1953 | 119 |
serverMessageForOldVersions :: String, |
1804 | 120 |
listenPort :: PortNumber, |
121 |
nextRoomID :: Int, |
|
1832 | 122 |
dbHost :: String, |
123 |
dbLogin :: String, |
|
124 |
dbPassword :: String, |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
125 |
lastLogins :: [(String, UTCTime)], |
1833 | 126 |
stats :: TMVar StatisticsInfo, |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
127 |
coreChan :: Chan CoreMessage, |
1833 | 128 |
dbQueries :: Chan DBQuery |
1804 | 129 |
} |
130 |
||
131 |
instance Show ServerInfo where |
|
2004 | 132 |
show si = "Server Info" |
1804 | 133 |
|
134 |
newServerInfo = ( |
|
135 |
ServerInfo |
|
136 |
True |
|
137 |
"<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>" |
|
1986 | 138 |
"<font color=yellow><h3>Hedgewars 0.9.10 is out! Please, update. Support for previous versions IS DROPPED</h3><p align=center><a href=http://hedgewars.org/download.html>Download page here</a></p><h4>New features are:</h4><ul><li>Large maps</li><li>New game options</li><li>Utilities</li><li>...</li></ul></font>" |
1804 | 139 |
46631 |
140 |
0 |
|
1832 | 141 |
"" |
142 |
"" |
|
143 |
"" |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
144 |
[] |
1804 | 145 |
) |
146 |
||
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
147 |
data AccountInfo = |
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
148 |
HasAccount String Bool |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
149 |
| Guest |
1921 | 150 |
| Admin |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
151 |
|
1804 | 152 |
data CoreMessage = |
153 |
Accept ClientInfo |
|
154 |
| ClientMessage (Int, [String]) |
|
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
155 |
| ClientAccountInfo Int AccountInfo |
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
156 |
| TimerAction |
1804 | 157 |
|
1833 | 158 |
data DBQuery = |
1921 | 159 |
CheckAccount ClientInfo |
1833 | 160 |
|
1804 | 161 |
|
162 |
type Clients = IntMap.IntMap ClientInfo |
|
163 |
type Rooms = IntMap.IntMap RoomInfo |
|
164 |
||
165 |
--type ClientsTransform = [ClientInfo] -> [ClientInfo] |
|
166 |
--type RoomsTransform = [RoomInfo] -> [RoomInfo] |
|
167 |
--type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [ClientInfo] |
|
168 |
--type Answer = ServerInfo -> (HandlesSelector, [String]) |
|
169 |
||
170 |
type ClientsSelector = Clients -> Rooms -> [Int] |