Role ban improvements (#6855)
This commit is contained in:
@@ -112,6 +112,22 @@ namespace Content.Server.Database
|
||||
modelBuilder.Entity<ServerBan>()
|
||||
.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
|
||||
|
||||
modelBuilder.Entity<ServerRoleBan>()
|
||||
.HasIndex(p => p.UserId);
|
||||
|
||||
modelBuilder.Entity<ServerRoleBan>()
|
||||
.HasIndex(p => p.Address);
|
||||
|
||||
modelBuilder.Entity<ServerRoleBan>()
|
||||
.HasIndex(p => p.UserId);
|
||||
|
||||
modelBuilder.Entity<ServerRoleUnban>()
|
||||
.HasIndex(p => p.BanId)
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<ServerRoleBan>()
|
||||
.HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL");
|
||||
|
||||
modelBuilder.Entity<Player>()
|
||||
.HasIndex(p => p.UserId)
|
||||
.IsUnique();
|
||||
|
||||
@@ -53,12 +53,21 @@ public sealed class RoleBanListCommand : IConsoleCommand
|
||||
|
||||
var bansString = new StringBuilder("Bans in record:\n");
|
||||
|
||||
var first = true;
|
||||
foreach (var ban in bans)
|
||||
{
|
||||
if (!first)
|
||||
bansString.Append("\n\n");
|
||||
else
|
||||
first = false;
|
||||
|
||||
bansString
|
||||
.Append("Ban ID: ")
|
||||
.Append(ban.Id)
|
||||
.Append("\n")
|
||||
.Append('\n')
|
||||
.Append("Role: ")
|
||||
.Append(ban.Role)
|
||||
.Append('\n')
|
||||
.Append("Banned on ")
|
||||
.Append(ban.BanTime);
|
||||
|
||||
@@ -70,13 +79,11 @@ public sealed class RoleBanListCommand : IConsoleCommand
|
||||
}
|
||||
|
||||
bansString
|
||||
.Append(".")
|
||||
.Append("\n");
|
||||
.Append('\n');
|
||||
|
||||
bansString
|
||||
.Append("Reason: ")
|
||||
.Append(ban.Reason)
|
||||
.Append('\n');
|
||||
.Append(ban.Reason);
|
||||
}
|
||||
|
||||
shell.WriteLine(bansString.ToString());
|
||||
|
||||
60
Content.Server/Administration/Commands/RoleUnbanCommand.cs
Normal file
60
Content.Server/Administration/Commands/RoleUnbanCommand.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Text;
|
||||
using Content.Server.Database;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Administration.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Ban)]
|
||||
public sealed class RoleUnbanCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "roleunban";
|
||||
public string Description => "Pardons a player's role ban";
|
||||
public string Help => $"Usage: {Command} <role ban id>";
|
||||
|
||||
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = shell.Player as IPlayerSession;
|
||||
var dbMan = IoCManager.Resolve<IServerDbManager>();
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
shell.WriteLine(Help);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var banId))
|
||||
{
|
||||
shell.WriteLine($"Unable to parse {args[1]} as a ban id integer.\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
var ban = await dbMan.GetServerRoleBanAsync(banId);
|
||||
|
||||
if (ban == null)
|
||||
{
|
||||
shell.WriteLine($"No ban found with id {banId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ban.Unban != null)
|
||||
{
|
||||
var response = new StringBuilder("This ban has already been pardoned");
|
||||
|
||||
if (ban.Unban.UnbanningAdmin != null)
|
||||
{
|
||||
response.Append($" by {ban.Unban.UnbanningAdmin.Value}");
|
||||
}
|
||||
|
||||
response.Append($" in {ban.Unban.UnbanTime}.");
|
||||
|
||||
shell.WriteLine(response.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
await dbMan.AddServerRoleUnbanAsync(new ServerRoleUnbanDef(banId, player?.UserId, DateTimeOffset.Now));
|
||||
|
||||
shell.WriteLine($"Pardoned ban with id {banId}");
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ namespace Content.Server.Database
|
||||
var queryBans = await GetAllRoleBans(db.SqliteDbContext, includeUnbanned);
|
||||
|
||||
return queryBans
|
||||
.Where(b => BanMatches(b, address, userId, hwId))
|
||||
.Where(b => RoleBanMatches(b, address, userId, hwId))
|
||||
.Select(ConvertRoleBan)
|
||||
.ToList()!;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ namespace Content.Server.Database
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
private static bool BanMatches(
|
||||
private static bool RoleBanMatches(
|
||||
ServerRoleBan ban,
|
||||
IPAddress? address,
|
||||
NetUserId? userId,
|
||||
|
||||
Reference in New Issue
Block a user