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