diff --git a/Content.Server.Database/Model.cs b/Content.Server.Database/Model.cs index 1eafaf2152..8119091553 100644 --- a/Content.Server.Database/Model.cs +++ b/Content.Server.Database/Model.cs @@ -112,6 +112,22 @@ namespace Content.Server.Database modelBuilder.Entity() .HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL"); + modelBuilder.Entity() + .HasIndex(p => p.UserId); + + modelBuilder.Entity() + .HasIndex(p => p.Address); + + modelBuilder.Entity() + .HasIndex(p => p.UserId); + + modelBuilder.Entity() + .HasIndex(p => p.BanId) + .IsUnique(); + + modelBuilder.Entity() + .HasCheckConstraint("HaveEitherAddressOrUserIdOrHWId", "address IS NOT NULL OR user_id IS NOT NULL OR hwid IS NOT NULL"); + modelBuilder.Entity() .HasIndex(p => p.UserId) .IsUnique(); diff --git a/Content.Server/Administration/Commands/RoleBanListCommand.cs b/Content.Server/Administration/Commands/RoleBanListCommand.cs index c23c1c141e..14f93099d7 100644 --- a/Content.Server/Administration/Commands/RoleBanListCommand.cs +++ b/Content.Server/Administration/Commands/RoleBanListCommand.cs @@ -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()); diff --git a/Content.Server/Administration/Commands/RoleUnbanCommand.cs b/Content.Server/Administration/Commands/RoleUnbanCommand.cs new file mode 100644 index 0000000000..5f5925cd96 --- /dev/null +++ b/Content.Server/Administration/Commands/RoleUnbanCommand.cs @@ -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} "; + + public async void Execute(IConsoleShell shell, string argStr, string[] args) + { + var player = shell.Player as IPlayerSession; + var dbMan = IoCManager.Resolve(); + + 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}"); + } +} diff --git a/Content.Server/Database/ServerDbPostgres.cs b/Content.Server/Database/ServerDbPostgres.cs index 58d54e0b5d..86cfabe9fe 100644 --- a/Content.Server/Database/ServerDbPostgres.cs +++ b/Content.Server/Database/ServerDbPostgres.cs @@ -217,9 +217,9 @@ namespace Content.Server.Database db.PgDbContext.Unban.Add(new ServerUnban { - BanId = serverUnban.BanId, - UnbanningAdmin = serverUnban.UnbanningAdmin?.UserId, - UnbanTime = serverUnban.UnbanTime.UtcDateTime + BanId = serverUnban.BanId, + UnbanningAdmin = serverUnban.UnbanningAdmin?.UserId, + UnbanTime = serverUnban.UnbanTime.UtcDateTime }); await db.PgDbContext.SaveChangesAsync(); @@ -401,9 +401,9 @@ namespace Content.Server.Database db.PgDbContext.RoleUnban.Add(new ServerRoleUnban { - BanId = serverRoleUnban.BanId, - UnbanningAdmin = serverRoleUnban.UnbanningAdmin?.UserId, - UnbanTime = serverRoleUnban.UnbanTime.UtcDateTime + BanId = serverRoleUnban.BanId, + UnbanningAdmin = serverRoleUnban.UnbanningAdmin?.UserId, + UnbanTime = serverRoleUnban.UnbanTime.UtcDateTime }); await db.PgDbContext.SaveChangesAsync(); diff --git a/Content.Server/Database/ServerDbSqlite.cs b/Content.Server/Database/ServerDbSqlite.cs index ab89379c4a..4ad42baeed 100644 --- a/Content.Server/Database/ServerDbSqlite.cs +++ b/Content.Server/Database/ServerDbSqlite.cs @@ -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,