Allow server admins to join passworded/restricted rooms when it is really needed
authorunc0rr
Mon, 28 Dec 2015 23:37:44 +0300
changeset 11467 f2c36df8c7b1
parent 11466 4b5c7a5c49fd
child 11468 2f6f8baa2a97
Allow server admins to join passworded/restricted rooms when it is really needed
gameServer/CoreTypes.hs
gameServer/HWProtoCore.hs
gameServer/HWProtoLobbyState.hs
gameServer/NetRoutines.hs
--- a/gameServer/CoreTypes.hs	Mon Dec 28 21:51:12 2015 +0300
+++ b/gameServer/CoreTypes.hs	Mon Dec 28 23:37:44 2015 +0300
@@ -142,6 +142,7 @@
         isReady :: !Bool,
         isInGame :: !Bool,
         isAdministrator :: !Bool,
+        hasSuperPower :: !Bool,
         isChecker :: !Bool,
         isContributor :: !Bool,
         isKickedFromServer :: !Bool,
--- a/gameServer/HWProtoCore.hs	Mon Dec 28 21:51:12 2015 +0300
+++ b/gameServer/HWProtoCore.hs	Mon Dec 28 23:37:44 2015 +0300
@@ -75,11 +75,10 @@
         h "QUIT" m | not $ B.null m = handleCmd ["QUIT", m]
                    | otherwise = handleCmd ["QUIT"]
         h "RND" p = handleCmd ("RND" : B.words p)
-        h "GLOBAL" p = do
-            cl <- thisClient
+        h "GLOBAL" p = serverAdminOnly $ do
             rnc <- liftM snd ask
             let chans = map (sendChan . client rnc) $ allClients rnc
-            return [AnswerClients chans ["CHAT", "[global notice]", p] | isAdministrator cl]
+            return [AnswerClients chans ["CHAT", "[global notice]", p]]
         h "WATCH" f = return [QueryReplay f]
         h "FIX" _ = handleCmd ["FIX"]
         h "UNFIX" _ = handleCmd ["UNFIX"]
@@ -92,14 +91,13 @@
         h "MAXTEAMS" n | not $ B.null n = handleCmd ["MAXTEAMS", n]
         h "INFO" n | not $ B.null n = handleCmd ["INFO", n]
         h "RESTART_SERVER" "YES" = handleCmd ["RESTART_SERVER"]
-        h "REGISTERED_ONLY" _ = do
+        h "REGISTERED_ONLY" _ = serverAdminOnly $ do
             cl <- thisClient
-            return $ if isAdministrator cl then 
+            return
                 [ModifyServerInfo(\s -> s{isRegisteredUsersOnly = not $ isRegisteredUsersOnly s})
                 , AnswerClients [sendChan cl] ["CHAT", "[server]", "'Registered only' state toggled"]
                 ]
-                else
-                []
+        h "SUPER_POWER" _ = serverAdminOnly $ return [ModifyClient (\c -> c{hasSuperPower = True})]
         h c p = return [Warning $ B.concat ["Unknown cmd: /", c, " ", p]]
 
         extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b)
--- a/gameServer/HWProtoLobbyState.hs	Mon Dec 28 21:51:12 2015 +0300
+++ b/gameServer/HWProtoLobbyState.hs	Mon Dec 28 23:37:44 2015 +0300
@@ -93,13 +93,13 @@
             [Warning $ loc "No such room"]
             else if (not sameProto) && (not $ isAdministrator cl) then
             [Warning $ loc "Room version incompatible to your hedgewars version"]
-            else if isRestrictedJoins jRoom then
+            else if isRestrictedJoins jRoom && not (hasSuperPower cl) then
             [Warning $ loc "Joining restricted"]
             else if isRegisteredOnly jRoom && (B.null . webPassword $ cl) && not (isAdministrator cl) then
             [Warning $ loc "Registered users only"]
             else if isBanned then
             [Warning $ loc "You are banned in this room"]
-            else if roomPassword /= password jRoom then
+            else if roomPassword /= password jRoom  && not (hasSuperPower cl) then
             [NoticeMessage WrongPassword]
             else
             (
--- a/gameServer/NetRoutines.hs	Mon Dec 28 21:51:12 2015 +0300
+++ b/gameServer/NetRoutines.hs	Mon Dec 28 23:37:44 2015 +0300
@@ -73,6 +73,7 @@
                     False
                     False
                     False
+                    False
                     Nothing
                     Nothing
                     newEventsInfo