# HG changeset patch # User unc0rr # Date 1295547170 -10800 # Node ID 59eb6319c9500c0f364457199303730363d19cb7 # Parent 4fa0c3da81f857924e2de6ff6edc6fc2860f9340 Impement 60 seconds ban after kick from server. Not tested at all. diff -r 4fa0c3da81f8 -r 59eb6319c950 gameServer/Actions.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 diff -r 4fa0c3da81f8 -r 59eb6319c950 gameServer/CoreTypes.hs --- 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