Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
authorunc0rr
Mon, 13 Aug 2012 23:17:09 +0400
changeset 7537 833a0c34fafc
parent 7535 87e5838103ff
child 7539 c6ffbc6530e3
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
QTfrontend/ui/widget/chatwidget.cpp
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
--- a/QTfrontend/ui/widget/chatwidget.cpp	Mon Aug 13 23:04:42 2012 +0400
+++ b/QTfrontend/ui/widget/chatwidget.cpp	Mon Aug 13 23:17:09 2012 +0400
@@ -922,7 +922,7 @@
     if(b)
     {
         chatNicks->insertAction(0, acKick);
-//      chatNicks->insertAction(0, acBan);
+        chatNicks->insertAction(0, acBan);
     }
 }
 
--- a/gameServer/Actions.hs	Mon Aug 13 23:04:42 2012 +0400
+++ b/gameServer/Actions.hs	Mon Aug 13 23:17:09 2012 +0400
@@ -469,9 +469,9 @@
 
 processAction BanList = do
     ch <- client's sendChan
-    bans <- gets (bans . serverInfo)
+    bans <- gets (B.pack . unlines . map show . bans . serverInfo)
     processAction $
-        AnswerClients [ch] ["BANLIST", B.pack $ show bans]
+        AnswerClients [ch] ["BANLIST", bans]
 
 
 
--- a/gameServer/CoreTypes.hs	Mon Aug 13 23:04:42 2012 +0400
+++ b/gameServer/CoreTypes.hs	Mon Aug 13 23:17:09 2012 +0400
@@ -94,6 +94,7 @@
         readyPlayers :: !Int,
         isRestrictedJoins :: Bool,
         isRestrictedTeams :: Bool,
+        roomBansList :: [B.ByteString],
         mapParams :: Map.Map B.ByteString B.ByteString,
         params :: Map.Map B.ByteString [B.ByteString]
     }
@@ -111,6 +112,7 @@
         0
         False
         False
+        []
         (
             Map.fromList $ Prelude.zipWith (,)
                 ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
--- a/gameServer/HWProtoInRoomState.hs	Mon Aug 13 23:04:42 2012 +0400
+++ b/gameServer/HWProtoInRoomState.hs	Mon Aug 13 23:17:09 2012 +0400
@@ -278,6 +278,14 @@
     where
         engineMsg cl = toEngineMsg $ B.concat ["b", nick cl, "(team): ", msg, "\x20\x20"]
 
+handleCmd_inRoom ["BAN", banNick] = do
+    (_, rnc) <- ask
+    maybeClientId <- clientByNick banNick
+    let banId = fromJust maybeClientId
+    master <- liftM isMaster thisClient
+    return [ModifyRoom (\r -> r{roomBansList = (host $ rnc `client` banId) : roomBansList r}) | master && isJust maybeClientId]
+
+
 handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17)
 
 handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"]
--- a/gameServer/HWProtoLobbyState.hs	Mon Aug 13 23:04:42 2012 +0400
+++ b/gameServer/HWProtoLobbyState.hs	Mon Aug 13 23:17:09 2012 +0400
@@ -70,11 +70,14 @@
     let jRoomClients = map (client irnc) $ roomClients irnc jRI
     let nicks = map nick jRoomClients
     let chans = map sendChan (cl : jRoomClients)
+    let isBanned = host cl `elem` roomBansList jRoom
     return $
         if isNothing maybeRI || not sameProto then
             [Warning "No such room"]
             else if isRestrictedJoins jRoom then
             [Warning "Joining restricted"]
+            else if isBanned then
+            [Warning "You are banned in this room"]
             else if roomPassword /= password jRoom then
             [NoticeMessage WrongPassword]
             else
@@ -183,7 +186,7 @@
 
 handleCmd_lobby ["RESTART_SERVER"] = do
     cl <- thisClient
-    return [RestartServer]
+    return [RestartServer | isAdministrator cl]
 
 
 handleCmd_lobby _ = return [ProtocolError "Incorrect command (state: in lobby)"]