--- 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
)