Files
space-station-14/Content.Server/Administration/Commands/RoleBanListCommand.cs
Pieter-Jan Briers 29b7fc4463 Stable to master (#42599)
Ban database refactor (#42495)

* Ban DB refactor seems to work at a basic level for PostgreSQL

* New ban creation API

Supports all the new functionality (multiple players/addresses/hwids/roles/rounds per ban).

* Make the migration irreversible

* Re-implement ban notifications

The server ID check is no longer done as admins may want to place bans spanning multiple rounds irrelevant of the source server.

* Fix some split query warnings

* Implement migration on SQLite

* More comments

* Remove required from ban reason

SS14.Admin changes would like this

* More missing AsSplitQuery() calls

* Fix missing ban type filter

* Fix old CreateServerBan API with permanent time

* Fix department and role ban commands with permanent time

* Re-add banhits navigation property

Dropped this on accident, SS14.Admin needs it.

* More ban API fixes.

* Don't fetch ban exemption info for role bans

Not relevant, reduces query performance

* Regenerate migrations

* Fix adminnotes command for players that never connected

Would blow up handling null player records. Not a new bug introduced by the refactor, but I ran into it.

* Great shame... I accidentally committed submodule update...

* Update GDPR scripts

* Fix sandbox violation

* Fix bans with duplicate info causing DB exceptions

Most notably happened with role bans, as multiple departments may include the same role.
2026-01-23 15:34:23 +01:00

83 lines
2.6 KiB
C#

using Content.Server.Administration.BanList;
using Content.Server.EUI;
using Content.Server.Database;
using Content.Shared.Administration;
using Content.Shared.Database;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands;
[AdminCommand(AdminFlags.Ban)]
public sealed class RoleBanListCommand : IConsoleCommand
{
[Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly EuiManager _eui = default!;
[Dependency] private readonly IPlayerLocator _locator = default!;
public string Command => "rolebanlist";
public string Description => Loc.GetString("cmd-rolebanlist-desc");
public string Help => Loc.GetString("cmd-rolebanlist-help");
public async void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1 && args.Length != 2)
{
shell.WriteLine($"Invalid amount of args. {Help}");
return;
}
var includeUnbanned = true;
if (args.Length == 2 && !bool.TryParse(args[1], out includeUnbanned))
{
shell.WriteLine($"Argument two ({args[1]}) is not a boolean.");
return;
}
var data = await _locator.LookupIdByNameOrIdAsync(args[0]);
if (data == null)
{
shell.WriteError("Unable to find a player with that name or id.");
return;
}
if (shell.Player is not { } player)
{
var bans = await _dbManager.GetBansAsync(data.LastAddress, data.UserId, data.LastLegacyHWId, data.LastModernHWIds, includeUnbanned, type: BanType.Role);
if (bans.Count == 0)
{
shell.WriteLine("That user has no bans in their record.");
return;
}
foreach (var ban in bans)
{
var msg = $"ID: {ban.Id}: Role(s): {string.Join(",", ban.Roles ?? [])} Reason: {ban.Reason}";
shell.WriteLine(msg);
}
return;
}
var ui = new BanListEui();
_eui.OpenEui(ui, player);
await ui.ChangeBanListPlayer(data.UserId);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
return args.Length switch
{
1 => CompletionResult.FromHintOptions(CompletionHelper.SessionNames(),
Loc.GetString("cmd-rolebanlist-hint-1")),
2 => CompletionResult.FromHintOptions(CompletionHelper.Booleans,
Loc.GetString("cmd-rolebanlist-hint-2")),
_ => CompletionResult.Empty
};
}
}