Replaces NullCommandBus.Instance in PanelContext with a real LiveCommandBus when a live session is active. Panels publish SendChatCmd; the host routes it to the right wire opcode + emits a ChatLog.OnSelfSent local echo (optimistic; retail-equivalent for Talk). Pieces: - ChatChannelKind enum (UI.Abstractions) - mirrors holtburger's ChatChannelKind (references/holtburger/.../client/types.rs:35-49). - SendChatCmd record (UI.Abstractions) - (Channel, TargetName?, Text). - LiveCommandBus (UI.Abstractions) - single-handler-per-type; Register<T> throws on double-register; Publish<T> logs missing handler but does not throw. - ChannelResolver (UI.Abstractions) - port of holtburger's resolve_legacy_channel (client/commands.rs:50-62) mapping ChatChannelKind to legacy ChatChannel ids verbatim from holtburger-protocol/.../chat/types.rs:8-24 (Fellow=0x0800, AllegianceBroadcast=0x02000000, Vassals=0x1000, Patron=0x2000, Monarch=0x4000, CoVassals=0x01000000). - WorldSession.SendTalk / SendTell / SendChannel - 3-line wrappers around existing ChatRequests.Build* + SendGameAction. Internal GameActionCapture seam + InternalsVisibleTo for tests. - GameWindow registers SendChatCmd handler: Say -> SendTalk + ChatLog echo, Tell -> SendTell + echo, channel kinds -> ChannelResolver.Resolve -> SendChannel + echo. 12 new tests across SendChatCmd + LiveCommandBus + ChannelResolver + WorldSessionChat. NullCommandBus.Instance retained for back-compat when no live session. Solution total: 893 green (51 + 229 + 613). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using System.Net;
|
|
using AcDream.Core.Net;
|
|
using AcDream.Core.Net.Messages;
|
|
|
|
namespace AcDream.Core.Net.Tests;
|
|
|
|
/// <summary>
|
|
/// Phase I.3 — verifies that <see cref="WorldSession.SendTalk"/>,
|
|
/// <see cref="WorldSession.SendTell"/>, and <see cref="WorldSession.SendChannel"/>
|
|
/// produce the same wire bytes that <see cref="ChatRequests"/> builders do,
|
|
/// using a sequence number drawn from <see cref="WorldSession.NextGameActionSequence"/>.
|
|
///
|
|
/// <para>
|
|
/// Uses the internal <c>GameActionCapture</c> test seam to intercept the
|
|
/// game-action body before it hits the (unseeded) ISAAC-encrypted wire path.
|
|
/// </para>
|
|
/// </summary>
|
|
public sealed class WorldSessionChatTests
|
|
{
|
|
private static WorldSession NewSession()
|
|
{
|
|
// Bind to a throwaway loopback endpoint; we never actually
|
|
// exchange packets — the capture hook intercepts the body.
|
|
var ep = new IPEndPoint(IPAddress.Loopback, 65000);
|
|
return new WorldSession(ep);
|
|
}
|
|
|
|
[Fact]
|
|
public void SendTalk_EmitsBytesIdenticalToChatRequestsBuildTalk()
|
|
{
|
|
using var session = NewSession();
|
|
byte[]? captured = null;
|
|
session.GameActionCapture = body => captured = body;
|
|
|
|
session.SendTalk("hello");
|
|
|
|
// After SendTalk, the sequence counter has been incremented to 1.
|
|
// ChatRequests.BuildTalk(seq=1, "hello") should match exactly.
|
|
byte[] expected = ChatRequests.BuildTalk(1, "hello");
|
|
Assert.NotNull(captured);
|
|
Assert.Equal(expected, captured);
|
|
}
|
|
|
|
[Fact]
|
|
public void SendTell_EmitsBytesIdenticalToChatRequestsBuildTell()
|
|
{
|
|
using var session = NewSession();
|
|
byte[]? captured = null;
|
|
session.GameActionCapture = body => captured = body;
|
|
|
|
session.SendTell("Alice", "hey");
|
|
|
|
byte[] expected = ChatRequests.BuildTell(1, "Alice", "hey");
|
|
Assert.NotNull(captured);
|
|
Assert.Equal(expected, captured);
|
|
}
|
|
|
|
[Fact]
|
|
public void SendChannel_IncrementsSequence_AndMatchesBuildChatChannel()
|
|
{
|
|
using var session = NewSession();
|
|
var captured = new System.Collections.Generic.List<byte[]>();
|
|
session.GameActionCapture = body => captured.Add(body);
|
|
|
|
session.SendChannel(channelId: 0x00000800u, "raid plan");
|
|
session.SendChannel(channelId: 0x02000000u, "allegiance ping");
|
|
|
|
Assert.Equal(2, captured.Count);
|
|
Assert.Equal(ChatRequests.BuildChatChannel(1, 0x00000800u, "raid plan"), captured[0]);
|
|
Assert.Equal(ChatRequests.BuildChatChannel(2, 0x02000000u, "allegiance ping"), captured[1]);
|
|
}
|
|
|
|
[Fact]
|
|
public void SendTalk_NullText_Throws()
|
|
{
|
|
using var session = NewSession();
|
|
Assert.Throws<ArgumentNullException>(() => session.SendTalk(null!));
|
|
}
|
|
}
|