diff --git a/Content.Server/Administration/Commands/BanCommand.cs b/Content.Server/Administration/Commands/BanCommand.cs index baff7d1b68..65daf43d36 100644 --- a/Content.Server/Administration/Commands/BanCommand.cs +++ b/Content.Server/Administration/Commands/BanCommand.cs @@ -14,8 +14,8 @@ namespace Content.Server.Administration.Commands public sealed class BanCommand : IConsoleCommand { public string Command => "ban"; - public string Description => "Bans somebody"; - public string Help => $"Usage: {Command} [duration in minutes, leave out or 0 for permanent ban]"; + public string Description => Loc.GetString("cmd-ban-desc"); + public string Help => Loc.GetString("cmd-ban-help", ("Command", Command)); public async void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -54,7 +54,7 @@ namespace Content.Server.Administration.Commands var located = await locator.LookupIdByNameOrIdAsync(target); if (located == null) { - shell.WriteError("Unable to find a player with that name."); + shell.WriteError(Loc.GetString("cmd-ban-player")); return; } @@ -64,7 +64,7 @@ namespace Content.Server.Administration.Commands if (player != null && player.UserId == targetUid) { - shell.WriteLine("You can't ban yourself!"); + shell.WriteLine(Loc.GetString("cmd-ban-self")); return; } @@ -118,11 +118,11 @@ namespace Content.Server.Administration.Commands { var playerMgr = IoCManager.Resolve(); var options = playerMgr.ServerSessions.Select(c => c.Name).OrderBy(c => c).ToArray(); - return CompletionResult.FromHintOptions(options, ""); + return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-ban-hint")); } if (args.Length == 2) - return CompletionResult.FromHint(""); + return CompletionResult.FromHint(Loc.GetString("cmd-ban-hint-reason")); if (args.Length == 3) { @@ -133,7 +133,7 @@ namespace Content.Server.Administration.Commands new("10080", "1 week"), }; - return CompletionResult.FromHintOptions(durations, "[duration]"); + return CompletionResult.FromHintOptions(durations, Loc.GetString("cmd-ban-hint-duration")); } return CompletionResult.Empty; diff --git a/Content.Server/Administration/Commands/BanListCommand.cs b/Content.Server/Administration/Commands/BanListCommand.cs index e52b84296a..1c2be52394 100644 --- a/Content.Server/Administration/Commands/BanListCommand.cs +++ b/Content.Server/Administration/Commands/BanListCommand.cs @@ -1,53 +1,73 @@ -using Content.Server.Administration.BanList; +using System.Linq; +using Content.Server.Administration.BanList; +using Content.Server.Database; using Content.Server.EUI; using Content.Shared.Administration; using Robust.Server.Player; using Robust.Shared.Console; -namespace Content.Server.Administration.Commands -{ - [AdminCommand(AdminFlags.Ban)] - public sealed class BanListCommand : IConsoleCommand - { - public string Command => "banlist"; - public string Description => "Opens the ban list panel."; - public string Help => $"Usage: {Command} "; +namespace Content.Server.Administration.Commands; - public async void Execute(IConsoleShell shell, string argStr, string[] args) +/// +/// Lists someones active Ban Ids or opens a window to see them. +/// +[AdminCommand(AdminFlags.Ban)] +public sealed class BanListCommand : LocalizedCommands +{ + [Dependency] private readonly IServerDbManager _dbManager = default!; + [Dependency] private readonly EuiManager _eui = default!; + [Dependency] private readonly IPlayerLocator _locator = default!; + + public override string Command => "banlist"; + + public override async void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 1) { - if (shell.Player is not IPlayerSession player) + shell.WriteError(Help); + return; + } + + var data = await _locator.LookupIdByNameOrIdAsync(args[0]); + + if (data == null) + { + shell.WriteError(Loc.GetString("cmd-ban-player")); + return; + } + + if (shell.Player is not IPlayerSession player) + { + var bans = await _dbManager.GetServerBansAsync(data.LastAddress, data.UserId, data.LastHWId, false); + + if (bans.Count == 0) { - shell.WriteError("This does not work from the server console."); + shell.WriteLine(Loc.GetString("cmd-banlist-empty", ("user", data.Username))); return; } - Guid banListPlayer; - - switch (args.Length) + foreach (var ban in bans) { - case 1 when Guid.TryParse(args[0], out banListPlayer): - break; - case 1: - var locator = IoCManager.Resolve(); - var dbGuid = await locator.LookupIdByNameAsync(args[0]); - - if (dbGuid == null) - { - shell.WriteError($"Unable to find {args[0]} netuserid"); - return; - } - - banListPlayer = dbGuid.UserId; - break; - default: - shell.WriteError($"Invalid arguments.\n{Help}"); - return; + var msg = $"{ban.Id}: {ban.Reason}"; + shell.WriteLine(msg); } - var euis = IoCManager.Resolve(); - var ui = new BanListEui(); - euis.OpenEui(ui, player); - await ui.ChangeBanListPlayer(banListPlayer); + return; } + + var ui = new BanListEui(); + _eui.OpenEui(ui, player); + await ui.ChangeBanListPlayer(data.UserId); + } + + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length != 1) + return CompletionResult.Empty; + + var playerMgr = IoCManager.Resolve(); + var options = playerMgr.ServerSessions.Select(c => c.Name).OrderBy(c => c).ToArray(); + return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-banlist-hint")); } } diff --git a/Resources/Locale/en-US/info/ban.ftl b/Resources/Locale/en-US/info/ban.ftl new file mode 100644 index 0000000000..325e574168 --- /dev/null +++ b/Resources/Locale/en-US/info/ban.ftl @@ -0,0 +1,14 @@ +# ban +cmd-ban-desc = Bans somebody +cmd-ban-help = Usage: {$Command} [duration in minutes, leave out or 0 for permanent ban] +cmd-ban-player = Unable to find a player with that name. +cmd-ban-self = You can't ban yourself! +cmd-ban-hint = +cmd-ban-hint-reason = +cmd-ban-hint-duration = [duration] + +# listbans +cmd-banlist-desc = Lists a user's active bans. +cmd-banlist-help = Usage: banlist +cmd-banlist-empty = No active bans found for {$user} +cmd-banlistF-hint =