fix: Fixes DeltaQueue recursion, StatMod bug, and memory leak (#1233)
* Fixes recursion with DeltaQueue causing multiple sets of packets to be sent to the client. * Fixes StatMods that are expired not being checked properly. * Adds a timer to properly expire/remove stat mods instead of relying on a side-effect.
This commit is contained in:
parent
d7d914df6c
commit
59dcd24bed
3 changed files with 61 additions and 26 deletions
|
|
@ -33,6 +33,11 @@ public partial class StatMod : MobileMod
|
|||
[SerializableField(3, setter: "private")]
|
||||
private int _offset;
|
||||
|
||||
// Added a timer and removed the processing of expirations in GetStatOffset which caused recursions in DeltaQueue
|
||||
// ProcessDeltaQueue -> Dequeue -> ProcessDelta -> SendStats packet -> get_HitsMax ->
|
||||
// - GetStatOffset -> Delta -> Queue to DeltaQueue
|
||||
private TimerExecutionToken _timerToken;
|
||||
|
||||
public StatMod(Mobile owner) : base(owner)
|
||||
{
|
||||
}
|
||||
|
|
@ -43,7 +48,26 @@ public partial class StatMod : MobileMod
|
|||
_offset = offset;
|
||||
_duration = duration;
|
||||
_added = Core.Now;
|
||||
|
||||
if (_duration > TimeSpan.Zero)
|
||||
{
|
||||
Timer.StartTimer(duration, RemoveFromOwner, out _timerToken);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasElapsed() => _duration != TimeSpan.Zero && Core.Now - _added >= _duration;
|
||||
public bool HasElapsed() => _duration > TimeSpan.Zero && Core.Now - _added >= _duration;
|
||||
|
||||
[AfterDeserialization]
|
||||
private void AfterDeserialization()
|
||||
{
|
||||
if (_duration > TimeSpan.Zero && Core.Now - _added < _duration)
|
||||
{
|
||||
Timer.StartTimer(_duration, RemoveFromOwner, out _timerToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveFromOwner() => Owner?.RemoveStatMod(this);
|
||||
|
||||
// Called by Mobile.RemoveStatMod()
|
||||
public void Remove() => _timerToken.Cancel();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue