Implement ban by nickname
authorunc0rr
Fri, 30 Nov 2012 18:43:43 +0400
changeset 8154 0ea76ea45e6a
parent 8153 e97e00427204
child 8155 0bccee1d31da
Implement ban by nickname
gameServer/Actions.hs
gameServer/HWProtoLobbyState.hs
--- a/gameServer/Actions.hs	Fri Nov 30 15:26:49 2012 +0100
+++ b/gameServer/Actions.hs	Fri Nov 30 18:43:43 2012 +0400
@@ -52,6 +52,7 @@
     | KickRoomClient ClientIndex
     | BanClient NominalDiffTime B.ByteString ClientIndex
     | BanIP B.ByteString NominalDiffTime B.ByteString
+    | BanNick B.ByteString NominalDiffTime B.ByteString
     | BanList
     | Unban B.ByteString
     | ChangeMaster
@@ -500,6 +501,16 @@
     processAction $
         AddIP2Bans ip msg (addUTCTime seconds currentTime)
 
+processAction (BanNick n seconds reason) = do
+    currentTime <- io getCurrentTime
+    let msg = 
+            if seconds > 60 * 60 * 24 * 365 then
+                B.concat ["Permanent ban (", reason, ")"]
+                else
+                B.concat ["Ban for ", B.pack . show $ seconds, " (", reason, ")"]
+    processAction $
+        AddNick2Bans n msg (addUTCTime seconds currentTime)
+
 processAction BanList = do
     ch <- client's sendChan
     b <- gets (B.pack . unlines . map show . bans . serverInfo)
--- a/gameServer/HWProtoLobbyState.hs	Fri Nov 30 15:26:49 2012 +0100
+++ b/gameServer/HWProtoLobbyState.hs	Fri Nov 30 18:43:43 2012 +0400
@@ -160,6 +160,10 @@
     cl <- thisClient
     return [BanIP ip (readInt_ duration) reason | isAdministrator cl]
 
+handleCmd_lobby ["BANNICK", n, reason, duration] = do
+    cl <- thisClient
+    return [BanNick n (readInt_ duration) reason | isAdministrator cl]
+
 handleCmd_lobby ["BANLIST"] = do
     cl <- thisClient
     return [BanList | isAdministrator cl]