]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix whitelist commands not giving feedback with 0 arguments, trim names, add [player...
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Sat, 21 Oct 2023 21:57:51 +0000 (14:57 -0700)
committerGitHub <noreply@github.com>
Sat, 21 Oct 2023 21:57:51 +0000 (14:57 -0700)
Content.Server/Whitelist/WhitelistCommands.cs
Resources/Changelog/Admin.yml
Resources/Locale/en-US/connection-messages.ftl
Resources/Locale/en-US/shell.ftl

index 59b576e7ca4f129c028125d0fa83442c7f51464e..165b8dcae2208de675e7d66b67acadb5ee98ed05 100644 (file)
@@ -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<IServerDbManager>();
         var loc = IoCManager.Resolve<IPlayerLocator>();
 
-        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<IServerDbManager>();
         var loc = IoCManager.Resolve<IPlayerLocator>();
 
-        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<IConfigurationManager>();
 
@@ -111,6 +140,5 @@ public sealed class KickNonWhitelistedCommand : IConsoleCommand
                 net.DisconnectChannel(session.ConnectedClient, Loc.GetString("whitelist-not-whitelisted"));
             }
         }
-
     }
 }
index 74156b9d1326a0f8f0cc6ce0f233a0fd51385789..a5e13ab040b897ee383836fcb141d9716ef0e876 100644 (file)
@@ -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'
index 2755cf789a5190a688762a5c579e5bcb21f0af6b..b9eccda3ec49bab36337d3cde2c5e1c0cf1ee6fc 100644 (file)
@@ -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 <username>
-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 <username>
+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 <username>
-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 <username>
+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}
index fe69bb0c4a3875780f29f19df2fa641646947cd7..7a66fbc794d721659b4d43be549a897d17301ef2 100644 (file)
@@ -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