Wire (Core.Net):
- CharacterCreate.cs: outbound 0xF656 builder, byte-exact port of
Proto_UI::SendCharGenResult@0x00546a70 -> ACCharGenResult::Pack@0x005c7570
-> CG_Pack@0x005c7200. Account String16L first (packed outside CG_Pack),
then the constant-1 u32, heritage/gender, 14 appearance strip/style/color
u32s, 6 f64 shades (skin/hair/headgear/shirt/trousers/footwear, retail
order), template, 6 attributes, slot, classId, numSkills + exactly 55
u32 skill-advancement classes (ReadOnlySpan validated ==55, throws
ArgumentException otherwise — ACE terminates the session on any other
count via PlayerFactory.CreateResult.ClientServerSkillsMismatch), name
String16L, startArea, isAdmin, isEnvoy, and a trailing checksum whose
exact 19-term accumulation set (heritage+gender+3 strips+hairColor+
eyeColor+hairStyle+headgearStyle+shirtStyle+trousersStyle+footwearStyle+
template+6 attributes) is read byte-for-byte off CG_Pack's decompiled
accumulator (0x005c7213-0x005c74c3) — headgearColor/shirtColor/
trousersColor/footwearColor/shades/slot/classId are deliberately absent
from the sum despite sitting adjacent on the wire. Cross-checked against
ACE's CharacterCreateInfo.Unpack/Appearance.Unpack and holtburger's
CharacterCreateRequestData (types.rs:236-369), which agree on every
field and order. Retail routes via SendToLogon — the same queue
CharacterDelete already uses.
- CharGenVerificationResponse.cs (new): promotes the shared 0xF643 parse
out of CharacterRestore — full Code enum (Undef..AdminPrivilegeDenied=7,
ACE's CharacterGenerationVerificationResponse) plus the conditional
Ok-only identity payload (guid/String16L name/u32 secondsGreyedOut).
CharacterRestore.Parse now delegates to it; CharacterRestore's public
Parsed shape, Parse signature, and every existing test expectation are
UNCHANGED.
- PacketWriter.WriteDouble: f64 little-endian helper for the shade fields.
WorldSession dispatch (Core.Net):
- Added an awaiting-request latch (None/Restore/Create), armed by
SendRestoreCharacter/the new SendCharacterCreation immediately before
each send (SendCharacterCreation builds the body first so a skill-count
throw never arms the latch for a request that was never sent), cleared
the instant a matching 0xF643 is dispatched (success OR parse failure —
a malformed reply must never wedge the latch open) and on Dispose.
0xF643 now routes to CharacterRestoreReceived or the new
CharacterCreateResponseReceived (Action<CharGenVerificationResponse.Parsed>)
by that latch; an unexpected 0xF643 with nothing outstanding logs once
and is dropped, never misattributed. Fixed
WorldSessionCharacterSelectionTests' restore-dispatch test, which
previously fed a bare CharacterRestore response with no preceding
SendRestoreCharacter — that shape is now the "no outstanding request"
drop path by design.
Status events (Runtime + Launcher.Core, contract first):
- Amended docs/plans/2026-08-14-launcher-campaign.md §LA1's pinned status
vocabulary to add characterCreated{guid,name} (Ok reply identity, named
to mirror CharGenVerificationResponse's own fields and to read distinct
from enteredWorld — retail logs a freshly created character straight in
without a fresh characterList) and creationFailed{code,name} (raw Code
value + its enum member name).
- SessionStatusWriter.CharacterCreated/CreationFailed implement that
contract.
- Launcher.Core: CharacterCreatedStatusEvent/CreationFailedStatusEvent +
StatusEventParser cases, in lockstep.
Tests: CharacterCreateTests (byte-exact layout incl. checksum term-set,
55-slot fixture, wrong-count throws), CharGenVerificationResponseTests
(every Code value), WorldSessionCharacterCreationTests (create-then-
response routes correctly, restore unaffected, no-outstanding drop,
second-response-after-consumed drop, Dispose clears the latch, a builder
throw never arms it), SessionStatusWriterTests + Launcher.Core
StatusEventParserTests/StatusFileTailerTests (pinned shape + tailer
round-trip) for the two new events.
Verified: dotnet build AcDream.slnx -c Release — 0 errors. Full solution
test run green (Core.Net.Tests 993/993, Runtime.Tests 1667/1667,
Launcher.Core.Tests 323/323, plus every other project in the solution).
WSL Ubuntu: Core.Net.Tests 993/993, Runtime.Tests 1667/1667.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
265 lines
11 KiB
C#
265 lines
11 KiB
C#
using AcDream.Launcher.Core.Status;
|
|
|
|
namespace AcDream.Launcher.Core.Tests.Status;
|
|
|
|
public sealed class StatusEventParserTests
|
|
{
|
|
[Fact]
|
|
public void ParsesStarted()
|
|
{
|
|
var e = StatusEventParser.Parse(
|
|
"""{"v":1,"e":"started","t":"2026-08-14T12:00:00Z","sessionId":"s1"}""");
|
|
|
|
var started = Assert.IsType<StartedStatusEvent>(e);
|
|
Assert.Equal(1, started.V);
|
|
Assert.Equal("started", started.E);
|
|
Assert.Equal("s1", started.SessionId);
|
|
Assert.Equal(
|
|
DateTimeOffset.Parse("2026-08-14T12:00:00Z"),
|
|
started.T);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesConnected()
|
|
{
|
|
var e = StatusEventParser.Parse(
|
|
"""{"v":1,"e":"connected","t":"2026-08-14T12:00:01Z","sessionId":"s1"}""");
|
|
Assert.IsType<ConnectedStatusEvent>(e);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesCharacterListWithMultipleCharacters()
|
|
{
|
|
var e = StatusEventParser.Parse(
|
|
"""
|
|
{"v":1,"e":"characterList","t":"2026-08-14T12:00:02Z","sessionId":"s1",
|
|
"accountName":"testaccount","slotCount":6,
|
|
"characters":[
|
|
{"id":1342177290,"name":"+Acdream","secondsGreyedOut":0},
|
|
{"id":1342177291,"name":"+Second","secondsGreyedOut":1}
|
|
]}
|
|
""");
|
|
|
|
var list = Assert.IsType<CharacterListStatusEvent>(e);
|
|
Assert.Equal("testaccount", list.AccountName);
|
|
Assert.Equal(6, list.SlotCount);
|
|
Assert.Equal(2, list.Characters.Count);
|
|
Assert.Equal(1342177290u, list.Characters[0].Id);
|
|
Assert.Equal("+Acdream", list.Characters[0].Name);
|
|
Assert.Equal(0u, list.Characters[0].SecondsGreyedOut);
|
|
Assert.Equal(1342177291u, list.Characters[1].Id);
|
|
Assert.Equal(1u, list.Characters[1].SecondsGreyedOut);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesEnteredWorld()
|
|
{
|
|
var e = StatusEventParser.Parse(
|
|
"""{"v":1,"e":"enteredWorld","t":"2026-08-14T12:00:03Z","sessionId":"s1","characterId":1342177290,"characterName":"+Acdream"}""");
|
|
|
|
var entered = Assert.IsType<EnteredWorldStatusEvent>(e);
|
|
Assert.Equal(1342177290u, entered.CharacterId);
|
|
Assert.Equal("+Acdream", entered.CharacterName);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesPluginLoadedAndPluginFailed()
|
|
{
|
|
var loaded = Assert.IsType<PluginLoadedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"pluginLoaded","t":"2026-08-14T12:00:04Z","sessionId":"s1","plugin":"ExamplePlugin"}"""));
|
|
Assert.Equal("ExamplePlugin", loaded.Plugin);
|
|
|
|
var failed = Assert.IsType<PluginFailedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"pluginFailed","t":"2026-08-14T12:00:05Z","sessionId":"s1","plugin":"BadPlugin","error":"boom"}"""));
|
|
Assert.Equal("BadPlugin", failed.Plugin);
|
|
Assert.Equal("boom", failed.Error);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesCharacterCreatedAndCreationFailed()
|
|
{
|
|
var created = Assert.IsType<CharacterCreatedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"characterCreated","t":"2026-08-15T12:00:00Z","sessionId":"s1","guid":1342177296,"name":"NewChar"}"""));
|
|
Assert.Equal(1342177296u, created.Guid);
|
|
Assert.Equal("NewChar", created.Name);
|
|
|
|
var failed = Assert.IsType<CreationFailedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"creationFailed","t":"2026-08-15T12:00:01Z","sessionId":"s1","code":3,"name":"NameInUse"}"""));
|
|
Assert.Equal(3u, failed.Code);
|
|
Assert.Equal("NameInUse", failed.Name);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("{\"v\":1,\"e\":\"characterCreated\",\"t\":\"2026-08-15T12:00:00Z\",\"sessionId\":\"s1\",\"name\":\"NewChar\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"characterCreated\",\"t\":\"2026-08-15T12:00:00Z\",\"sessionId\":\"s1\",\"guid\":1342177296}")]
|
|
[InlineData("{\"v\":1,\"e\":\"creationFailed\",\"t\":\"2026-08-15T12:00:00Z\",\"sessionId\":\"s1\",\"name\":\"NameInUse\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"creationFailed\",\"t\":\"2026-08-15T12:00:00Z\",\"sessionId\":\"s1\",\"code\":3}")]
|
|
public void MalformedCharacterCreationEventsUseTheKnownEventFailurePath(string line)
|
|
{
|
|
var malformed = Assert.IsType<MalformedStatusEvent>(StatusEventParser.Parse(line));
|
|
|
|
Assert.Equal("s1", malformed.SessionId);
|
|
Assert.False(string.IsNullOrWhiteSpace(malformed.Error));
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesLoginCommandFailed()
|
|
{
|
|
var failed = Assert.IsType<LoginCommandFailedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"loginCommandFailed","t":"2026-08-14T12:00:05Z","sessionId":"s1","commandIndex":2,"command":"/version","error":"unsupported headless command"}"""));
|
|
|
|
Assert.Equal(2, failed.CommandIndex);
|
|
Assert.Equal("/version", failed.Command);
|
|
Assert.Equal("unsupported headless command", failed.Error);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("{\"v\":1,\"e\":\"loginCommandFailed\",\"t\":\"2026-08-14T12:00:05Z\",\"sessionId\":\"s1\",\"commandIndex\":-1,\"command\":\"/version\",\"error\":\"unsupported\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"loginCommandFailed\",\"t\":\"2026-08-14T12:00:05Z\",\"sessionId\":\"s1\",\"commandIndex\":0,\"error\":\"unsupported\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"loginCommandFailed\",\"t\":\"2026-08-14T12:00:05Z\",\"sessionId\":\"s1\",\"commandIndex\":0,\"command\":\"/version\"}")]
|
|
public void MalformedLoginCommandFailureUsesTheKnownEventFailurePath(string line)
|
|
{
|
|
var malformed = Assert.IsType<MalformedStatusEvent>(
|
|
StatusEventParser.Parse(line));
|
|
|
|
Assert.Equal("loginCommandFailed", malformed.E);
|
|
Assert.Equal("s1", malformed.SessionId);
|
|
Assert.False(string.IsNullOrWhiteSpace(malformed.Error));
|
|
}
|
|
|
|
[Fact]
|
|
public void ParsesDisconnectedAndExited()
|
|
{
|
|
var disconnected = Assert.IsType<DisconnectedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"disconnected","t":"2026-08-14T12:00:06Z","sessionId":"s1","reason":"serverClosed"}"""));
|
|
Assert.Equal("serverClosed", disconnected.Reason);
|
|
|
|
var exited = Assert.IsType<ExitedStatusEvent>(
|
|
StatusEventParser.Parse(
|
|
"""{"v":1,"e":"exited","t":"2026-08-14T12:00:07Z","sessionId":"s1","code":0,"reason":"graceful"}"""));
|
|
Assert.Equal(0, exited.Code);
|
|
Assert.Equal("graceful", exited.Reason);
|
|
}
|
|
|
|
[Fact]
|
|
public void UnknownEValueSurfacesAsUnknownEventRatherThanThrowing()
|
|
{
|
|
var e = StatusEventParser.Parse(
|
|
"""{"v":1,"e":"someFutureEvent","t":"2026-08-14T12:00:08Z","sessionId":"s1","extra":true}""");
|
|
|
|
var unknown = Assert.IsType<UnknownStatusEvent>(e);
|
|
Assert.Equal("someFutureEvent", unknown.E);
|
|
Assert.Equal("s1", unknown.SessionId);
|
|
Assert.Contains("someFutureEvent", unknown.RawJson);
|
|
}
|
|
|
|
[Fact]
|
|
public void MalformedJsonSurfacesAsUnknownEventRatherThanThrowing()
|
|
{
|
|
var e = StatusEventParser.Parse("{not json");
|
|
|
|
Assert.IsType<UnknownStatusEvent>(e);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("[]")]
|
|
[InlineData("null")]
|
|
[InlineData("42")]
|
|
[InlineData("\"text\"")]
|
|
public void CompleteJsonWithANonObjectRootSurfacesAsMalformedEvent(string line)
|
|
{
|
|
var e = StatusEventParser.Parse(line);
|
|
|
|
var malformed = Assert.IsType<MalformedStatusEvent>(e);
|
|
Assert.Contains("root", malformed.Error, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
[InlineData("\t")]
|
|
public void WhitespaceOrEmptyLineSurfacesAsUnknownEventRatherThanThrowing(string line)
|
|
{
|
|
// Review finding F7: ArgumentException.ThrowIfNullOrWhiteSpace
|
|
// used to guard this method BEFORE the try/catch, so a
|
|
// whitespace-only line (e.g. a stray blank line the tailer
|
|
// happens to hand over) escaped as an uncaught exception instead
|
|
// of degrading like every other malformed-input case.
|
|
var e = StatusEventParser.Parse(line);
|
|
|
|
Assert.IsType<UnknownStatusEvent>(e);
|
|
}
|
|
|
|
[Fact]
|
|
public void NullLineSurfacesAsUnknownEventRatherThanThrowing()
|
|
{
|
|
var e = StatusEventParser.Parse(null!);
|
|
|
|
Assert.IsType<UnknownStatusEvent>(e);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("{\"e\":\"started\",\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":\"1\",\"e\":\"connected\",\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":2,\"e\":\"started\",\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"connected\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"started\",\"t\":42,\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"connected\",\"t\":\"not-a-time\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"started\",\"t\":\"2026-08-14T12:00:00+02:00\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"connected\",\"t\":\"2026-08-14T12:00:00Z\"}")]
|
|
[InlineData("{\"v\":1,\"e\":\"started\",\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":42}")]
|
|
[InlineData("{\"v\":1,\"e\":\"connected\",\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":\"\"}")]
|
|
public void PayloadFreeKnownEventsRequireTheFullPinnedV1Envelope(string line)
|
|
{
|
|
var e = StatusEventParser.Parse(line);
|
|
|
|
var malformed = Assert.IsType<MalformedStatusEvent>(e);
|
|
Assert.False(string.IsNullOrWhiteSpace(malformed.Error));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("{\"v\":1,\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":\"s1\"}")]
|
|
[InlineData("{\"v\":1,\"e\":42,\"t\":\"2026-08-14T12:00:00Z\",\"sessionId\":\"s1\"}")]
|
|
public void MissingOrWrongKindEventNameSurfacesAsMalformedEvent(string line)
|
|
{
|
|
Assert.IsType<MalformedStatusEvent>(StatusEventParser.Parse(line));
|
|
}
|
|
|
|
[Fact]
|
|
public void KnownEValueWithMissingRequiredFieldSurfacesAsMalformedEventRatherThanThrowing()
|
|
{
|
|
// characterList without "characters" — a shape mismatch on a
|
|
// KNOWN event name. Review finding F12: this must be
|
|
// distinguishable from an unrecognized e value, so it now
|
|
// surfaces as MalformedStatusEvent rather than UnknownStatusEvent.
|
|
var e = StatusEventParser.Parse(
|
|
"""{"v":1,"e":"characterList","t":"2026-08-14T12:00:09Z","sessionId":"s1","accountName":"a","slotCount":6}""");
|
|
|
|
var malformed = Assert.IsType<MalformedStatusEvent>(e);
|
|
Assert.Equal("characterList", malformed.E);
|
|
Assert.Equal("s1", malformed.SessionId);
|
|
Assert.False(string.IsNullOrWhiteSpace(malformed.Error));
|
|
}
|
|
|
|
[Fact]
|
|
public void KnownEValueWithAFieldOfTheWrongJsonKindSurfacesAsMalformedEvent()
|
|
{
|
|
// "characters" present but not an array — this throws
|
|
// InvalidOperationException out of JsonElement.EnumerateArray()
|
|
// rather than the FormatException a missing/wrong-kind scalar
|
|
// field throws, so it exercises the parser's other malformed-
|
|
// payload catch path.
|
|
var e = StatusEventParser.Parse(
|
|
"""{"v":1,"e":"characterList","t":"2026-08-14T12:00:10Z","sessionId":"s1","accountName":"a","slotCount":6,"characters":"not-an-array"}""");
|
|
|
|
var malformed = Assert.IsType<MalformedStatusEvent>(e);
|
|
Assert.Equal("characterList", malformed.E);
|
|
Assert.False(string.IsNullOrWhiteSpace(malformed.Error));
|
|
}
|
|
}
|