equal
deleted
inserted
replaced
1 module FloodDetection where |
1 module FloodDetection where |
2 |
2 |
|
3 import Control.Monad.State.Strict |
|
4 import Data.Time |
|
5 import Control.Arrow |
|
6 ---------------- |
|
7 import ServerState |
3 import CoreTypes |
8 import CoreTypes |
4 |
9 |
5 registerEvent :: Event -> a |
10 registerEvent :: Event -> StateT ServerState IO [Action] |
6 registerEvent e = undefined |
11 registerEvent e = do |
|
12 eventInfo <- client's $ einfo e |
|
13 if (not $ null eventInfo) && 0 == (fst $ head eventInfo) then doCheck eventInfo else updateInfo |
|
14 where |
|
15 einfo LobbyChatMessage = eiLobbyChat |
|
16 einfo EngineMessage = eiEM |
|
17 einfo RoomJoin = eiJoin |
|
18 |
|
19 transformField LobbyChatMessage f = \c -> c{eiLobbyChat = f $ eiLobbyChat c} |
|
20 transformField EngineMessage f = \c -> c{eiLobbyChat = f $ eiEM c} |
|
21 transformField RoomJoin f = \c -> c{eiLobbyChat = f $ eiJoin c} |
|
22 |
|
23 doCheck ei = do |
|
24 liftM Just $ io getCurrentTime |
|
25 return [] |
|
26 updateInfo = return [ |
|
27 ModifyClient $ transformField e |
|
28 $ \ei -> if null ei then |
|
29 [] |
|
30 else |
|
31 let (h:hs) = ei in first (flip (-) 1) h : hs |
|
32 ] |