gameServer/FloodDetection.hs
changeset 10093 ada172d33988
parent 10090 a471a7bbc339
child 10094 d3a2fe9f04f2
--- a/gameServer/FloodDetection.hs	Fri Jan 31 12:45:51 2014 +0400
+++ b/gameServer/FloodDetection.hs	Fri Jan 31 16:51:20 2014 +0400
@@ -1,6 +1,32 @@
 module FloodDetection where
 
+import Control.Monad.State.Strict
+import Data.Time
+import Control.Arrow
+----------------
+import ServerState
 import CoreTypes
 
-registerEvent :: Event -> a
-registerEvent e = undefined
+registerEvent :: Event -> StateT ServerState IO [Action]
+registerEvent e = do
+    eventInfo <- client's $ einfo e
+    if (not $ null eventInfo) && 0 == (fst $ head eventInfo) then doCheck eventInfo else updateInfo
+    where
+    einfo LobbyChatMessage = eiLobbyChat
+    einfo EngineMessage = eiEM
+    einfo RoomJoin = eiJoin
+     
+    transformField LobbyChatMessage f = \c -> c{eiLobbyChat = f $ eiLobbyChat c}
+    transformField EngineMessage f = \c -> c{eiLobbyChat = f $ eiEM c}
+    transformField RoomJoin f = \c -> c{eiLobbyChat = f $ eiJoin c}
+    
+    doCheck ei = do
+        liftM Just $ io getCurrentTime
+        return []
+    updateInfo = return [
+        ModifyClient $ transformField e 
+            $ \ei -> if null ei then 
+                [] 
+                else 
+                let (h:hs) = ei in first (flip (-) 1) h : hs
+        ]