author | unc0rr |
Mon, 13 Apr 2009 09:36:25 +0000 | |
changeset 1979 | 912e450d4db2 |
parent 1953 | fd9c8e3c734d |
child 1986 | 15e612c68ea8 |
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 |
{ |
|
18 |
clientUID :: Int, |
|
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, |
1804 | 26 |
clientProto :: Word16, |
27 |
roomID :: Int, |
|
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
28 |
pingsQueue :: Word, |
1804 | 29 |
isMaster :: Bool, |
30 |
isReady :: Bool, |
|
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1841
diff
changeset
|
31 |
isAdministrator :: Bool, |
1804 | 32 |
forceQuit :: Bool, |
33 |
partRoom :: Bool |
|
34 |
} |
|
35 |
||
36 |
instance Show ClientInfo where |
|
37 |
show ci = show $ clientUID ci |
|
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 |
{ |
|
62 |
roomUID :: Int, |
|
63 |
name :: String, |
|
64 |
password :: String, |
|
65 |
roomProto :: Word16, |
|
66 |
teams :: [TeamInfo], |
|
67 |
gameinprogress :: Bool, |
|
68 |
playersIn :: !Int, |
|
69 |
readyPlayers :: Int, |
|
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 |
loginsNumber :: Int, |
|
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 |
|
133 |
show si = "Logins: " ++ (show $ loginsNumber si) |
|
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>" |
|
1953 | 139 |
"<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></li><li></li><li></li><li>...</li></ul></font>" |
1804 | 140 |
46631 |
141 |
0 |
|
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 |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
153 |
|
1804 | 154 |
data CoreMessage = |
155 |
Accept ClientInfo |
|
156 |
| ClientMessage (Int, [String]) |
|
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1833
diff
changeset
|
157 |
| ClientAccountInfo Int AccountInfo |
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
158 |
| TimerAction |
1804 | 159 |
|
1833 | 160 |
data DBQuery = |
1921 | 161 |
CheckAccount ClientInfo |
1833 | 162 |
|
1804 | 163 |
|
164 |
type Clients = IntMap.IntMap ClientInfo |
|
165 |
type Rooms = IntMap.IntMap RoomInfo |
|
166 |
||
167 |
--type ClientsTransform = [ClientInfo] -> [ClientInfo] |
|
168 |
--type RoomsTransform = [RoomInfo] -> [RoomInfo] |
|
169 |
--type HandlesSelector = ClientInfo -> [ClientInfo] -> [RoomInfo] -> [ClientInfo] |
|
170 |
--type Answer = ServerInfo -> (HandlesSelector, [String]) |
|
171 |
||
172 |
type ClientsSelector = Clients -> Rooms -> [Int] |