More work on flood detector
authorunc0rr
Fri, 31 Jan 2014 16:51:20 +0400
changeset 10093 ada172d33988
parent 10092 a92a4ba39a79
child 10094 d3a2fe9f04f2
More work on flood detector
gameServer/CoreTypes.hs
gameServer/FloodDetection.hs
gameServer/NetRoutines.hs
--- a/gameServer/CoreTypes.hs	Fri Jan 31 12:45:51 2014 +0400
+++ b/gameServer/CoreTypes.hs	Fri Jan 31 16:51:20 2014 +0400
@@ -84,7 +84,12 @@
 data Event = LobbyChatMessage
            | EngineMessage
            | RoomJoin
+           
+type EventsInfo = [(Int, Maybe UTCTime)]
 
+newEventsInfo :: EventsInfo
+newEventsInfo = []   
+    
 type ClientChan = Chan [B.ByteString]
 
 data CheckInfo =
@@ -119,6 +124,9 @@
         isJoinedMidGame :: Bool,
         clientClan :: !(Maybe B.ByteString),
         checkInfo :: Maybe CheckInfo,
+        eiLobbyChat,
+        eiEM,
+        eiJoin :: EventsInfo,
         teamsInGame :: Word
     }
 
--- 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
+        ]
--- a/gameServer/NetRoutines.hs	Fri Jan 31 12:45:51 2014 +0400
+++ b/gameServer/NetRoutines.hs	Fri Jan 31 16:51:20 2014 +0400
@@ -56,6 +56,9 @@
                     False
                     Nothing
                     Nothing
+                    newEventsInfo
+                    newEventsInfo
+                    newEventsInfo
                     0
                     )