acdream/tests/AcDream.Core.Net.Tests/WorldSessionChatTests.cs
Erik f6fe0f2a4f
All checks were successful
CI / linux-portable (push) Successful in 3m27s
CI / windows-gate (push) Successful in 6m42s
CI / release (push) Successful in 2m12s
fix(client): restore retail interaction parity
Harden keyboard and camera routing, inventory and vendor interactions, chat/emotes, relog portal flow, and paperdoll rendering. Add retail research, connected gate coverage, and release-gate validation.
2026-08-26 20:45:11 +02:00

117 lines
3.8 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!));
}
[Fact]
public void SendSoulEmote_EmitsRetailGameAction()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendSoulEmote("waves.");
Assert.Equal(ClientCommandRequests.BuildSoulEmote(1u, "waves."), captured);
}
[Fact]
public void SendTeleportToLifestone_EmitsRetailGameAction()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendTeleportToLifestone();
Assert.NotNull(captured);
Assert.Equal(InteractRequests.BuildTeleToLifestone(1), captured);
}
[Fact]
public void SendEnterPkLite_EmitsRetailGameAction()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendEnterPkLite();
Assert.NotNull(captured);
Assert.Equal(ClientCommandRequests.BuildEnterPkLite(1), captured);
}
}