Fix whitelist commands not giving feedback with 0 arguments, trim names, add [player] completion hint (#21152)
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user