Holy crap auth works (#2099)
* Holy crap auth works * Fix some usages of UserID instead of UserName * Refactor preferences. They be non-async now. Also faster. * Rename DbContext. * Guest username assignment. * Fix saving of profiles. * Don't store data for guests. * Fix generating invalid random colors. * Don't allow dumb garbage for char preferences. * Bans. * Lol forgot to fill out the command description. * Connection log. * Rename all the tables and columns to be snake_case. * Re-do migrations. * Fixing tests and warnings. * Update submodule
This commit is contained in:
committed by
GitHub
parent
8a33e0a9bd
commit
66c8a68891
57
Content.Server/Administration/BanCommand.cs
Normal file
57
Content.Server/Administration/BanCommand.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using Content.Server.Database;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Server.Administration
|
||||
{
|
||||
public sealed class BanCommand : IClientCommand
|
||||
{
|
||||
public string Command => "ban";
|
||||
public string Description => "Bans somebody";
|
||||
public string Help => "Usage: <name or user ID> <reason> <duration in minutes, or 0 for permanent ban>";
|
||||
|
||||
public async void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||
{
|
||||
var plyMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
var dbMan = IoCManager.Resolve<IServerDbManager>();
|
||||
|
||||
var target = args[0];
|
||||
var reason = args[1];
|
||||
var duration = int.Parse(args[2]);
|
||||
NetUserId targetUid;
|
||||
|
||||
if (plyMgr.TryGetSessionByUsername(target, out var targetSession))
|
||||
{
|
||||
targetUid = targetSession.UserId;
|
||||
}
|
||||
else if (Guid.TryParse(target, out var targetGuid))
|
||||
{
|
||||
targetUid = new NetUserId(targetGuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
shell.SendText(player, "Unable to find user with that name.");
|
||||
return;
|
||||
}
|
||||
|
||||
DateTimeOffset? expires = null;
|
||||
if (duration > 0)
|
||||
{
|
||||
expires = DateTimeOffset.Now + TimeSpan.FromMinutes(duration);
|
||||
}
|
||||
|
||||
await dbMan.AddServerBanAsync(new ServerBanDef(targetUid, null, DateTimeOffset.Now, expires, reason, player?.UserId));
|
||||
|
||||
if (plyMgr.TryGetSessionById(targetUid, out var targetPlayer))
|
||||
{
|
||||
targetPlayer.ConnectedClient.Disconnect("You've been banned. Tough shit.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user