author | unc0rr |
Fri, 27 Mar 2009 20:29:38 +0000 | |
changeset 1927 | e2031906a347 |
parent 1926 | cb46fbdcaa41 |
child 1928 | 9bf8f4f30d6b |
permissions | -rw-r--r-- |
1804 | 1 |
module Actions where |
2 |
||
3 |
import Control.Concurrent.STM |
|
4 |
import Control.Concurrent.Chan |
|
5 |
import Data.IntMap |
|
6 |
import qualified Data.IntSet as IntSet |
|
1813 | 7 |
import qualified Data.Sequence as Seq |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
8 |
import System.Log.Logger |
1804 | 9 |
import Monad |
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
10 |
import Data.Time |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
11 |
import Maybe |
1804 | 12 |
----------------------------- |
13 |
import CoreTypes |
|
1813 | 14 |
import Utils |
1804 | 15 |
|
16 |
data Action = |
|
17 |
AnswerThisClient [String] |
|
18 |
| AnswerAll [String] |
|
19 |
| AnswerAllOthers [String] |
|
20 |
| AnswerThisRoom [String] |
|
21 |
| AnswerOthersInRoom [String] |
|
22 |
| AnswerLobby [String] |
|
1923 | 23 |
| SendServerMessage |
1804 | 24 |
| RoomAddThisClient Int -- roomID |
25 |
| RoomRemoveThisClient |
|
1813 | 26 |
| RemoveTeam String |
1804 | 27 |
| RemoveRoom |
1811 | 28 |
| UnreadyRoomClients |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
29 |
| MoveToLobby |
1804 | 30 |
| ProtocolError String |
31 |
| Warning String |
|
32 |
| ByeClient String |
|
1862 | 33 |
| KickClient Int -- clID |
1879 | 34 |
| KickRoomClient Int -- clID |
1921 | 35 |
| BanClient String -- nick |
1879 | 36 |
| RemoveClientTeams Int -- clID |
1804 | 37 |
| ModifyClient (ClientInfo -> ClientInfo) |
38 |
| ModifyRoom (RoomInfo -> RoomInfo) |
|
1925 | 39 |
| ModifyServerInfo (ServerInfo -> ServerInfo) |
1804 | 40 |
| AddRoom String String |
1834 | 41 |
| CheckRegistered |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
42 |
| ProcessAccountInfo AccountInfo |
1804 | 43 |
| Dump |
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
44 |
| AddClient ClientInfo |
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
45 |
| PingAll |
1804 | 46 |
|
47 |
type CmdHandler = Int -> Clients -> Rooms -> [String] -> [Action] |
|
48 |
||
1862 | 49 |
replaceID a (b, c, d, e) = (a, c, d, e) |
1804 | 50 |
|
51 |
processAction :: (Int, ServerInfo, Clients, Rooms) -> Action -> IO (Int, ServerInfo, Clients, Rooms) |
|
52 |
||
53 |
||
54 |
processAction (clID, serverInfo, clients, rooms) (AnswerThisClient msg) = do |
|
55 |
writeChan (sendChan $ clients ! clID) msg |
|
56 |
return (clID, serverInfo, clients, rooms) |
|
57 |
||
58 |
||
59 |
processAction (clID, serverInfo, clients, rooms) (AnswerAll msg) = do |
|
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
60 |
mapM_ (\cl -> writeChan (sendChan cl) msg) (elems clients) |
1804 | 61 |
return (clID, serverInfo, clients, rooms) |
62 |
||
63 |
||
64 |
processAction (clID, serverInfo, clients, rooms) (AnswerAllOthers msg) = do |
|
1879 | 65 |
mapM_ (\id -> writeChan (sendChan $ clients ! id) msg) $ |
66 |
Prelude.filter (\id' -> (id' /= clID) && (logonPassed $ clients ! id')) (keys clients) |
|
1804 | 67 |
return (clID, serverInfo, clients, rooms) |
68 |
||
69 |
||
70 |
processAction (clID, serverInfo, clients, rooms) (AnswerThisRoom msg) = do |
|
71 |
mapM_ (\id -> writeChan (sendChan $ clients ! id) msg) roomClients |
|
72 |
return (clID, serverInfo, clients, rooms) |
|
73 |
where |
|
74 |
roomClients = IntSet.elems $ playersIDs room |
|
75 |
room = rooms ! rID |
|
76 |
rID = roomID client |
|
77 |
client = clients ! clID |
|
78 |
||
79 |
||
80 |
processAction (clID, serverInfo, clients, rooms) (AnswerOthersInRoom msg) = do |
|
81 |
mapM_ (\id -> writeChan (sendChan $ clients ! id) msg) $ Prelude.filter (/= clID) roomClients |
|
82 |
return (clID, serverInfo, clients, rooms) |
|
83 |
where |
|
84 |
roomClients = IntSet.elems $ playersIDs room |
|
85 |
room = rooms ! rID |
|
86 |
rID = roomID client |
|
87 |
client = clients ! clID |
|
88 |
||
89 |
||
90 |
processAction (clID, serverInfo, clients, rooms) (AnswerLobby msg) = do |
|
91 |
mapM_ (\id -> writeChan (sendChan $ clients ! id) msg) roomClients |
|
92 |
return (clID, serverInfo, clients, rooms) |
|
93 |
where |
|
94 |
roomClients = IntSet.elems $ playersIDs room |
|
95 |
room = rooms ! 0 |
|
96 |
||
97 |
||
1923 | 98 |
processAction (clID, serverInfo, clients, rooms) SendServerMessage = do |
99 |
writeChan (sendChan $ clients ! clID) $ ["SERVER_MESSAGE", serverMessage serverInfo] |
|
100 |
return (clID, serverInfo, clients, rooms) |
|
101 |
||
102 |
||
1804 | 103 |
processAction (clID, serverInfo, clients, rooms) (ProtocolError msg) = do |
104 |
writeChan (sendChan $ clients ! clID) ["ERROR", msg] |
|
105 |
return (clID, serverInfo, clients, rooms) |
|
106 |
||
107 |
||
108 |
processAction (clID, serverInfo, clients, rooms) (Warning msg) = do |
|
109 |
writeChan (sendChan $ clients ! clID) ["WARNING", msg] |
|
110 |
return (clID, serverInfo, clients, rooms) |
|
111 |
||
112 |
||
113 |
processAction (clID, serverInfo, clients, rooms) (ByeClient msg) = do |
|
114 |
mapM_ (processAction (clID, serverInfo, clients, rooms)) $ answerOthersQuit ++ answerInformRoom |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
115 |
writeChan (sendChan $ clients ! clID) ["BYE", msg] |
1804 | 116 |
return ( |
117 |
0, |
|
118 |
serverInfo, |
|
119 |
delete clID clients, |
|
1823 | 120 |
adjust (\r -> r{ |
121 |
playersIDs = IntSet.delete clID (playersIDs r), |
|
122 |
playersIn = (playersIn r) - 1, |
|
123 |
readyPlayers = if isReady client then readyPlayers r - 1 else readyPlayers r |
|
124 |
}) rID rooms |
|
1804 | 125 |
) |
126 |
where |
|
127 |
client = clients ! clID |
|
128 |
rID = roomID client |
|
129 |
clientNick = nick client |
|
130 |
answerInformRoom = |
|
131 |
if roomID client /= 0 then |
|
132 |
if not $ Prelude.null msg then |
|
133 |
[AnswerThisRoom ["LEFT", clientNick, msg]] |
|
134 |
else |
|
135 |
[AnswerThisRoom ["LEFT", clientNick]] |
|
136 |
else |
|
137 |
[] |
|
138 |
answerOthersQuit = |
|
1846 | 139 |
if logonPassed client then |
1804 | 140 |
if not $ Prelude.null msg then |
141 |
[AnswerAll ["LOBBY:LEFT", clientNick, msg]] |
|
142 |
else |
|
143 |
[AnswerAll ["LOBBY:LEFT", clientNick]] |
|
144 |
else |
|
145 |
[] |
|
146 |
||
147 |
||
148 |
processAction (clID, serverInfo, clients, rooms) (ModifyClient func) = do |
|
149 |
return (clID, serverInfo, adjust func clID clients, rooms) |
|
150 |
||
151 |
||
152 |
processAction (clID, serverInfo, clients, rooms) (ModifyRoom func) = do |
|
153 |
return (clID, serverInfo, clients, adjust func rID rooms) |
|
154 |
where |
|
155 |
rID = roomID $ clients ! clID |
|
156 |
||
157 |
||
1925 | 158 |
processAction (clID, serverInfo, clients, rooms) (ModifyServerInfo func) = do |
159 |
return (clID, func serverInfo, clients, rooms) |
|
160 |
||
161 |
||
1804 | 162 |
processAction (clID, serverInfo, clients, rooms) (RoomAddThisClient rID) = do |
163 |
processAction ( |
|
164 |
clID, |
|
165 |
serverInfo, |
|
166 |
adjust (\cl -> cl{roomID = rID}) clID clients, |
|
167 |
adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r), playersIn = (playersIn r) + 1}) rID $ |
|
168 |
adjust (\r -> r{playersIDs = IntSet.delete clID (playersIDs r)}) 0 rooms |
|
169 |
) joinMsg |
|
170 |
where |
|
171 |
client = clients ! clID |
|
172 |
joinMsg = if rID == 0 then |
|
173 |
AnswerAllOthers ["LOBBY:JOINED", nick client] |
|
174 |
else |
|
175 |
AnswerThisRoom ["JOINED", nick client] |
|
176 |
||
177 |
||
178 |
processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient) = do |
|
179 |
when (rID /= 0) $ (processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["LEFT", nick client, "part"]) >> return () |
|
180 |
return ( |
|
181 |
clID, |
|
182 |
serverInfo, |
|
183 |
adjust (\cl -> cl{roomID = 0}) clID clients, |
|
1823 | 184 |
adjust (\r -> r{ |
185 |
playersIDs = IntSet.delete clID (playersIDs r), |
|
186 |
playersIn = (playersIn r) - 1, |
|
1827 | 187 |
readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r |
1823 | 188 |
}) rID $ |
1804 | 189 |
adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r)}) 0 rooms |
190 |
) |
|
191 |
where |
|
192 |
rID = roomID client |
|
193 |
client = clients ! clID |
|
194 |
||
195 |
||
196 |
processAction (clID, serverInfo, clients, rooms) (AddRoom roomName roomPassword) = do |
|
197 |
let newServerInfo = serverInfo {nextRoomID = newID} |
|
198 |
let room = newRoom{ |
|
199 |
roomUID = newID, |
|
200 |
name = roomName, |
|
201 |
password = roomPassword, |
|
202 |
roomProto = (clientProto client) |
|
203 |
} |
|
204 |
||
205 |
processAction (clID, serverInfo, clients, rooms) $ AnswerLobby ["ROOM", "ADD", roomName] |
|
206 |
||
207 |
processAction ( |
|
208 |
clID, |
|
209 |
newServerInfo, |
|
210 |
adjust (\cl -> cl{isMaster = True}) clID clients, |
|
211 |
insert newID room rooms |
|
212 |
) $ RoomAddThisClient newID |
|
213 |
where |
|
214 |
newID = (nextRoomID serverInfo) - 1 |
|
215 |
client = clients ! clID |
|
216 |
||
217 |
||
218 |
processAction (clID, serverInfo, clients, rooms) (RemoveRoom) = do |
|
1811 | 219 |
processAction (clID, serverInfo, clients, rooms) $ AnswerLobby ["ROOM", "DEL", name room] |
220 |
processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["ROOMABANDONED", name room] |
|
1804 | 221 |
return (clID, |
222 |
serverInfo, |
|
1827 | 223 |
Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False, isReady = False} else cl) clients, |
1811 | 224 |
delete rID $ adjust (\r -> r{playersIDs = IntSet.union (playersIDs room) (playersIDs r)}) 0 rooms |
1804 | 225 |
) |
226 |
where |
|
1811 | 227 |
room = rooms ! rID |
1804 | 228 |
rID = roomID client |
229 |
client = clients ! clID |
|
230 |
||
1813 | 231 |
|
1811 | 232 |
processAction (clID, serverInfo, clients, rooms) (UnreadyRoomClients) = do |
233 |
processAction (clID, serverInfo, clients, rooms) $ AnswerThisRoom ("NOT_READY" : roomPlayers) |
|
234 |
return (clID, |
|
235 |
serverInfo, |
|
236 |
Data.IntMap.map (\cl -> if roomID cl == rID then cl{isReady = False} else cl) clients, |
|
1827 | 237 |
adjust (\r -> r{readyPlayers = 0}) rID rooms) |
1811 | 238 |
where |
239 |
room = rooms ! rID |
|
240 |
rID = roomID client |
|
241 |
client = clients ! clID |
|
242 |
roomPlayers = Prelude.map (nick . (clients !)) roomPlayersIDs |
|
243 |
roomPlayersIDs = IntSet.elems $ playersIDs room |
|
244 |
||
245 |
||
1813 | 246 |
processAction (clID, serverInfo, clients, rooms) (RemoveTeam teamName) = do |
247 |
newRooms <- if not $ gameinprogress room then |
|
248 |
do |
|
249 |
processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["REMOVE_TEAM", teamName] |
|
250 |
return $ |
|
251 |
adjust (\r -> r{teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r}) rID rooms |
|
252 |
else |
|
253 |
do |
|
1866 | 254 |
processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["EM", rmTeamMsg] |
1813 | 255 |
return $ |
256 |
adjust (\r -> r{ |
|
257 |
teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r, |
|
258 |
leftTeams = teamName : leftTeams r, |
|
259 |
roundMsgs = roundMsgs r Seq.|> rmTeamMsg |
|
260 |
}) rID rooms |
|
261 |
return (clID, serverInfo, clients, newRooms) |
|
262 |
where |
|
263 |
room = rooms ! rID |
|
264 |
rID = roomID client |
|
265 |
client = clients ! clID |
|
266 |
rmTeamMsg = toEngineMsg $ 'F' : teamName |
|
267 |
||
268 |
||
1834 | 269 |
processAction (clID, serverInfo, clients, rooms) (CheckRegistered) = do |
1921 | 270 |
writeChan (dbQueries serverInfo) $ CheckAccount client |
1834 | 271 |
return (clID, serverInfo, clients, rooms) |
272 |
where |
|
273 |
client = clients ! clID |
|
274 |
||
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
275 |
|
1804 | 276 |
processAction (clID, serverInfo, clients, rooms) (Dump) = do |
277 |
writeChan (sendChan $ clients ! clID) ["DUMP", show serverInfo, showTree clients, showTree rooms] |
|
278 |
return (clID, serverInfo, clients, rooms) |
|
279 |
||
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
280 |
|
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
281 |
processAction (clID, serverInfo, clients, rooms) (ProcessAccountInfo info) = do |
1923 | 282 |
processAction (clID, serverInfo, clients, rooms) SendServerMessage |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
283 |
case info of |
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1846
diff
changeset
|
284 |
HasAccount passwd isAdmin -> do |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
285 |
infoM "Clients" $ show clID ++ " has account" |
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
286 |
writeChan (sendChan $ clients ! clID) ["ASKPASSWORD"] |
1847
2178c0fc838c
Set admin flag and send admin notification to users with rid equal to 3
unc0rr
parents:
1846
diff
changeset
|
287 |
return (clID, serverInfo, adjust (\cl -> cl{webPassword = passwd, isAdministrator = isAdmin}) clID clients, rooms) |
1839
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
288 |
Guest -> do |
5dd4cb7fd7e5
Server now send ASKPASSWORD command to frontend when user has web account
unc0rr
parents:
1834
diff
changeset
|
289 |
infoM "Clients" $ show clID ++ " is guest" |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
290 |
processAction (clID, serverInfo, adjust (\cl -> cl{logonPassed = True}) clID clients, rooms) MoveToLobby |
1921 | 291 |
Admin -> do |
292 |
infoM "Clients" $ show clID ++ " is admin" |
|
293 |
foldM processAction (clID, serverInfo, adjust (\cl -> cl{logonPassed = True, isAdministrator = True}) clID clients, rooms) [MoveToLobby, AnswerThisClient ["ADMIN_ACCESS"]] |
|
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
294 |
|
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
295 |
|
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
296 |
processAction (clID, serverInfo, clients, rooms) (MoveToLobby) = do |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
297 |
foldM processAction (clID, serverInfo, clients, rooms) $ |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
298 |
(RoomAddThisClient 0) |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
299 |
: answerLobbyNicks |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
300 |
-- ++ (answerServerMessage client clients) |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
301 |
where |
1846 | 302 |
lobbyNicks = Prelude.map nick $ Prelude.filter logonPassed $ elems clients |
1841
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
303 |
answerLobbyNicks = if not $ Prelude.null lobbyNicks then |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
304 |
[AnswerThisClient (["LOBBY:JOINED"] ++ lobbyNicks)] |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
305 |
else |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
306 |
[] |
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
307 |
|
fba7210b438b
Retrieve client password from web database and ask for it
unc0rr
parents:
1839
diff
changeset
|
308 |
|
1862 | 309 |
processAction (clID, serverInfo, clients, rooms) (KickClient kickID) = do |
1879 | 310 |
liftM2 replaceID (return clID) (processAction (kickID, serverInfo, clients, rooms) $ ByeClient "Kicked") |
311 |
||
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
312 |
|
1921 | 313 |
processAction (clID, serverInfo, clients, rooms) (BanClient banNick) = do |
314 |
return (clID, serverInfo, clients, rooms) |
|
315 |
||
1879 | 316 |
|
317 |
processAction (clID, serverInfo, clients, rooms) (KickRoomClient kickID) = do |
|
318 |
writeChan (sendChan $ clients ! kickID) ["KICKED"] |
|
319 |
liftM2 replaceID (return clID) (processAction (kickID, serverInfo, clients, rooms) $ RoomRemoveThisClient) |
|
320 |
||
321 |
||
322 |
processAction (clID, serverInfo, clients, rooms) (RemoveClientTeams teamsClID) = do |
|
323 |
liftM2 replaceID (return clID) $ |
|
324 |
foldM processAction (teamsClID, serverInfo, clients, rooms) $ removeTeamsActions |
|
325 |
where |
|
326 |
client = clients ! teamsClID |
|
327 |
room = rooms ! (roomID client) |
|
328 |
teamsToRemove = Prelude.filter (\t -> teamowner t == nick client) $ teams room |
|
329 |
removeTeamsActions = Prelude.map (RemoveTeam . teamname) teamsToRemove |
|
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
330 |
|
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
331 |
|
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
332 |
processAction (clID, serverInfo, clients, rooms) (AddClient client) = do |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
333 |
let updatedClients = insert (clientUID client) client clients |
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
334 |
infoM "Clients" ((show $ clientUID client) ++ ": New client. Time: " ++ (show $ connectTime client)) |
1926
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
335 |
writeChan (sendChan $ client) ["CONNECTED", "Hedgewars server http://www.hedgewars.org/"] |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
336 |
|
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
337 |
let newLogins = takeWhile (\(_ , time) -> (connectTime client) `diffUTCTime` time <= 20) $ lastLogins serverInfo |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
338 |
|
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
339 |
if isJust $ host client `Prelude.lookup` newLogins then |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
340 |
processAction (clID, serverInfo{lastLogins = newLogins}, updatedClients, rooms) $ ByeClient "Reconnected too fast" |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
341 |
else |
cb46fbdcaa41
Add simple DoS protection mechanism (although better than previous server had)
unc0rr
parents:
1925
diff
changeset
|
342 |
return (clID, serverInfo{lastLogins = (host client, connectTime client) : newLogins}, updatedClients, rooms) |
1927
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
343 |
|
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
344 |
|
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
345 |
processAction (clID, serverInfo, clients, rooms) PingAll = do |
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
346 |
processAction (clID, |
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
347 |
serverInfo, |
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
348 |
map (\cl -> cl{pingsQueue = pingsQueue cl + 1}) clients, |
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
349 |
rooms) $ AnswerAll ["PING"] |
e2031906a347
Ping clients every 30 seconds. Disconnection due to ping timeout to be implemented.
unc0rr
parents:
1926
diff
changeset
|
350 |