From b44281a5d4b69a6f154e3a6d9ee3908f60a2576d Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Sat, 21 Oct 2023 14:57:51 -0700 Subject: [PATCH] Fix whitelist commands not giving feedback with 0 arguments, trim names, add [player] completion hint (#21152) --- Content.Server/Whitelist/WhitelistCommands.cs | 80 +++++++++++++------ Resources/Changelog/Admin.yml | 9 +++ .../Locale/en-US/connection-messages.ftl | 26 +++--- Resources/Locale/en-US/shell.ftl | 2 + 4 files changed, 79 insertions(+), 38 deletions(-) diff --git a/Content.Server/Whitelist/WhitelistCommands.cs b/Content.Server/Whitelist/WhitelistCommands.cs index 59b576e7ca..165b8dcae2 100644 --- a/Content.Server/Whitelist/WhitelistCommands.cs +++ b/Content.Server/Whitelist/WhitelistCommands.cs @@ -10,20 +10,23 @@ using Robust.Shared.Network; namespace Content.Server.Whitelist; [AdminCommand(AdminFlags.Ban)] -public sealed class AddWhitelistCommand : IConsoleCommand +public sealed class AddWhitelistCommand : LocalizedCommands { - public string Command => "whitelistadd"; - public string Description => Loc.GetString("command-whitelistadd-description"); - public string Help => Loc.GetString("command-whitelistadd-help"); - public async void Execute(IConsoleShell shell, string argStr, string[] args) + public override string Command => "whitelistadd"; + + public override async void Execute(IConsoleShell shell, string argStr, string[] args) { - if (args.Length != 1) + if (args.Length == 0) + { + shell.WriteError(Loc.GetString("shell-need-minimum-one-argument")); + shell.WriteLine(Help); return; + } var db = IoCManager.Resolve(); var loc = IoCManager.Resolve(); - var name = args[0]; + var name = string.Join(' ', args).Trim(); var data = await loc.LookupIdByNameAsync(name); if (data != null) @@ -32,34 +35,47 @@ public sealed class AddWhitelistCommand : IConsoleCommand var isWhitelisted = await db.GetWhitelistStatusAsync(guid); if (isWhitelisted) { - shell.WriteLine(Loc.GetString("command-whitelistadd-existing", ("username", data.Username))); + shell.WriteLine(Loc.GetString("cmd-whitelistadd-existing", ("username", data.Username))); return; } await db.AddToWhitelistAsync(guid); - shell.WriteLine(Loc.GetString("command-whitelistadd-added", ("username", data.Username))); + shell.WriteLine(Loc.GetString("cmd-whitelistadd-added", ("username", data.Username))); return; } - shell.WriteError(Loc.GetString("command-whitelistadd-not-found", ("username", args[0]))); + shell.WriteError(Loc.GetString("cmd-whitelistadd-not-found", ("username", args[0]))); + } + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length == 1) + { + return CompletionResult.FromHint(Loc.GetString("cmd-whitelistadd-arg-player")); + } + + return CompletionResult.Empty; } } [AdminCommand(AdminFlags.Ban)] -public sealed class RemoveWhitelistCommand : IConsoleCommand +public sealed class RemoveWhitelistCommand : LocalizedCommands { - public string Command => "whitelistremove"; - public string Description => Loc.GetString("command-whitelistremove-description"); - public string Help => Loc.GetString("command-whitelistremove-help"); - public async void Execute(IConsoleShell shell, string argStr, string[] args) + public override string Command => "whitelistremove"; + + public override async void Execute(IConsoleShell shell, string argStr, string[] args) { - if (args.Length != 1) + if (args.Length == 0) + { + shell.WriteError(Loc.GetString("shell-need-minimum-one-argument")); + shell.WriteLine(Help); return; + } var db = IoCManager.Resolve(); var loc = IoCManager.Resolve(); - var name = args[0]; + var name = string.Join(' ', args).Trim(); var data = await loc.LookupIdByNameAsync(name); if (data != null) @@ -68,29 +84,42 @@ public sealed class RemoveWhitelistCommand : IConsoleCommand var isWhitelisted = await db.GetWhitelistStatusAsync(guid); if (!isWhitelisted) { - shell.WriteLine(Loc.GetString("command-whitelistremove-existing", ("username", data.Username))); + shell.WriteLine(Loc.GetString("cmd-whitelistremove-existing", ("username", data.Username))); return; } await db.RemoveFromWhitelistAsync(guid); - shell.WriteLine(Loc.GetString("command-whitelistremove-removed", ("username", data.Username))); + shell.WriteLine(Loc.GetString("cmd-whitelistremove-removed", ("username", data.Username))); return; } - shell.WriteError(Loc.GetString("command-whitelistremove-not-found", ("username", args[0]))); + shell.WriteError(Loc.GetString("cmd-whitelistremove-not-found", ("username", args[0]))); + } + + public override CompletionResult GetCompletion(IConsoleShell shell, string[] args) + { + if (args.Length == 1) + { + return CompletionResult.FromHint(Loc.GetString("cmd-whitelistremove-arg-player")); + } + + return CompletionResult.Empty; } } [AdminCommand(AdminFlags.Ban)] -public sealed class KickNonWhitelistedCommand : IConsoleCommand +public sealed class KickNonWhitelistedCommand : LocalizedCommands { - public string Command => "kicknonwhitelisted"; - public string Description => Loc.GetString("command-kicknonwhitelisted-description"); - public string Help => Loc.GetString("command-kicknonwhitelisted-help"); - public async void Execute(IConsoleShell shell, string argStr, string[] args) + public override string Command => "kicknonwhitelisted"; + + public override async void Execute(IConsoleShell shell, string argStr, string[] args) { if (args.Length != 0) + { + shell.WriteError(Loc.GetString("shell-wrong-arguments-number-need-specific", ("properAmount", 0), ("currentAmount", args.Length))); + shell.WriteLine(Help); return; + } var cfg = IoCManager.Resolve(); @@ -111,6 +140,5 @@ public sealed class KickNonWhitelistedCommand : IConsoleCommand net.DisconnectChannel(session.ConnectedClient, Loc.GetString("whitelist-not-whitelisted")); } } - } } diff --git a/Resources/Changelog/Admin.yml b/Resources/Changelog/Admin.yml index 74156b9d13..a5e13ab040 100644 --- a/Resources/Changelog/Admin.yml +++ b/Resources/Changelog/Admin.yml @@ -46,3 +46,12 @@ Entries: - {message: 'Fixed playtime being sorted incorrectly in the F7 players tab.', type: Fix} id: 7 time: '2023-10-16T04:23:00.0000000+00:00' +- author: DrSmugleaf + changes: + - {message: 'Fixed whitelist commands not giving feedback with 0 arguments.', type: Fix} + - {message: 'Fixed not trimming starting and trailing whitespaces within names + in whitelist commands.', type: Fix} + - {message: 'Added a \[player\] completion type hint to whitelist add and remove + commands.', type: Tweak} + id: 8 + time: '2023-10-21T09:53:00.0000000+00:00' diff --git a/Resources/Locale/en-US/connection-messages.ftl b/Resources/Locale/en-US/connection-messages.ftl index 2755cf789a..b9eccda3ec 100644 --- a/Resources/Locale/en-US/connection-messages.ftl +++ b/Resources/Locale/en-US/connection-messages.ftl @@ -10,20 +10,22 @@ whitelist-playercount-invalid = {$min -> } whitelist-not-whitelisted-rp = You are not whitelisted. To become whitelisted, visit our Discord (which can be found at https://spacestation14.io) and check the #rp-whitelist channel. -command-whitelistadd-description = Adds the player with the given username to the server whitelist. -command-whitelistadd-help = whitelistadd -command-whitelistadd-existing = {$username} is already on the whitelist! -command-whitelistadd-added = {$username} added to the whitelist -command-whitelistadd-not-found = Unable to find '{$username}' +cmd-whitelistadd-desc = Adds the player with the given username to the server whitelist. +cmd-whitelistadd-help = Usage: whitelistadd +cmd-whitelistadd-existing = {$username} is already on the whitelist! +cmd-whitelistadd-added = {$username} added to the whitelist +cmd-whitelistadd-not-found = Unable to find '{$username}' +cmd-whitelistadd-arg-player = [player] -command-whitelistremove-description = Removes the player with the given username from the server whitelist. -command-whitelistremove-help = whitelistremove -command-whitelistremove-existing = {$username} is not on the whitelist! -command-whitelistremove-removed = {$username} removed from the whitelist -command-whitelistremove-not-found = Unable to find '{$username}' +cmd-whitelistremove-desc = Removes the player with the given username from the server whitelist. +cmd-whitelistremove-help = Usage: whitelistremove +cmd-whitelistremove-existing = {$username} is not on the whitelist! +cmd-whitelistremove-removed = {$username} removed from the whitelist +cmd-whitelistremove-not-found = Unable to find '{$username}' +cmd-whitelistremove-arg-player = [player] -command-kicknonwhitelisted-description = Kicks all non-whitelisted players from the server. -command-kicknonwhitelisted-help = kicknonwhitelisted +cmd-kicknonwhitelisted-desc = Kicks all non-whitelisted players from the server. +cmd-kicknonwhitelisted-help = Usage: kicknonwhitelisted ban-banned-permanent = This ban will only be removed via appeal. ban-banned-permanent-appeal = This ban will only be removed via appeal. You can appeal at {$link} diff --git a/Resources/Locale/en-US/shell.ftl b/Resources/Locale/en-US/shell.ftl index fe69bb0c4a..7a66fbc794 100644 --- a/Resources/Locale/en-US/shell.ftl +++ b/Resources/Locale/en-US/shell.ftl @@ -18,6 +18,8 @@ shell-argument-must-be-number = Argument must be a number. shell-argument-must-be-boolean = Argument must be a boolean. shell-wrong-arguments-number = Wrong number of arguments. shell-need-between-arguments = Need {$lower} to {$upper} arguments! +shell-need-minimum-arguments = Need at least {$minimum} arguments! +shell-need-minimum-one-argument = Need at least one argument! shell-argument-uid = EntityUid