refactor(net): own live session routing

This commit is contained in:
Erik 2026-07-21 11:17:09 +02:00
parent 707e606e35
commit 961bdd07b7
12 changed files with 1645 additions and 543 deletions

View file

@ -1,5 +1,6 @@
using System.Net;
using System.Reflection;
using System.Buffers.Binary;
using AcDream.Core.Chat;
using AcDream.Core.Combat;
using AcDream.Core.Items;
@ -115,6 +116,35 @@ public sealed class WorldSessionWiringOwnershipTests
Assert.Equal(baselineCount, session.GameEvents.RegisteredHandlerCount);
}
[Fact]
public void GameEventWiring_AcceptanceGateSilencesCopiedOrInFlightDispatch()
{
var dispatcher = new GameEventDispatcher();
var combat = new CombatState();
bool accepting = true;
using IDisposable registration = GameEventWiring.WireAll(
dispatcher,
new ClientObjectTable(),
combat,
new Spellbook(),
new ChatLog(),
accepting: () => accepting);
byte[] first = new byte[8];
BinaryPrimitives.WriteUInt32LittleEndian(first, 0x50000001u);
BinaryPrimitives.WriteSingleLittleEndian(first.AsSpan(4), 0.75f);
byte[] stale = new byte[8];
BinaryPrimitives.WriteUInt32LittleEndian(stale, 0x50000001u);
BinaryPrimitives.WriteSingleLittleEndian(stale.AsSpan(4), 0.25f);
dispatcher.Dispatch(new GameEventEnvelope(
0u, 0u, GameEventType.UpdateHealth, first));
accepting = false;
dispatcher.Dispatch(new GameEventEnvelope(
0u, 0u, GameEventType.UpdateHealth, stale));
Assert.Equal(0.75f, combat.GetHealthPercent(0x50000001u));
}
private static WorldSession NewSession() =>
new(new IPEndPoint(IPAddress.Loopback, 9));