Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
authorunc0rr
Sun, 12 Jan 2014 15:15:59 +0400
changeset 9973 7589978c9912
parent 9971 071902835770
child 9975 9fcdaa2be27e
Stub for joins monitor which is a replacement to plain ban for 10 seconds system after join
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/ServerCore.hs
gameServer/ServerState.hs
--- a/gameServer/Actions.hs	Sun Jan 12 11:07:49 2014 +0400
+++ b/gameServer/Actions.hs	Sun Jan 12 15:15:59 2014 +0400
@@ -569,13 +569,18 @@
         return ci
 
     modify (\s -> s{clientIndex = Just newClId})
-    mapM_ processAction
-        [
-            AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion]
-            , CheckBanned True
-            , AddIP2Bans (host cl) "Reconnected too fast" (addUTCTime 10 $ connectTime cl)
-        ]
+
+    jm <- gets joinsMonitor
+    pass <- io $ joinsSentry jm (host cl) (connectTime cl)
 
+    if pass then
+        mapM_ processAction
+            [
+                CheckBanned True
+                , AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion]
+            ]
+        else
+        processAction $ ByeClient $ loc "Reconnected too fast"
 
 processAction (AddNick2Bans n reason expiring) = do
     processAction $ ModifyServerInfo (\s -> s{bans = BanByNick n reason expiring : bans s})
@@ -760,3 +765,11 @@
             , [AnswerClients [c] $ "EM" : roundMsgs']
             , [AnswerClients [c] ["KICKED"]]
             ]
+
+
+processAction Cleanup = do
+    jm <- gets joinsMonitor
+    
+    io $ do
+        t <- getCurrentTime
+        cleanup jm t
--- a/gameServer/CoreTypes.hs	Sun Jan 12 11:07:49 2014 +0400
+++ b/gameServer/CoreTypes.hs	Sun Jan 12 15:15:59 2014 +0400
@@ -16,7 +16,6 @@
 -----------------------
 import RoomsAndClients
 
-
 #if __GLASGOW_HASKELL__ < 706
 instance NFData B.ByteString
 #endif
@@ -78,6 +77,7 @@
     | Random [ClientChan] [B.ByteString]
     | QueryReplay B.ByteString
     | ShowReplay B.ByteString
+    | Cleanup
 
 type ClientChan = Chan [B.ByteString]
 
--- a/gameServer/ServerCore.hs	Sun Jan 12 11:07:49 2014 +0400
+++ b/gameServer/ServerCore.hs	Sun Jan 12 15:15:59 2014 +0400
@@ -62,7 +62,9 @@
 
         TimerAction tick ->
                 mapM_ processAction $
-                    PingAll : [StatsAction | even tick]
+                    PingAll 
+                    : [StatsAction | even tick] 
+                    ++ [Cleanup | tick `mod` 100 == 0]
 
 
 startServer :: ServerInfo -> IO ()
@@ -79,5 +81,6 @@
     startDBConnection si
 
     rnc <- newRoomsAndClients newRoom
+    jm <- newJoinMonitor
 
-    evalStateT mainLoop (ServerState Nothing si Set.empty rnc)
+    evalStateT mainLoop (ServerState Nothing si Set.empty rnc jm)
--- a/gameServer/ServerState.hs	Sun Jan 12 11:07:49 2014 +0400
+++ b/gameServer/ServerState.hs	Sun Jan 12 15:15:59 2014 +0400
@@ -1,6 +1,7 @@
 module ServerState
     (
     module RoomsAndClients,
+    module JoinsMonitor,
     clientRoomA,
     ServerState(..),
     client's,
@@ -17,12 +18,14 @@
 ----------------------
 import RoomsAndClients
 import CoreTypes
+import JoinsMonitor
 
 data ServerState = ServerState {
         clientIndex :: !(Maybe ClientIndex),
         serverInfo :: !ServerInfo,
         removedClients :: !(Set.Set ClientIndex),
-        roomsClients :: !MRnC
+        roomsClients :: !MRnC,
+        joinsMonitor :: !JoinsMonitor
     }