diff --git a/Content.Client/Administration/UI/Notes/AdminNotesLinePopup.xaml.cs b/Content.Client/Administration/UI/Notes/AdminNotesLinePopup.xaml.cs index d78f2aac49..4dd4427487 100644 --- a/Content.Client/Administration/UI/Notes/AdminNotesLinePopup.xaml.cs +++ b/Content.Client/Administration/UI/Notes/AdminNotesLinePopup.xaml.cs @@ -1,4 +1,4 @@ -using Content.Shared.Administration.Notes; +using Content.Shared.Administration.Notes; using Content.Shared.Database; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; @@ -18,6 +18,7 @@ public sealed partial class AdminNotesLinePopup : Popup public AdminNotesLinePopup(SharedAdminNote note, string playerName, bool showDelete, bool showEdit) { + IoCManager.InjectDependencies(this); RobustXamlLoader.Load(this); NoteId = note.Id; diff --git a/Content.Client/Administration/UI/Notes/NoteEdit.xaml.cs b/Content.Client/Administration/UI/Notes/NoteEdit.xaml.cs index 23dd1b83ec..5cd3da438e 100644 --- a/Content.Client/Administration/UI/Notes/NoteEdit.xaml.cs +++ b/Content.Client/Administration/UI/Notes/NoteEdit.xaml.cs @@ -163,7 +163,7 @@ public sealed partial class NoteEdit : FancyWindow return; if (DeleteResetOn is null) { - DeleteResetOn = _gameTiming.CurTime.Add(TimeSpan.FromSeconds(3)); + DeleteResetOn = _gameTiming.RealTime + TimeSpan.FromSeconds(3); SubmitButton.Text = Loc.GetString("admin-note-editor-submit-confirm"); SubmitButton.ModulateSelfOverride = Color.Red; // Task.Delay(3000).ContinueWith(_ => ResetSubmitButton()); // TODO: fix @@ -185,7 +185,7 @@ public sealed partial class NoteEdit : FancyWindow { base.FrameUpdate(args); // This checks for null for free, do not invert it as null always produces a false value - if (DeleteResetOn > _gameTiming.CurTime) + if (DeleteResetOn < _gameTiming.RealTime) { ResetSubmitButton(); DeleteResetOn = null; diff --git a/Content.Server.Database/Migrations/Postgres/20230503001749_AdminNotesImprovement.cs b/Content.Server.Database/Migrations/Postgres/20230503001749_AdminNotesImprovement.cs index bfcaaabbd5..4047915b2c 100644 --- a/Content.Server.Database/Migrations/Postgres/20230503001749_AdminNotesImprovement.cs +++ b/Content.Server.Database/Migrations/Postgres/20230503001749_AdminNotesImprovement.cs @@ -28,10 +28,6 @@ namespace Content.Server.Database.Migrations.Postgres name: "FK_admin_notes_player_player_user_id", table: "admin_notes"); - migrationBuilder.DropCheckConstraint( - name: "HaveEitherAddressOrUserIdOrHWId", - table: "server_role_ban"); - migrationBuilder.DropCheckConstraint( name: "HaveEitherAddressOrUserIdOrHWId", table: "server_ban"); diff --git a/Content.Server/Administration/BanList/BanListEui.cs b/Content.Server/Administration/BanList/BanListEui.cs index a3edd4ec48..8da2acf829 100644 --- a/Content.Server/Administration/BanList/BanListEui.cs +++ b/Content.Server/Administration/BanList/BanListEui.cs @@ -31,6 +31,13 @@ public sealed class BanListEui : BaseEui _admins.OnPermsChanged += OnPermsChanged; } + public override void Closed() + { + base.Closed(); + + _admins.OnPermsChanged -= OnPermsChanged; + } + public override EuiStateBase GetNewState() { return new BanListEuiState(BanListPlayerName, Bans); @@ -42,10 +49,6 @@ public sealed class BanListEui : BaseEui { Close(); } - else - { - StateDirty(); - } } private async Task LoadFromDb() diff --git a/Content.Server/Administration/Commands/DepartmentBanCommand.cs b/Content.Server/Administration/Commands/DepartmentBanCommand.cs index 2dbd2f940f..a2e527b22a 100644 --- a/Content.Server/Administration/Commands/DepartmentBanCommand.cs +++ b/Content.Server/Administration/Commands/DepartmentBanCommand.cs @@ -99,8 +99,6 @@ public sealed class DepartmentBanCommand : IConsoleCommand { _banManager.CreateRoleBan(targetUid, located.Username, shell.Player?.UserId, null, targetHWid, job, minutes, severity, reason, now); } - - _banManager.SendRoleBans(located.UserId); } public CompletionResult GetCompletion(IConsoleShell shell, string[] args) diff --git a/Content.Server/Administration/Commands/RoleBanCommand.cs b/Content.Server/Administration/Commands/RoleBanCommand.cs index 23762755ed..8b535977ee 100644 --- a/Content.Server/Administration/Commands/RoleBanCommand.cs +++ b/Content.Server/Administration/Commands/RoleBanCommand.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using System.Text; using Content.Server.Administration.Managers; using Content.Shared.Administration; @@ -87,7 +87,6 @@ public sealed class RoleBanCommand : IConsoleCommand var targetHWid = located.LastHWId; _bans.CreateRoleBan(targetUid, located.Username, shell.Player?.UserId, null, targetHWid, job, minutes, severity, reason, DateTimeOffset.UtcNow); - _bans.SendRoleBans(located.UserId); } public CompletionResult GetCompletion(IConsoleShell shell, string[] args) diff --git a/Content.Server/Administration/Managers/BanManager.cs b/Content.Server/Administration/Managers/BanManager.cs index 197daa1d46..cc76438e28 100644 --- a/Content.Server/Administration/Managers/BanManager.cs +++ b/Content.Server/Administration/Managers/BanManager.cs @@ -40,6 +40,8 @@ public sealed class BanManager : IBanManager, IPostInjectInit public void Initialize() { _playerManager.PlayerStatusChanged += OnPlayerStatusChanged; + + _netManager.RegisterNetMessage(); } private async void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) @@ -212,6 +214,11 @@ public sealed class BanManager : IBanManager, IPostInjectInit var length = expires == null ? Loc.GetString("cmd-roleban-inf") : Loc.GetString("cmd-roleban-until", ("expires", expires)); _chat.SendAdminAlert(Loc.GetString("cmd-roleban-success", ("target", targetUsername ?? "null"), ("role", role), ("reason", reason), ("length", length))); + + if (target != null) + { + SendRoleBans(target.Value); + } } public HashSet? GetJobBans(NetUserId playerUserId) diff --git a/Content.Server/Content.Server.csproj b/Content.Server/Content.Server.csproj index 33d3871372..fa3ee60eb9 100644 --- a/Content.Server/Content.Server.csproj +++ b/Content.Server/Content.Server.csproj @@ -15,7 +15,6 @@ - diff --git a/Content.Server/Database/ServerDbBase.cs b/Content.Server/Database/ServerDbBase.cs index 47f6e16b37..63d820614a 100644 --- a/Content.Server/Database/ServerDbBase.cs +++ b/Content.Server/Database/ServerDbBase.cs @@ -1304,70 +1304,67 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id} // You can't group queries, as player will not always exist. When it doesn't, the // whole query returns nothing var player = await db.DbContext.Player.SingleOrDefaultAsync(p => p.UserId == user); - return await (from ban in db.DbContext.Ban - where ban.PlayerUserId == user && - !ban.Hidden - select ban) + var bans = await db.DbContext.Ban + .Where(ban => ban.PlayerUserId == user && !ban.Hidden) .Include(ban => ban.Unban) .Include(ban => ban.Round) .ThenInclude(r => r!.Server) .Include(ban => ban.CreatedBy) .Include(ban => ban.LastEditedBy) .Include(ban => ban.Unban) - .ToAsyncEnumerable() - .SelectAwait(async ban => - new ServerBanNote(ban.Id, ban.RoundId, ban.Round, ban.PlayerUserId, player, - ban.PlaytimeAtNote, ban.Reason, ban.Severity, ban.CreatedBy, ban.BanTime, - ban.LastEditedBy, ban.LastEditedAt, ban.ExpirationTime, ban.Hidden, - ban.Unban?.UnbanningAdmin == null - ? null - : await db.DbContext.Player.SingleOrDefaultAsync(p => p.UserId == ban.Unban.UnbanningAdmin.Value), - ban.Unban?.UnbanTime) - ).ToListAsync(); + .ToArrayAsync(); + + var banNotes = new List(); + foreach (var ban in bans) + { + var banNote = new ServerBanNote(ban.Id, ban.RoundId, ban.Round, ban.PlayerUserId, player, + ban.PlaytimeAtNote, ban.Reason, ban.Severity, ban.CreatedBy, ban.BanTime, + ban.LastEditedBy, ban.LastEditedAt, ban.ExpirationTime, ban.Hidden, + ban.Unban?.UnbanningAdmin == null + ? null + : await db.DbContext.Player.SingleOrDefaultAsync( + p => p.UserId == ban.Unban.UnbanningAdmin.Value), + ban.Unban?.UnbanTime); + + banNotes.Add(banNote); + } + + return banNotes; } protected async Task> GetGroupedServerRoleBansAsNotesForUser(DbGuard db, Guid user) { // Server side query - var bansQuery = - (from ban in db.DbContext.RoleBan - where ban.PlayerUserId == user && - !ban.Hidden - select ban) + var bansQuery = await db.DbContext.RoleBan + .Where(ban => ban.PlayerUserId == user && !ban.Hidden) .Include(ban => ban.Unban) .Include(ban => ban.Round) .ThenInclude(r => r!.Server) .Include(ban => ban.CreatedBy) .Include(ban => ban.LastEditedBy) .Include(ban => ban.Unban) - .ToAsyncEnumerable(); + .ToArrayAsync(); // Client side query, as EF can't do groups yet - var bansEnumerable = - (from ban in bansQuery - group ban by new - { - ban.BanTime, - ban.CreatedBy, - ban.Reason, - Unbanned = ban.Unban == null - } - into banGroup - select banGroup) - .AsAsyncEnumerable(); + var bansEnumerable = bansQuery + .GroupBy(ban => new { ban.BanTime, ban.CreatedBy, ban.Reason, Unbanned = ban.Unban == null }) + .Select(banGroup => banGroup) + .ToArray(); List bans = new(); var player = await db.DbContext.Player.SingleOrDefaultAsync(p => p.UserId == user); - await foreach (var banGroup in bansEnumerable) + foreach (var banGroup in bansEnumerable) { - var firstBan = await banGroup.FirstAsync(); + var firstBan = banGroup.First(); Player? unbanningAdmin = null; + if (firstBan.Unban?.UnbanningAdmin is not null) unbanningAdmin = await db.DbContext.Player.SingleOrDefaultAsync(p => p.UserId == firstBan.Unban.UnbanningAdmin.Value); + bans.Add(new ServerRoleBanNote(firstBan.Id, firstBan.RoundId, firstBan.Round, firstBan.PlayerUserId, player, firstBan.PlaytimeAtNote, firstBan.Reason, firstBan.Severity, firstBan.CreatedBy, firstBan.BanTime, firstBan.LastEditedBy, firstBan.LastEditedAt, firstBan.ExpirationTime, - firstBan.Hidden, await banGroup.Select(ban => ban.RoleId.Replace(BanManager.JobPrefix, null)).ToArrayAsync(), + firstBan.Hidden, banGroup.Select(ban => ban.RoleId.Replace(BanManager.JobPrefix, null)).ToArray(), unbanningAdmin, firstBan.Unban?.UnbanTime)); } diff --git a/Tools/package_server_build.py b/Tools/package_server_build.py index 4c5c03d3e6..32a61722f6 100755 --- a/Tools/package_server_build.py +++ b/Tools/package_server_build.py @@ -71,7 +71,6 @@ SERVER_CONTENT_ASSEMBLIES = [ SERVER_EXTRA_ASSEMBLIES = [ "Npgsql.", "Microsoft", - "System.Linq.Async", ] SERVER_NOT_EXTRA_ASSEMBLIES = [