Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Content.Client/Administration/UI/BanList/BanListEui.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using System.Linq;
using System.Numerics;
using Content.Client.Administration.UI.BanList.Bans;
using Content.Client.Administration.UI.BanList.RoleBans;
using Content.Client.Eui;
Expand Down Expand Up @@ -73,7 +74,7 @@ private static string FormatDate(DateTimeOffset date)
return date.ToString("MM/dd/yyyy h:mm tt");
}

public static void SetData<T>(IBanListLine<T> line, SharedServerBan ban) where T : SharedServerBan
public static void SetData<T>(IBanListLine<T> line, SharedBan ban) where T : SharedBan
{
line.Reason.Text = ban.Reason;
line.BanTime.Text = FormatDate(ban.BanTime);
Expand All @@ -94,20 +95,20 @@ public static void SetData<T>(IBanListLine<T> line, SharedServerBan ban) where T
line.BanningAdmin.Text = ban.BanningAdminName;
}

private void OnLineIdsClicked<T>(IBanListLine<T> line) where T : SharedServerBan
private void OnLineIdsClicked<T>(IBanListLine<T> line) where T : SharedBan
{
_popup?.Close();
_popup = null;

var ban = line.Ban;
var id = ban.Id == null ? string.Empty : Loc.GetString("ban-list-id", ("id", ban.Id.Value));
var ip = ban.Address == null
var ip = ban.Addresses.Length == 0
? string.Empty
: Loc.GetString("ban-list-ip", ("ip", ban.Address.Value.address));
var hwid = ban.HWId == null ? string.Empty : Loc.GetString("ban-list-hwid", ("hwid", ban.HWId));
var guid = ban.UserId == null
: Loc.GetString("ban-list-ip", ("ip", string.Join(',', ban.Addresses.Select(a => a.address))));
var hwid = ban.HWIds.Length == 0 ? string.Empty : Loc.GetString("ban-list-hwid", ("hwid", string.Join(',', ban.HWIds)));
var guid = ban.UserIds.Length == 0
? string.Empty
: Loc.GetString("ban-list-guid", ("guid", ban.UserId.Value.ToString()));
: Loc.GetString("ban-list-guid", ("guid", string.Join(',', ban.UserIds)));

_popup = new BanListIdsPopup(id, ip, hwid, guid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public BanListControl()
RobustXamlLoader.Load(this);
}

public void SetBans(List<SharedServerBan> bans)
public void SetBans(List<SharedBan> bans)
{
for (var i = Bans.ChildCount - 1; i >= 1; i--)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
namespace Content.Client.Administration.UI.BanList.Bans;

[GenerateTypedNameReferences]
public sealed partial class BanListLine : BoxContainer, IBanListLine<SharedServerBan>
public sealed partial class BanListLine : BoxContainer, IBanListLine<SharedBan>
{
public SharedServerBan Ban { get; }
public SharedBan Ban { get; }

public event Action<BanListLine>? IdsClicked;

public BanListLine(SharedServerBan ban)
public BanListLine(SharedBan ban)
{
RobustXamlLoader.Load(this);

Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Administration/UI/BanList/IBanListLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Content.Client.Administration.UI.BanList;

public interface IBanListLine<T> where T : SharedServerBan
public interface IBanListLine<T> where T : SharedBan
{
T Ban { get; }
Label Reason { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public RoleBanListControl()
RobustXamlLoader.Load(this);
}

public void SetRoleBans(List<SharedServerRoleBan> bans)
public void SetRoleBans(List<SharedBan> bans)
{
for (var i = RoleBans.ChildCount - 1; i >= 1; i--)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
namespace Content.Client.Administration.UI.BanList.RoleBans;

[GenerateTypedNameReferences]
public sealed partial class RoleBanListLine : BoxContainer, IBanListLine<SharedServerRoleBan>
public sealed partial class RoleBanListLine : BoxContainer, IBanListLine<SharedBan>
{
public SharedServerRoleBan Ban { get; }
public SharedBan Ban { get; }

public event Action<RoleBanListLine>? IdsClicked;

public RoleBanListLine(SharedServerRoleBan ban)
public RoleBanListLine(SharedBan ban)
{
RobustXamlLoader.Load(this);

Ban = ban;
IdsHidden.OnPressed += IdsPressed;

BanListEui.SetData(this, ban);
Role.Text = ban.Role;
Role.Text = string.Join(", ", ban.Roles ?? []);
}

private void IdsPressed(ButtonEventArgs buttonEventArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void Refresh()

TimeLabel.Text = Note.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
ServerLabel.Text = Note.ServerName ?? "Unknown";
RoundLabel.Text = Note.Round == null ? "Unknown round" : "Round " + Note.Round;
RoundLabel.Text = Note.Rounds.Length == 0 ? "Unknown round" : "Round " + string.Join(',', Note.Rounds);
AdminLabel.Text = Note.CreatedByName;
PlaytimeLabel.Text = $"{Note.PlaytimeAtNote.TotalHours: 0.0}h";

Expand Down Expand Up @@ -143,7 +143,7 @@ private string FormatBanMessage()

private string FormatRoleBanMessage()
{
var banMessage = new StringBuilder($"{Loc.GetString("admin-notes-banned-from")} {string.Join(", ", Note.BannedRoles ?? new[] { "unknown" })} ");
var banMessage = new StringBuilder($"{Loc.GetString("admin-notes-banned-from")} {string.Join(", ", Note.BannedRoles ?? [new BanRoleDef("what", "You should not be seeing this")])} ");
return FormatBanMessageCommon(banMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public AdminNotesLinePopup(SharedAdminNote note, string playerName, bool showDel
IdLabel.Text = Loc.GetString("admin-notes-id", ("id", note.Id));
TypeLabel.Text = Loc.GetString("admin-notes-type", ("type", note.NoteType));
SeverityLabel.Text = Loc.GetString("admin-notes-severity", ("severity", note.NoteSeverity ?? NoteSeverity.None));
RoundIdLabel.Text = note.Round == null
RoundIdLabel.Text = note.Rounds.Length == 0
? Loc.GetString("admin-notes-round-id-unknown")
: Loc.GetString("admin-notes-round-id", ("id", note.Round));
: Loc.GetString("admin-notes-round-id", ("id", string.Join(',', note.Rounds)));
CreatedByLabel.Text = Loc.GetString("admin-notes-created-by", ("author", note.CreatedByName));
CreatedAtLabel.Text = Loc.GetString("admin-notes-created-at", ("date", note.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")));
EditedByLabel.Text = Loc.GetString("admin-notes-last-edited-by", ("author", note.EditedByName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public sealed class JobRequirementsManager : ISharedPlaytimeManager
[Dependency] private readonly IPrototypeManager _prototypes = default!;

private readonly Dictionary<string, TimeSpan> _roles = new();
private readonly List<string> _jobBans = new();
private readonly List<string> _antagBans = new();
private readonly List<ProtoId<JobPrototype>> _jobBans = new();
private readonly List<ProtoId<AntagPrototype>> _antagBans = new();
private readonly List<string> _jobWhitelists = new();

private ISawmill _sawmill = default!;
Expand Down
40 changes: 20 additions & 20 deletions Content.IntegrationTests/Tests/Commands/PardonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public async Task PardonTest()
// No bans on record
Assert.Multiple(async () =>
{
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null, null), Is.Null);
Assert.That(await sDatabase.GetServerBanAsync(1), Is.Null);
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null, null), Is.Empty);
Assert.That(await sDatabase.GetBanAsync(null, clientId, null, null), Is.Null);
Assert.That(await sDatabase.GetBanAsync(1), Is.Null);
Assert.That(await sDatabase.GetBansAsync(null, clientId, null, null), Is.Empty);
});

// Try to pardon a ban that does not exist
Expand All @@ -43,9 +43,9 @@ public async Task PardonTest()
// Still no bans on record
Assert.Multiple(async () =>
{
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null, null), Is.Null);
Assert.That(await sDatabase.GetServerBanAsync(1), Is.Null);
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null, null), Is.Empty);
Assert.That(await sDatabase.GetBanAsync(null, clientId, null, null), Is.Null);
Assert.That(await sDatabase.GetBanAsync(1), Is.Null);
Assert.That(await sDatabase.GetBansAsync(null, clientId, null, null), Is.Empty);
});

var banReason = "test";
Expand All @@ -57,9 +57,9 @@ public async Task PardonTest()
// Should have one ban on record now
Assert.Multiple(async () =>
{
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null, null), Is.Not.Null);
Assert.That(await sDatabase.GetServerBanAsync(1), Is.Not.Null);
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));
Assert.That(await sDatabase.GetBanAsync(null, clientId, null, null), Is.Not.Null);
Assert.That(await sDatabase.GetBanAsync(1), Is.Not.Null);
Assert.That(await sDatabase.GetBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));
});

await pair.RunTicksSync(5);
Expand All @@ -70,17 +70,17 @@ public async Task PardonTest()
await server.WaitPost(() => sConsole.ExecuteCommand("pardon 2"));

// The existing ban is unaffected
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null, null), Is.Not.Null);
Assert.That(await sDatabase.GetBanAsync(null, clientId, null, null), Is.Not.Null);

var ban = await sDatabase.GetServerBanAsync(1);
var ban = await sDatabase.GetBanAsync(1);
Assert.Multiple(async () =>
{
Assert.That(ban, Is.Not.Null);
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));
Assert.That(await sDatabase.GetBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));

// Check that it matches
Assert.That(ban.Id, Is.EqualTo(1));
Assert.That(ban.UserId, Is.EqualTo(clientId));
Assert.That(ban.UserIds, Is.EquivalentTo([clientId]));
Assert.That(ban.BanTime.UtcDateTime - DateTime.UtcNow, Is.LessThanOrEqualTo(MarginOfError));
Assert.That(ban.ExpirationTime, Is.Not.Null);
Assert.That(ban.ExpirationTime.Value.UtcDateTime - DateTime.UtcNow.AddHours(24), Is.LessThanOrEqualTo(MarginOfError));
Expand All @@ -95,20 +95,20 @@ public async Task PardonTest()
await server.WaitPost(() => sConsole.ExecuteCommand("pardon 1"));

// No bans should be returned
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null, null), Is.Null);
Assert.That(await sDatabase.GetBanAsync(null, clientId, null, null), Is.Null);

// Direct id lookup returns a pardoned ban
var pardonedBan = await sDatabase.GetServerBanAsync(1);
var pardonedBan = await sDatabase.GetBanAsync(1);
Assert.Multiple(async () =>
{
// Check that it matches
Assert.That(pardonedBan, Is.Not.Null);

// The list is still returned since that ignores pardons
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));
Assert.That(await sDatabase.GetBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));

Assert.That(pardonedBan.Id, Is.EqualTo(1));
Assert.That(pardonedBan.UserId, Is.EqualTo(clientId));
Assert.That(pardonedBan.UserIds, Is.EquivalentTo([clientId]));
Assert.That(pardonedBan.BanTime.UtcDateTime - DateTime.UtcNow, Is.LessThanOrEqualTo(MarginOfError));
Assert.That(pardonedBan.ExpirationTime, Is.Not.Null);
Assert.That(pardonedBan.ExpirationTime.Value.UtcDateTime - DateTime.UtcNow.AddHours(24), Is.LessThanOrEqualTo(MarginOfError));
Expand All @@ -133,13 +133,13 @@ public async Task PardonTest()
Assert.Multiple(async () =>
{
// No bans should be returned
Assert.That(await sDatabase.GetServerBanAsync(null, clientId, null, null), Is.Null);
Assert.That(await sDatabase.GetBanAsync(null, clientId, null, null), Is.Null);

// Direct id lookup returns a pardoned ban
Assert.That(await sDatabase.GetServerBanAsync(1), Is.Not.Null);
Assert.That(await sDatabase.GetBanAsync(1), Is.Not.Null);

// The list is still returned since that ignores pardons
Assert.That(await sDatabase.GetServerBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));
Assert.That(await sDatabase.GetBansAsync(null, clientId, null, null), Has.Count.EqualTo(1));
});

// Reconnect client. Slightly faster than dirtying the pair.
Expand Down
Loading
Loading