author | nemo |
Sun, 26 Jul 2009 19:43:38 +0000 | |
changeset 2276 | d4d9e490d534 |
parent 2245 | c011aecc95e5 |
child 2352 | 7eaf82cf0890 |
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, |
|
2245
c011aecc95e5
unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents:
2173
diff
changeset
|
31 |
isAdministrator :: Bool, |
c011aecc95e5
unc0rr's patch from issue #144 - prevent spectators from ruining the game
nemo
parents:
2173
diff
changeset
|
32 |
teamsInGame :: Word |
1804 | 33 |
} |
34 |
||
35 |
instance Show ClientInfo where |
|
2004 | 36 |
show ci = (show $ clientUID ci) |
37 |
++ " nick: " ++ (nick ci) |
|
38 |
++ " host: " ++ (host ci) |
|
1804 | 39 |
|
40 |
instance Eq ClientInfo where |
|
41 |
a1 == a2 = clientHandle a1 == clientHandle a2 |
|
42 |
||
43 |
data HedgehogInfo = |
|
44 |
HedgehogInfo String String |
|
45 |
||
46 |
data TeamInfo = |
|
47 |
TeamInfo |
|
48 |
{ |
|
49 |
teamowner :: String, |
|
50 |
teamname :: String, |
|
51 |
teamcolor :: String, |
|
52 |
teamgrave :: String, |
|
53 |
teamfort :: String, |
|
54 |
teamvoicepack :: String, |
|
55 |
difficulty :: Int, |
|
56 |
hhnum :: Int, |
|
57 |
hedgehogs :: [HedgehogInfo] |
|
58 |
} |
|
59 |
||
60 |
data RoomInfo = |
|
61 |
RoomInfo |
|
62 |
{ |
|
2004 | 63 |
roomUID :: !Int, |
1804 | 64 |
name :: String, |
65 |
password :: String, |
|
66 |
roomProto :: Word16, |
|
67 |
teams :: [TeamInfo], |
|
68 |
gameinprogress :: Bool, |
|
69 |
playersIn :: !Int, |
|
2004 | 70 |
readyPlayers :: !Int, |
1804 | 71 |
playersIDs :: IntSet.IntSet, |
72 |
isRestrictedJoins :: Bool, |
|
73 |
isRestrictedTeams :: Bool, |
|
74 |
roundMsgs :: Seq String, |
|
75 |
leftTeams :: [String], |
|
76 |
teamsAtStart :: [TeamInfo], |
|
77 |
params :: Map.Map String [String] |
|
78 |
} |
|
79 |
||
80 |
instance Show RoomInfo where |
|
81 |
show ri = (show $ roomUID ri) |
|
82 |
++ ", players ids: " ++ (show $ IntSet.size $ playersIDs ri) |
|
83 |
++ ", players: " ++ (show $ playersIn ri) |
|
1824 | 84 |
++ ", ready: " ++ (show $ readyPlayers ri) |
1804 | 85 |
|
86 |
instance Eq RoomInfo where |
|
87 |
a1 == a2 = roomUID a1 == roomUID a2 |
|
88 |
||
89 |
newRoom = ( |
|
90 |
RoomInfo |
|
91 |
0 |
|
92 |
"" |
|
93 |
"" |
|
94 |
0 |
|
95 |
[] |
|
96 |
False |
|
97 |
0 |
|
98 |
0 |
|
99 |
IntSet.empty |
|
100 |
False |
|
101 |
False |
|
102 |
Data.Sequence.empty |
|
103 |
[] |
|
104 |
[] |
|
105 |
(Map.singleton "MAP" ["+rnd+"]) |
|
106 |
) |
|
107 |
||
108 |
data StatisticsInfo = |
|
109 |
StatisticsInfo |
|
110 |
{ |
|
111 |
playersNumber :: Int, |
|
112 |
roomsNumber :: Int |
|
113 |
} |
|
114 |
||
115 |
data ServerInfo = |
|
116 |
ServerInfo |
|
117 |
{ |
|
118 |
isDedicated :: Bool, |
|
119 |
serverMessage :: String, |
|
1953 | 120 |
serverMessageForOldVersions :: String, |
1804 | 121 |
listenPort :: PortNumber, |
122 |
nextRoomID :: Int, |
|
1832 | 123 |
dbHost :: String, |
124 |
dbLogin :: String, |
|
125 |
dbPassword :: String, |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
126 |
lastLogins :: [(String, UTCTime)], |
1833 | 127 |
stats :: TMVar StatisticsInfo, |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
128 |
coreChan :: Chan CoreMessage, |
1833 | 129 |
dbQueries :: Chan DBQuery |
1804 | 130 |
} |
131 |
||
132 |
instance Show ServerInfo where |
|
2004 | 133 |
show si = "Server Info" |
1804 | 134 |
|
135 |
newServerInfo = ( |
|
136 |
ServerInfo |
|
137 |
True |
|
138 |
"<h2><p align=center><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p></h2>" |
|
2104 | 139 |
"<font color=yellow><h3>Hedgewars 0.9.11 is out! Please, update.</h3><p align=center><a href=http://hedgewars.org/download.html>Download page here</a></p><h4>New features are:</h4><ul><li>Speech bubbles</li><li>New game modes</li><li>Sniper rifle</li><li>...</li></ul></font>" |
1804 | 140 |
46631 |
141 |
0 |
|
1832 | 142 |
"" |
143 |
"" |
|
144 |
"" |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1921
diff
changeset
|
145 |
[] |
1804 | 146 |
) |
147 |
||
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
148 |
data AccountInfo = |
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
149 |
HasAccount String Bool |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
150 |
| Guest |
1921 | 151 |
| Admin |
2116
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
152 |
deriving (Show, Read) |
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
153 |
|
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
154 |
data DBQuery = |
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
155 |
CheckAccount Int String String |
2155
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
2116
diff
changeset
|
156 |
| ClearCache |
2172 | 157 |
| SendStats Int Int |
2116
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
158 |
deriving (Show, Read) |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
159 |
|
1804 | 160 |
data CoreMessage = |
161 |
Accept ClientInfo |
|
162 |
| ClientMessage (Int, [String]) |
|
2116
dec7ead2d178
Bring back authentication to official server, now using separate process to perform database interaction
unc0rr
parents:
2104
diff
changeset
|
163 |
| ClientAccountInfo (Int, AccountInfo) |
2173 | 164 |
| TimerAction Int |
1804 | 165 |
|
166 |
type Clients = IntMap.IntMap ClientInfo |
|
167 |
type Rooms = IntMap.IntMap RoomInfo |
|
168 |
||
169 |
--type ClientsTransform = [ClientInfo] -> [ClientInfo] |
|
170 |
--type RoomsTransform = [RoomInfo] -> [RoomInfo] |
|
171 |
--type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [ClientInfo] |
|
172 |
--type Answer = ServerInfo -> (HandlesSelector, [String]) |
|
173 |
||
174 |
type ClientsSelector = Clients -> Rooms -> [Int] |