From 6c09e5a006e84612e6122c77316c0a02aa1dd02e Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:27:40 -0700 Subject: [PATCH] fix: Fixes infinite loop in bulletin board cleanup (#1394) --- .../Items/Bulletin Boards/BulletinBoard.cs | 31 +++++++++---------- .../Items/Bulletin Boards/BulletinMessage.cs | 5 +++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Projects/UOContent/Items/Bulletin Boards/BulletinBoard.cs b/Projects/UOContent/Items/Bulletin Boards/BulletinBoard.cs index db23d67ba..d8d785445 100644 --- a/Projects/UOContent/Items/Bulletin Boards/BulletinBoard.cs +++ b/Projects/UOContent/Items/Bulletin Boards/BulletinBoard.cs @@ -58,9 +58,10 @@ namespace Server.Items } [AfterDeserialization(false)] - public virtual void Cleanup() + public void Cleanup() { var items = Items; + var queue = PooledRefQueue.Create(); for (var i = items.Count - 1; i >= 0; --i) { @@ -74,29 +75,28 @@ namespace Server.Items continue; } + // Top level thread expired if (msg.Thread == null && BulletinBoardSystem.CheckDeletionTime(msg.LastPostTime)) { - msg.Delete(); - var queue = PooledRefQueue.Create(); - var thread = msg; - - do - { - BFSDelete(thread, ref queue); - if (queue.Count > 0) - { - thread = (BulletinMessage)queue.Dequeue(); - } - } while (thread != null); - queue.Dispose(); + queue.Enqueue(msg); } } + + while (queue.Count > 0) + { + var msg = (BulletinMessage)queue.Dequeue(); + RecurseDelete(msg, ref queue); + msg.Delete(); + } + + queue.Dispose(); } - private void BFSDelete(BulletinMessage msg, ref PooledRefQueue queue) + private void RecurseDelete(BulletinMessage msg, ref PooledRefQueue queue) { var items = Items; + // All messages and sub-threads are also in the same bulletin board container for (var i = items.Count - 1; i >= 0; --i) { if (i >= items.Count) @@ -111,7 +111,6 @@ namespace Server.Items if (check.Thread == msg) { - check.Delete(); queue.Enqueue(check); } } diff --git a/Projects/UOContent/Items/Bulletin Boards/BulletinMessage.cs b/Projects/UOContent/Items/Bulletin Boards/BulletinMessage.cs index cfc3b2024..2e4500d10 100644 --- a/Projects/UOContent/Items/Bulletin Boards/BulletinMessage.cs +++ b/Projects/UOContent/Items/Bulletin Boards/BulletinMessage.cs @@ -38,21 +38,26 @@ namespace Server.Items } [SerializableField(0)] + [SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)] private Mobile _poster; [SerializableField(1)] + [SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)] private string _subject; [SerializableField(2)] + [SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)] private DateTime _time; [SerializableField(3)] private DateTime _lastPostTime; [SerializableField(4)] + [SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)] private BulletinMessage _thread; [SerializableField(5)] + [SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)] private string _postedName; [SerializableField(6)]