refactor(net): own session wiring subscriptions

This commit is contained in:
Erik 2026-07-21 10:45:15 +02:00
parent 88fe1db37b
commit 7d452aa6a2
8 changed files with 577 additions and 61 deletions

View file

@ -12,13 +12,15 @@ public static class CombatStateWiring
{
public const uint CombatModePropertyId = 40u;
public static void Wire(WorldSession session, CombatState combat)
public static IDisposable Wire(WorldSession session, CombatState combat)
{
ArgumentNullException.ThrowIfNull(session);
ArgumentNullException.ThrowIfNull(combat);
session.PlayerIntPropertyUpdated += update =>
Action<WorldSession.PlayerIntPropertyUpdate> handler = update =>
ApplyPlayerIntProperty(combat, update.Property, update.Value);
session.PlayerIntPropertyUpdated += handler;
return new EventSubscription(session, handler);
}
/// <summary>
@ -44,4 +46,15 @@ public static class CombatStateWiring
combat.SetCombatMode(mode);
return true;
}
private sealed class EventSubscription(
WorldSession session,
Action<WorldSession.PlayerIntPropertyUpdate> handler) : IDisposable
{
private Action? _unsubscribe =
() => session.PlayerIntPropertyUpdated -= handler;
public void Dispose() =>
Interlocked.Exchange(ref _unsubscribe, null)?.Invoke();
}
}