fix: Fixes infinite loop in bulletin board cleanup (#1394)

This commit is contained in:
Kamron Batman 2023-04-18 19:27:40 -07:00 • committed by GitHub
parent 5b3ff89e70
commit 6c09e5a006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 16 deletions

View file

@ -58,9 +58,10 @@ namespace Server.Items
} }
[AfterDeserialization(false)] [AfterDeserialization(false)]
public virtual void Cleanup() public void Cleanup()
{ {
var items = Items; var items = Items;
var queue = PooledRefQueue<Item>.Create();
for (var i = items.Count - 1; i >= 0; --i) for (var i = items.Count - 1; i >= 0; --i)
{ {
@ -74,29 +75,28 @@ namespace Server.Items
continue; continue;
} }
// Top level thread expired
if (msg.Thread == null && BulletinBoardSystem.CheckDeletionTime(msg.LastPostTime)) if (msg.Thread == null && BulletinBoardSystem.CheckDeletionTime(msg.LastPostTime))
{ {
msg.Delete(); queue.Enqueue(msg);
var queue = PooledRefQueue<Item>.Create();
var thread = msg;
do
{
BFSDelete(thread, ref queue);
if (queue.Count > 0)
{
thread = (BulletinMessage)queue.Dequeue();
}
} while (thread != null);
queue.Dispose();
} }
} }
while (queue.Count > 0)
{
var msg = (BulletinMessage)queue.Dequeue();
RecurseDelete(msg, ref queue);
msg.Delete();
}
queue.Dispose();
} }
private void BFSDelete(BulletinMessage msg, ref PooledRefQueue<Item> queue) private void RecurseDelete(BulletinMessage msg, ref PooledRefQueue<Item> queue)
{ {
var items = Items; 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) for (var i = items.Count - 1; i >= 0; --i)
{ {
if (i >= items.Count) if (i >= items.Count)
@ -111,7 +111,6 @@ namespace Server.Items
if (check.Thread == msg) if (check.Thread == msg)
{ {
check.Delete();
queue.Enqueue(check); queue.Enqueue(check);
} }
} }

View file

@ -38,21 +38,26 @@ namespace Server.Items
} }
[SerializableField(0)] [SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)]
private Mobile _poster; private Mobile _poster;
[SerializableField(1)] [SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)]
private string _subject; private string _subject;
[SerializableField(2)] [SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)]
private DateTime _time; private DateTime _time;
[SerializableField(3)] [SerializableField(3)]
private DateTime _lastPostTime; private DateTime _lastPostTime;
[SerializableField(4)] [SerializableField(4)]
[SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)]
private BulletinMessage _thread; private BulletinMessage _thread;
[SerializableField(5)] [SerializableField(5)]
[SerializedCommandProperty(AccessLevel.GameMaster, readOnly: true)]
private string _postedName; private string _postedName;
[SerializableField(6)] [SerializableField(6)]