diff --git a/Content.Client/Administration/UI/BanPanel/BanPanel.xaml.cs b/Content.Client/Administration/UI/BanPanel/BanPanel.xaml.cs index 1f32640f7d..dc263d6055 100644 --- a/Content.Client/Administration/UI/BanPanel/BanPanel.xaml.cs +++ b/Content.Client/Administration/UI/BanPanel/BanPanel.xaml.cs @@ -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 _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() diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 70a702a0c5..4a7b440846 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -796,19 +796,43 @@ namespace Content.Shared.CCVar /// Default severity for role bans /// public static readonly CVarDef 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); /// /// Default severity for department bans /// public static readonly CVarDef 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); /// /// Default severity for server bans /// public static readonly CVarDef 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); + + /// + /// Whether a server ban will ban the player's ip by default. + /// + public static readonly CVarDef ServerBanIpBanDefault = + CVarDef.Create("admin.server_ban_ip_ban_default", true, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED); + + /// + /// Whether a server ban will ban the player's hardware id by default. + /// + public static readonly CVarDef ServerBanHwidBanDefault = + CVarDef.Create("admin.server_ban_hwid_ban_default", true, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED); + + /// + /// Whether to use details from last connection for ip/hwid in the BanPanel. + /// + public static readonly CVarDef ServerBanUseLastDetails = + CVarDef.Create("admin.server_ban_use_last_details", true, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED); + + /// + /// Whether to erase a player's chat messages and their entity from the game when banned. + /// + public static readonly CVarDef ServerBanErasePlayer = + CVarDef.Create("admin.server_ban_erase_player", false, CVar.ARCHIVE | CVar.SERVER | CVar.REPLICATED); /// /// Minimum explosion intensity to create an admin alert message. -1 to disable the alert.