Make banpanel defaults use cvars (#27168)
* 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>
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Net;
|
|||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using Content.Client.Administration.UI.CustomControls;
|
using Content.Client.Administration.UI.CustomControls;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.Database;
|
using Content.Shared.Database;
|
||||||
using Content.Shared.Roles;
|
using Content.Shared.Roles;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
@@ -11,6 +12,7 @@ using Robust.Client.UserInterface;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
using Robust.Shared.Utility;
|
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
|
// 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.
|
// have to know how the controls are nested, which makes the code more complicated.
|
||||||
private readonly List<CheckBox> _roleCheckboxes = new();
|
private readonly List<CheckBox> _roleCheckboxes = new();
|
||||||
|
private readonly ISawmill _banpanelSawmill;
|
||||||
|
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||||
|
[Dependency] private readonly ILogManager _logManager = default!;
|
||||||
|
|
||||||
private enum TabNumbers
|
private enum TabNumbers
|
||||||
{
|
{
|
||||||
@@ -65,6 +70,7 @@ public sealed partial class BanPanel : DefaultWindow
|
|||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
_banpanelSawmill = _logManager.GetSawmill("admin.banpanel");
|
||||||
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
||||||
PlayerNameLine.OnFocusExit += _ => OnPlayerNameChanged();
|
PlayerNameLine.OnFocusExit += _ => OnPlayerNameChanged();
|
||||||
PlayerCheckbox.OnPressed += _ =>
|
PlayerCheckbox.OnPressed += _ =>
|
||||||
@@ -104,6 +110,11 @@ public sealed partial class BanPanel : DefaultWindow
|
|||||||
};
|
};
|
||||||
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
|
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-none"), (int) NoteSeverity.None);
|
||||||
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-low"), (int) NoteSeverity.Minor);
|
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-low"), (int) NoteSeverity.Minor);
|
||||||
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-medium"), (int) NoteSeverity.Medium);
|
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;
|
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);
|
outerContainer.AddChild(innerContainer);
|
||||||
foreach (var role in roleList)
|
foreach (var role in roleList)
|
||||||
@@ -353,6 +397,35 @@ public sealed partial class BanPanel : DefaultWindow
|
|||||||
{
|
{
|
||||||
TypeOption.ModulateSelfOverride = null;
|
TypeOption.ModulateSelfOverride = null;
|
||||||
Tabs.SetTabVisible((int) TabNumbers.Roles, TypeOption.SelectedId == (int) Types.Role);
|
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()
|
private void UpdateSubmitEnabled()
|
||||||
|
|||||||
@@ -796,19 +796,43 @@ namespace Content.Shared.CCVar
|
|||||||
/// Default severity for role bans
|
/// Default severity for role bans
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<string> RoleBanDefaultSeverity =
|
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>
|
/// <summary>
|
||||||
/// Default severity for department bans
|
/// Default severity for department bans
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<string> DepartmentBanDefaultSeverity =
|
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>
|
/// <summary>
|
||||||
/// Default severity for server bans
|
/// Default severity for server bans
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<string> ServerBanDefaultSeverity =
|
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>
|
/// <summary>
|
||||||
/// Minimum explosion intensity to create an admin alert message. -1 to disable the alert.
|
/// Minimum explosion intensity to create an admin alert message. -1 to disable the alert.
|
||||||
|
|||||||
Reference in New Issue
Block a user