acdream/tests/AcDream.Core.Net.Tests/WorldSessionChatTests.cs
Erik 69ba9486b6 feat(chat): port retail's @pklite client command (EnterPkLite 0x028F)
acdream never implemented @pklite. It is a CLIENT command in retail, not a
server one — ACE has no pklite text-command handler — so typing it forwarded as
inert chat text that the server ignored.

Retail: ClientCommunicationSystem::DoPKLite @0x0057A490 rejects with
WeenieError 0x507 when ACCWeenieObject::IsPlayerKiller @0x0058C910 is true
(that returns true when EITHER the PK bit 0x20 OR the PKLite bit 0x2000000 is
set), prints "Please see @help pklite for more..." and sends nothing if given
any argument text, and otherwise calls CM_Character::Event_EnterPKLite
@0x006A13F0 — a bare 12-byte parameterless game action, opcode 0x28F, the same
shape as Event_LoginCompleteNotification beside it. Verb string at 0x007E16B0,
help text at 0x007DF0C8, failure string at 0x007D31E8; one verb, no alias.

HasPlayerFlag is a tri-state (null = the local PublicWeenieDesc has not
arrived). The existing arena gates compare `== false` because they reject on a
known-FALSE flag; retail's DoPKLite gates the other way, rejecting on
known-TRUE. So this case compares `== true` on either bit: an indeterminate
description sends rather than blocks, which matches retail trusting the server
instead of inventing a client-side suppression rule.

Landed as its own commit because it is retail-faithful on its own merits, but
the motivation is C4 route 2: ACE advances SequenceType.ObjectForcePosition in
exactly two places, and the only reachable one is Player.HandleActionEnterPkLite's
entry-collision bump (allow_pkl_bump, default on). Every admin teleport advances
ObjectTeleport instead, so @teleto-style displacement exercises route 3, not
route 2. Without this command route 2 has no connected acceptance gate at all.

Gates: complete Release solution 10,867 passed / 4 skipped / 0 failed
(9966b531 baseline 10,858/4/0; +9 = the 9 tests added). Coverage includes both
known-true rejections, the known-false success case, the tri-state unknown
case, the 12-byte wire envelope, and @pklite resolving as ClientHandled rather
than falling through to the server-text path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-03 18:57:17 +02:00

105 lines
3.4 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 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);
}
}