You can now ban people that aren't on the server. Or that have never JOINED the server in the first place. Amazing!

This commit is contained in:
Pieter-Jan Briers
2021-03-08 02:19:19 +01:00
parent cf48e3a2d8
commit 1818b561f8
3 changed files with 144 additions and 15 deletions

View File

@@ -5,7 +5,6 @@ using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
using Robust.Shared.Network;
#nullable enable
@@ -16,12 +15,13 @@ namespace Content.Server.Administration.Commands
{
public string Command => "ban";
public string Description => "Bans somebody";
public string Help => $"Usage: {Command} <name or user ID> <reason> <duration in minutes, or 0 for permanent ban>";
public string Help => $"Usage: {Command} <name or user ID> <reason> [duration in minutes, leave out or 0 for permanent ban]";
public async void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
var plyMgr = IoCManager.Resolve<IPlayerManager>();
var locator = IoCManager.Resolve<IPlayerLocator>();
var dbMan = IoCManager.Resolve<IServerDbManager>();
string target;
@@ -51,22 +51,15 @@ namespace Content.Server.Administration.Commands
return;
}
NetUserId targetUid;
if (plyMgr.TryGetSessionByUsername(target, out var targetSession))
var resolvedUid = await locator.LookupIdByNameOrIdAsync(target);
if (resolvedUid == null)
{
targetUid = targetSession.UserId;
}
else if (Guid.TryParse(target, out var targetGuid))
{
targetUid = new NetUserId(targetGuid);
}
else
{
shell.WriteLine("Unable to find user with that name.");
shell.WriteError("Unable to find a player with that name.");
return;
}
var targetUid = resolvedUid.Value;
if (player != null && player.UserId == targetUid)
{
shell.WriteLine("You can't ban yourself!");
@@ -81,7 +74,7 @@ namespace Content.Server.Administration.Commands
await dbMan.AddServerBanAsync(new ServerBanDef(null, targetUid, null, DateTimeOffset.Now, expires, reason, player?.UserId, null));
var response = new StringBuilder($"Banned {targetUid} with reason \"{reason}\"");
var response = new StringBuilder($"Banned {target} with reason \"{reason}\"");
response.Append(expires == null ?
" permanently."