@@ -48,7 +48,7 @@ namespace Content.Server.Administration.Commands
|
|||||||
expires = DateTimeOffset.Now + TimeSpan.FromMinutes(duration);
|
expires = DateTimeOffset.Now + TimeSpan.FromMinutes(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
await dbMan.AddServerBanAsync(new ServerBanDef(targetUid, null, DateTimeOffset.Now, expires, reason, player?.UserId));
|
await dbMan.AddServerBanAsync(new ServerBanDef(null, targetUid, null, DateTimeOffset.Now, expires, reason, player?.UserId));
|
||||||
|
|
||||||
if (plyMgr.TryGetSessionById(targetUid, out var targetPlayer))
|
if (plyMgr.TryGetSessionById(targetUid, out var targetPlayer))
|
||||||
{
|
{
|
||||||
|
|||||||
89
Content.Server/Administration/Commands/BanListCommand.cs
Normal file
89
Content.Server/Administration/Commands/BanListCommand.cs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Content.Server.Database;
|
||||||
|
using Content.Shared.Administration;
|
||||||
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Console;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Network;
|
||||||
|
|
||||||
|
namespace Content.Server.Administration.Commands
|
||||||
|
{
|
||||||
|
[AdminCommand(AdminFlags.Ban)]
|
||||||
|
public class BanListCommand : IConsoleCommand
|
||||||
|
{
|
||||||
|
public string Command => "banlist";
|
||||||
|
public string Description => "Lists somebody's bans";
|
||||||
|
public string Help => "Usage: <name or user ID>";
|
||||||
|
|
||||||
|
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||||
|
{
|
||||||
|
if (args.Length != 1)
|
||||||
|
{
|
||||||
|
shell.WriteLine($"Invalid amount of args. {Help}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var plyMgr = IoCManager.Resolve<IPlayerManager>();
|
||||||
|
var dbMan = IoCManager.Resolve<IServerDbManager>();
|
||||||
|
|
||||||
|
var target = args[0];
|
||||||
|
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.WriteLine("Unable to find user with that name.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bans = await dbMan.GetServerBansAsync(null, targetUid);
|
||||||
|
|
||||||
|
if (bans.Count == 0)
|
||||||
|
{
|
||||||
|
shell.WriteLine("That user has no bans in their record.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bansString = new StringBuilder("Bans in record:\n");
|
||||||
|
|
||||||
|
foreach (var ban in bans)
|
||||||
|
{
|
||||||
|
bansString
|
||||||
|
.Append("Ban ID: ")
|
||||||
|
.Append(ban.Id)
|
||||||
|
.Append("\n")
|
||||||
|
.Append("Banned in ")
|
||||||
|
.Append(ban.BanTime);
|
||||||
|
|
||||||
|
if (ban.ExpirationTime == null)
|
||||||
|
{
|
||||||
|
bansString.Append(".");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bansString
|
||||||
|
.Append(" until ")
|
||||||
|
.Append(ban.ExpirationTime.Value)
|
||||||
|
.Append(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
bansString.Append("\n");
|
||||||
|
|
||||||
|
bansString
|
||||||
|
.Append("Reason: ")
|
||||||
|
.Append(ban.Reason)
|
||||||
|
.Append("\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
shell.WriteLine(bansString.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ namespace Content.Server.Database
|
|||||||
{
|
{
|
||||||
public sealed class ServerBanDef
|
public sealed class ServerBanDef
|
||||||
{
|
{
|
||||||
|
public int? Id { get; }
|
||||||
public NetUserId? UserId { get; }
|
public NetUserId? UserId { get; }
|
||||||
public (IPAddress address, int cidrMask)? Address { get; }
|
public (IPAddress address, int cidrMask)? Address { get; }
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ namespace Content.Server.Database
|
|||||||
public string Reason { get; }
|
public string Reason { get; }
|
||||||
public NetUserId? BanningAdmin { get; }
|
public NetUserId? BanningAdmin { get; }
|
||||||
|
|
||||||
public ServerBanDef(NetUserId? userId, (IPAddress, int)? address, DateTimeOffset banTime, DateTimeOffset? expirationTime, string reason, NetUserId? banningAdmin)
|
public ServerBanDef(int? id, NetUserId? userId, (IPAddress, int)? address, DateTimeOffset banTime, DateTimeOffset? expirationTime, string reason, NetUserId? banningAdmin)
|
||||||
{
|
{
|
||||||
if (userId == null && address == null)
|
if (userId == null && address == null)
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,7 @@ namespace Content.Server.Database
|
|||||||
address = (addr.Item1.MapToIPv4(), addr.Item2 - 96);
|
address = (addr.Item1.MapToIPv4(), addr.Item2 - 96);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Id = id;
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
Address = address;
|
Address = address;
|
||||||
BanTime = banTime;
|
BanTime = banTime;
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ namespace Content.Server.Database
|
|||||||
* BAN STUFF
|
* BAN STUFF
|
||||||
*/
|
*/
|
||||||
public abstract Task<ServerBanDef?> GetServerBanAsync(IPAddress? address, NetUserId? userId);
|
public abstract Task<ServerBanDef?> GetServerBanAsync(IPAddress? address, NetUserId? userId);
|
||||||
|
public abstract Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address, NetUserId? userId);
|
||||||
public abstract Task AddServerBanAsync(ServerBanDef serverBan);
|
public abstract Task AddServerBanAsync(ServerBanDef serverBan);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -41,6 +42,7 @@ namespace Content.Server.Database
|
|||||||
|
|
||||||
// Ban stuff
|
// Ban stuff
|
||||||
Task<ServerBanDef?> GetServerBanAsync(IPAddress? address, NetUserId? userId);
|
Task<ServerBanDef?> GetServerBanAsync(IPAddress? address, NetUserId? userId);
|
||||||
|
Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address, NetUserId? userId);
|
||||||
Task AddServerBanAsync(ServerBanDef serverBan);
|
Task AddServerBanAsync(ServerBanDef serverBan);
|
||||||
|
|
||||||
// Player records
|
// Player records
|
||||||
@@ -142,6 +144,11 @@ namespace Content.Server.Database
|
|||||||
return _db.GetServerBanAsync(address, userId);
|
return _db.GetServerBanAsync(address, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address, NetUserId? userId)
|
||||||
|
{
|
||||||
|
return _db.GetServerBansAsync(address, userId);
|
||||||
|
}
|
||||||
|
|
||||||
public Task AddServerBanAsync(ServerBanDef serverBan)
|
public Task AddServerBanAsync(ServerBanDef serverBan)
|
||||||
{
|
{
|
||||||
return _db.AddServerBanAsync(serverBan);
|
return _db.AddServerBanAsync(serverBan);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -74,6 +75,56 @@ namespace Content.Server.Database
|
|||||||
return ConvertBan(ban);
|
return ConvertBan(ban);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address, NetUserId? userId)
|
||||||
|
{
|
||||||
|
if (address == null && userId == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Address and userId cannot both be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
await using var db = await GetDbImpl();
|
||||||
|
|
||||||
|
var query = db.PgDbContext.Ban
|
||||||
|
.Include(p => p.Unban).AsQueryable();
|
||||||
|
|
||||||
|
if (userId is { } uid)
|
||||||
|
{
|
||||||
|
if (address == null)
|
||||||
|
{
|
||||||
|
// Only have a user ID.
|
||||||
|
query = query.Where(p => p.UserId == uid.UserId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Have both user ID and IP address.
|
||||||
|
query = query.Where(p =>
|
||||||
|
(p.Address != null && EF.Functions.ContainsOrEqual(p.Address.Value, address))
|
||||||
|
|| p.UserId == uid.UserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Only have a connecting address.
|
||||||
|
query = query.Where(
|
||||||
|
p => p.Address != null && EF.Functions.ContainsOrEqual(p.Address.Value, address));
|
||||||
|
}
|
||||||
|
|
||||||
|
var queryBans = await query.ToArrayAsync();
|
||||||
|
var bans = new List<ServerBanDef>();
|
||||||
|
|
||||||
|
foreach (var ban in queryBans)
|
||||||
|
{
|
||||||
|
var banDef = ConvertBan(ban);
|
||||||
|
|
||||||
|
if (banDef != null)
|
||||||
|
{
|
||||||
|
bans.Add(banDef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bans;
|
||||||
|
}
|
||||||
|
|
||||||
private static ServerBanDef? ConvertBan(PostgresServerBan? ban)
|
private static ServerBanDef? ConvertBan(PostgresServerBan? ban)
|
||||||
{
|
{
|
||||||
if (ban == null)
|
if (ban == null)
|
||||||
@@ -94,6 +145,7 @@ namespace Content.Server.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new ServerBanDef(
|
return new ServerBanDef(
|
||||||
|
ban.Id,
|
||||||
uid,
|
uid,
|
||||||
ban.Address,
|
ban.Address,
|
||||||
ban.BanTime,
|
ban.BanTime,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -72,6 +73,42 @@ namespace Content.Server.Database
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<List<ServerBanDef>> GetServerBansAsync(IPAddress? address, NetUserId? userId)
|
||||||
|
{
|
||||||
|
await using var db = await GetDbImpl();
|
||||||
|
|
||||||
|
// SQLite can't do the net masking stuff we need to match IP address ranges.
|
||||||
|
// So just pull down the whole list into memory.
|
||||||
|
var queryBans = await db.SqliteDbContext.Ban
|
||||||
|
.Include(p => p.Unban)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var bans = new List<ServerBanDef>();
|
||||||
|
|
||||||
|
foreach (var ban in queryBans)
|
||||||
|
{
|
||||||
|
ServerBanDef? banDef = null;
|
||||||
|
|
||||||
|
if (address != null && ban.Address != null && address.IsInSubnet(ban.Address))
|
||||||
|
{
|
||||||
|
banDef = ConvertBan(ban);
|
||||||
|
}
|
||||||
|
else if (userId is { } id && ban.UserId == id.UserId)
|
||||||
|
{
|
||||||
|
banDef = ConvertBan(ban);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (banDef == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bans.Add(banDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bans;
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task AddServerBanAsync(ServerBanDef serverBan)
|
public override async Task AddServerBanAsync(ServerBanDef serverBan)
|
||||||
{
|
{
|
||||||
await using var db = await GetDbImpl();
|
await using var db = await GetDbImpl();
|
||||||
@@ -182,6 +219,7 @@ namespace Content.Server.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new ServerBanDef(
|
return new ServerBanDef(
|
||||||
|
ban.Id,
|
||||||
uid,
|
uid,
|
||||||
addrTuple,
|
addrTuple,
|
||||||
ban.BanTime,
|
ban.BanTime,
|
||||||
|
|||||||
Reference in New Issue
Block a user