]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make banpanel defaults use cvars (#27168)
authornikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Sat, 20 Apr 2024 16:18:26 +0000 (16:18 +0000)
committerGitHub <noreply@github.com>
Sat, 20 Apr 2024 16:18:26 +0000 (18:18 +0200)
* Make banpanel respect CCVars. Add CCVars for default ip/hwid/use last
details checkboxes.

* Move severity handling for server/role ban to another function

* Save sawmill

* Line goofyness

---------

Co-authored-by: Vasilis <vasilis@pikachu.systems>
Content.Client/Administration/UI/BanPanel/BanPanel.xaml.cs
Content.Shared/CCVar/CCVars.cs

index 1f32640f7ddffae85634eafca0e4445aeb22a1e9..dc263d6055cef0f3aec5de1a654724273b51aa7f 100644 (file)
@@ -3,6 +3,7 @@ using System.Net;
 using System.Net.Sockets;
 using Content.Client.Administration.UI.CustomControls;
 using Content.Shared.Administration;
+using Content.Shared.CCVar;
 using Content.Shared.Database;
 using Content.Shared.Roles;
 using Robust.Client.AutoGenerated;
@@ -11,6 +12,7 @@ using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Configuration;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Timing;
 using Robust.Shared.Utility;
@@ -32,8 +34,11 @@ public sealed partial class BanPanel : DefaultWindow
     // This is less efficient than just holding a reference to the root control and enumerating children, but you
     // have to know how the controls are nested, which makes the code more complicated.
     private readonly List<CheckBox> _roleCheckboxes = new();
+    private readonly ISawmill _banpanelSawmill;
 
     [Dependency] private readonly IGameTiming _gameTiming = default!;
+    [Dependency] private readonly IConfigurationManager _cfg = default!;
+    [Dependency] private readonly ILogManager _logManager = default!;
 
     private enum TabNumbers
     {
@@ -65,6 +70,7 @@ public sealed partial class BanPanel : DefaultWindow
     {
         RobustXamlLoader.Load(this);
         IoCManager.InjectDependencies(this);
+        _banpanelSawmill = _logManager.GetSawmill("admin.banpanel");
         PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
         PlayerNameLine.OnFocusExit += _ => OnPlayerNameChanged();
         PlayerCheckbox.OnPressed += _ =>
@@ -104,6 +110,11 @@ public sealed partial class BanPanel : DefaultWindow
         };
         SubmitButton.OnPressed += SubmitButtonOnOnPressed;
 
+        IpCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanIpBanDefault);
+        HwidCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanHwidBanDefault);
+        LastConnCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanUseLastDetails);
+        EraseCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanErasePlayer);
+
         SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-none"), (int) NoteSeverity.None);
         SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-low"), (int) NoteSeverity.Minor);
         SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-medium"), (int) NoteSeverity.Medium);
@@ -175,6 +186,39 @@ public sealed partial class BanPanel : DefaultWindow
                     c.Pressed = args.Pressed;
                 }
             }
+
+            if (args.Pressed)
+            {
+                if (!Enum.TryParse(_cfg.GetCVar(CCVars.DepartmentBanDefaultSeverity), true, out NoteSeverity newSeverity))
+                {
+                    _banpanelSawmill
+                        .Warning("Departmental role ban severity could not be parsed from config!");
+                    return;
+                }
+                SeverityOption.SelectId((int) newSeverity);
+            }
+            else
+            {
+                foreach (var childContainer in RolesContainer.Children)
+                {
+                    if (childContainer is Container)
+                    {
+                        foreach (var child in childContainer.Children)
+                        {
+                            if (child is CheckBox { Pressed: true })
+                                return;
+                        }
+                    }
+                }
+
+                if (!Enum.TryParse(_cfg.GetCVar(CCVars.RoleBanDefaultSeverity), true, out NoteSeverity newSeverity))
+                {
+                    _banpanelSawmill
+                        .Warning("Role ban severity could not be parsed from config!");
+                    return;
+                }
+                SeverityOption.SelectId((int) newSeverity);
+            }
         };
         outerContainer.AddChild(innerContainer);
         foreach (var role in roleList)
@@ -353,6 +397,35 @@ public sealed partial class BanPanel : DefaultWindow
     {
         TypeOption.ModulateSelfOverride = null;
         Tabs.SetTabVisible((int) TabNumbers.Roles, TypeOption.SelectedId == (int) Types.Role);
+            NoteSeverity? newSeverity = null;
+            switch (TypeOption.SelectedId)
+            {
+                case (int)Types.Server:
+                if (Enum.TryParse(_cfg.GetCVar(CCVars.ServerBanDefaultSeverity), true, out NoteSeverity serverSeverity))
+                    newSeverity = serverSeverity;
+                else
+                {
+                    _banpanelSawmill
+                        .Warning("Server ban severity could not be parsed from config!");
+                }
+
+                break;
+                case (int) Types.Role:
+
+                    if (Enum.TryParse(_cfg.GetCVar(CCVars.RoleBanDefaultSeverity), true, out NoteSeverity roleSeverity))
+                    {
+                        newSeverity = roleSeverity;
+                    }
+                    else
+                    {
+                        _banpanelSawmill
+                            .Warning("Role ban severity could not be parsed from config!");
+                    }
+                    break;
+            }
+
+            if (newSeverity != null)
+                SeverityOption.SelectId((int) newSeverity.Value);
     }
 
     private void UpdateSubmitEnabled()
index 70a702a0c503797ea17d98469d9360f3ffbc1a56..4a7b4408466bda9a87044a38a7d58727141c05eb 100644 (file)
@@ -796,19 +796,43 @@ namespace Content.Shared.CCVar
         /// Default severity for role bans
         /// </summary>
         public static readonly CVarDef<string> RoleBanDefaultSeverity =
-            CVarDef.Create("admin.role_ban_default_severity", "medium", CVar.ARCHIVE | CVar.SERVER);
+            CVarDef.Create("admin.role_ban_default_severity", "medium", CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
 
         /// <summary>
         /// Default severity for department bans
         /// </summary>
         public static readonly CVarDef<string> DepartmentBanDefaultSeverity =
-            CVarDef.Create("admin.department_ban_default_severity", "medium", CVar.ARCHIVE | CVar.SERVER);
+            CVarDef.Create("admin.department_ban_default_severity", "medium", CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
 
         /// <summary>
         /// Default severity for server bans
         /// </summary>
         public static readonly CVarDef<string> ServerBanDefaultSeverity =
-            CVarDef.Create("admin.server_ban_default_severity", "High", CVar.ARCHIVE | CVar.SERVER);
+            CVarDef.Create("admin.server_ban_default_severity", "High", CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
+
+        /// <summary>
+        /// Whether a server ban will ban the player's ip by default.
+        /// </summary>
+        public static readonly CVarDef<bool> ServerBanIpBanDefault =
+            CVarDef.Create("admin.server_ban_ip_ban_default", true, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
+
+        /// <summary>
+        /// Whether a server ban will ban the player's hardware id by default.
+        /// </summary>
+        public static readonly CVarDef<bool> ServerBanHwidBanDefault =
+            CVarDef.Create("admin.server_ban_hwid_ban_default", true, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
+
+        /// <summary>
+        /// Whether to use details from last connection for ip/hwid in the BanPanel.
+        /// </summary>
+        public static readonly CVarDef<bool> ServerBanUseLastDetails =
+            CVarDef.Create("admin.server_ban_use_last_details", true, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
+
+        /// <summary>
+        /// Whether to erase a player's chat messages and their entity from the game when banned.
+        /// </summary>
+        public static readonly CVarDef<bool> ServerBanErasePlayer =
+            CVarDef.Create("admin.server_ban_erase_player", false, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED);
 
         /// <summary>
         ///     Minimum explosion intensity to create an admin alert message. -1 to disable the alert.