refactor(net): own live session routing
This commit is contained in:
parent
707e606e35
commit
961bdd07b7
12 changed files with 1645 additions and 543 deletions
|
|
@ -81,7 +81,8 @@ public static class GameEventWiring
|
|||
Action<IReadOnlyList<(uint Id, uint Amount)>>? onDesiredComponents = null,
|
||||
Action<uint /*options1*/, uint /*options2*/>? onCharacterOptions = null,
|
||||
Func<double>? clientTime = null,
|
||||
ExternalContainerState? externalContainers = null)
|
||||
ExternalContainerState? externalContainers = null,
|
||||
Func<bool>? accepting = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(dispatcher);
|
||||
ArgumentNullException.ThrowIfNull(items);
|
||||
|
|
@ -89,7 +90,7 @@ public static class GameEventWiring
|
|||
ArgumentNullException.ThrowIfNull(spellbook);
|
||||
ArgumentNullException.ThrowIfNull(chat);
|
||||
clientTime ??= static () => 0d;
|
||||
var registrar = new OwnedGameEventRegistrar(dispatcher);
|
||||
var registrar = new OwnedGameEventRegistrar(dispatcher, accepting);
|
||||
using var construction = new RegistrationBuildScope(registrar);
|
||||
|
||||
// ── Chat ──────────────────────────────────────────────────
|
||||
|
|
@ -659,14 +660,23 @@ public static class GameEventWiring
|
|||
}
|
||||
|
||||
private sealed class OwnedGameEventRegistrar(
|
||||
GameEventDispatcher dispatcher) : IDisposable
|
||||
GameEventDispatcher dispatcher,
|
||||
Func<bool>? accepting) : IDisposable
|
||||
{
|
||||
private readonly SubscriptionSet _subscriptions = new();
|
||||
|
||||
public void Register(
|
||||
GameEventType type,
|
||||
GameEventDispatcher.EventHandler handler) =>
|
||||
_subscriptions.Add(dispatcher.RegisterOwned(type, handler));
|
||||
GameEventDispatcher.EventHandler handler)
|
||||
{
|
||||
GameEventDispatcher.EventHandler registered = accepting is null
|
||||
? handler
|
||||
: envelope =>
|
||||
{
|
||||
if (accepting()) handler(envelope);
|
||||
};
|
||||
_subscriptions.Add(dispatcher.RegisterOwned(type, registered));
|
||||
}
|
||||
|
||||
public void Dispose() => _subscriptions.Dispose();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue