Automated whitelists (#23985)
* Beginnings of making the breadmemes jobs easier * stuff * stuff pt. 2 * Stuff pt.3 * Stuff I forgot last time * Basic whitelist Only people that are added to the whitelist with the addwhitelist command will be able to join. I call this the "legacy" whitelist * Remove always deny condition in favor of just breaking if playtime check fails * Change default whitelist Default whitelist is now the "legacy" whitelist. * localization * Admin check * minor spelling change * Fix build * Whitelist message * Fix vars not being datafield and spelling mistakes * Minor spelling mistake * Change config for salamander * Reviews and stuff * Add summaries * Fix whitelists * Forgot to add a datafield * Fixing stuff I guess * Reuse admin remarks to reduce load when connecting. * Update log messages to be verbose instead of debug * Reviews * whoops * Explain a bit more how whitelist checking works * Apply CE's review * Append Membership to Blacklist and Whitelist conditions * Fix review comments * Uncapitalize playerConnectionWhitelist, add to ignored client prototypes * Make note count field work * Fix cvar for thingy --------- Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
117
Content.Server/Connection/Whitelist/BlacklistCommands.cs
Normal file
117
Content.Server/Connection/Whitelist/BlacklistCommands.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Database;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Connection.Whitelist;
|
||||
|
||||
[AdminCommand(AdminFlags.Ban)]
|
||||
public sealed class AddBlacklistCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
|
||||
[Dependency] private readonly IServerDbManager _db = default!;
|
||||
|
||||
public override string Command => "blacklistadd";
|
||||
|
||||
public override async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-need-minimum-one-argument"));
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-need-exactly-one-argument"));
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[0];
|
||||
var data = await _playerLocator.LookupIdByNameAsync(name);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-blacklistadd-not-found", ("username", args[0])));
|
||||
return;
|
||||
}
|
||||
var guid = data.UserId;
|
||||
var isBlacklisted = await _db.GetBlacklistStatusAsync(guid);
|
||||
if (isBlacklisted)
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("cmd-blacklistadd-existing", ("username", data.Username)));
|
||||
return;
|
||||
}
|
||||
|
||||
await _db.AddToBlacklistAsync(guid);
|
||||
shell.WriteLine(Loc.GetString("cmd-blacklistadd-added", ("username", data.Username)));
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
return CompletionResult.FromHint(Loc.GetString("cmd-blacklistadd-arg-player"));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
[AdminCommand(AdminFlags.Ban)]
|
||||
public sealed class RemoveBlacklistCommand : LocalizedCommands
|
||||
{
|
||||
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
|
||||
[Dependency] private readonly IServerDbManager _db = default!;
|
||||
|
||||
public override string Command => "blacklistremove";
|
||||
|
||||
public override async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-need-minimum-one-argument"));
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("shell-need-exactly-one-argument"));
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[0];
|
||||
var data = await _playerLocator.LookupIdByNameAsync(name);
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
shell.WriteError(Loc.GetString("cmd-blacklistremove-not-found", ("username", args[0])));
|
||||
return;
|
||||
}
|
||||
|
||||
var guid = data.UserId;
|
||||
var isBlacklisted = await _db.GetBlacklistStatusAsync(guid);
|
||||
if (!isBlacklisted)
|
||||
{
|
||||
shell.WriteLine(Loc.GetString("cmd-blacklistremove-existing", ("username", data.Username)));
|
||||
return;
|
||||
}
|
||||
|
||||
await _db.RemoveFromBlacklistAsync(guid);
|
||||
shell.WriteLine(Loc.GetString("cmd-blacklistremove-removed", ("username", data.Username)));
|
||||
}
|
||||
|
||||
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
return CompletionResult.FromHint(Loc.GetString("cmd-blacklistremove-arg-player"));
|
||||
}
|
||||
|
||||
return CompletionResult.Empty;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user