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"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user