- Allow server admins to use DELEGATE even when not room owner
authorunc0rr
Sat, 19 Jan 2013 21:51:41 +0400
changeset 8403 fbc6e7602e05
parent 8402 659e043da6da
child 8409 2784b2610b5c
- Allow server admins to use DELEGATE even when not room owner - Show number of clients per version table on /stats command
gameServer/Actions.hs
gameServer/HWProtoCore.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
--- a/gameServer/Actions.hs	Sat Jan 19 00:55:51 2013 +0400
+++ b/gameServer/Actions.hs	Sat Jan 19 21:51:41 2013 +0400
@@ -1,9 +1,10 @@
-{-# LANGUAGE CPP, OverloadedStrings #-}
+{-# LANGUAGE CPP, OverloadedStrings, ScopedTypeVariables #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
 module Actions where
 
 import Control.Concurrent
 import qualified Data.Set as Set
+import qualified Data.Map as Map
 import qualified Data.List as L
 import qualified Control.Exception as Exception
 import System.Log.Logger
@@ -75,6 +76,7 @@
     | AddIP2Bans B.ByteString B.ByteString UTCTime
     | CheckBanned Bool
     | SaveReplay
+    | Stats
 
 
 type CmdHandler = [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
@@ -640,6 +642,15 @@
             return ()
         processAction $ ModifyServerInfo (\s -> s{shutdownPending = True})
 
+processAction Stats = do
+    cls <- allClientsS
+    let stats = versions cls
+    processAction $ Warning stats
+    where
+        versions = B.concat . ((:) "<table border=1>") . (flip (++) ["</table>"])
+            . concatMap (\(p, n :: Int) -> ["<tr><td>", protoNumber2ver p, "</td><td>", showB n, "</td></tr>"])
+            . Map.toList . Map.fromListWith (+) . map (\c -> (clientProto c, 1))
+
 #if defined(OFFICIAL_SERVER)
 processAction SaveReplay = do
     ri <- clientRoomA
--- a/gameServer/HWProtoCore.hs	Sat Jan 19 00:55:51 2013 +0400
+++ b/gameServer/HWProtoCore.hs	Sat Jan 19 21:51:41 2013 +0400
@@ -41,6 +41,7 @@
             return []
     where
         h ["DELEGATE", n] = handleCmd ["DELEGATE", n]
+        h ["STATS"] = handleCmd ["STATS"]
         h c = return [Warning . B.concat . L.intersperse " " $ "Unknown cmd" : c]
 
 handleCmd cmd = do
--- a/gameServer/HWProtoInRoomState.hs	Sat Jan 19 00:55:51 2013 +0400
+++ b/gameServer/HWProtoInRoomState.hs	Sat Jan 19 21:51:41 2013 +0400
@@ -304,10 +304,15 @@
     (thisClientId, rnc) <- ask
     maybeClientId <- clientByNick newAdmin
     master <- liftM isMaster thisClient
+    serverAdmin <- liftM isAdministrator thisClient
     let newAdminId = fromJust maybeClientId
     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc newAdminId
     return
-        [ChangeMaster (Just newAdminId) | master && isJust maybeClientId && (newAdminId /= thisClientId) && sameRoom]
+        [ChangeMaster (Just newAdminId) |
+            (master || serverAdmin)
+                && isJust maybeClientId
+                && ((newAdminId /= thisClientId) || (serverAdmin && not master))
+                && sameRoom]
 
 
 handleCmd_inRoom ["TEAMCHAT", msg] = do
--- a/gameServer/HWProtoLobbyState.hs	Sat Jan 19 00:55:51 2013 +0400
+++ b/gameServer/HWProtoLobbyState.hs	Sat Jan 19 21:51:41 2013 +0400
@@ -203,5 +203,8 @@
     cl <- thisClient
     return [RestartServer | isAdministrator cl]
 
+handleCmd_lobby ["STATS"] = do
+    cl <- thisClient
+    return [Stats | isAdministrator cl]
 
 handleCmd_lobby _ = return [ProtocolError "Incorrect command (state: in lobby)"]