Impement 60 seconds ban after kick from server. Not tested at all. 0.9.15
authorunc0rr
Thu, 20 Jan 2011 21:12:50 +0300
branch0.9.15
changeset 4762 59eb6319c950
parent 4759 4fa0c3da81f8
child 4765 adef9ec50d63
Impement 60 seconds ban after kick from server. Not tested at all.
gameServer/Actions.hs
gameServer/CoreTypes.hs
--- a/gameServer/Actions.hs	Mon Jan 17 14:53:14 2011 +0100
+++ b/gameServer/Actions.hs	Thu Jan 20 21:12:50 2011 +0300
@@ -391,8 +391,10 @@
         answerLobbyNicks = [AnswerThisClient ("LOBBY:JOINED": lobbyNicks) | not $ Prelude.null lobbyNicks]
 
 
-processAction (clID, serverInfo, clients, rooms) (KickClient kickID) =
-    liftM2 replaceID (return clID) (processAction (kickID, serverInfo, clients, rooms) $ ByeClient "Kicked")
+processAction (clID, serverInfo, clients, rooms) (KickClient kickID) = do
+    let client = clients ! clID
+    currentTime <- getCurrentTime
+    liftM2 replaceID (return clID) (processAction (kickID, serverInfo{lastLogins = (host client, (addUTCTime 60 $ currentTime, "60 seconds ban")) : lastLogins serverInfo}, clients, rooms) $ ByeClient "Kicked")
 
 
 processAction (clID, serverInfo, clients, rooms) (BanClient banNick) =
@@ -419,12 +421,13 @@
     infoM "Clients" (show (clientUID client) ++ ": New client. Time: " ++ show (connectTime client))
     writeChan (sendChan client) ["CONNECTED", "Hedgewars server http://www.hedgewars.org/"]
 
-    let newLogins = takeWhile (\(_ , time) -> (connectTime client) `diffUTCTime` time <= 11) $ lastLogins serverInfo
+    let newLogins = takeWhile (\(_ , (time, _)) -> (connectTime client) `diffUTCTime` time <= 0) $ lastLogins serverInfo
 
-    if isJust $ host client `Prelude.lookup` newLogins then
-        processAction (clID, serverInfo{lastLogins = newLogins}, updatedClients, rooms) $ ByeClient "Reconnected too fast"
+    let info = host client `Prelude.lookup` newLogins
+    if isJust info then
+        processAction (clID, serverInfo{lastLogins = newLogins}, updatedClients, rooms) $ ByeClient (snd .  fromJust $ info)
         else
-        return (clID, serverInfo{lastLogins = (host client, connectTime client) : newLogins}, updatedClients, rooms)
+        return (clID, serverInfo{lastLogins = (host client, (addUTCTime 10 $ connectTime client, "Reconnected too fast")) : newLogins}, updatedClients, rooms)
 
 
 processAction (clID, serverInfo, clients, rooms) PingAll = do
--- a/gameServer/CoreTypes.hs	Mon Jan 17 14:53:14 2011 +0100
+++ b/gameServer/CoreTypes.hs	Thu Jan 20 21:12:50 2011 +0300
@@ -136,14 +136,14 @@
         dbHost :: String,
         dbLogin :: String,
         dbPassword :: String,
-        lastLogins :: [(String, UTCTime)],
+        lastLogins :: [(String, (UTCTime, String))],
         stats :: TMVar StatisticsInfo,
         coreChan :: Chan CoreMessage,
         dbQueries :: Chan DBQuery
     }
 
 instance Show ServerInfo where
-    show si = "Server Info"
+    show _ = "Server Info"
 
 newServerInfo = (
     ServerInfo