Five sub-changes:
1. Windows-1252 codec switch (global). Every Encoding.ASCII call site
in src/AcDream.Core.Net/Messages/ -> Encoding.GetEncoding(1252).
Touched HearSpeech, ChatRequests, GameEvents, AppraiseInfoParser,
CharacterList, CreateObject, PlayerDescriptionParser, SocialActions.
New Encodings.cs module-init registers CodePagesEncodingProvider
(System.Text.Encoding.CodePages ships with .NET 10 SDK but isn't
auto-registered). Matches retail + holtburger; accented names
no longer round-trip-broken.
2. New parsers (opcodes confirmed against holtburger opcodes.rs):
- EmoteText (0x01E0) { u32 senderGuid, string16 senderName, string16 text }
- SoulEmote (0x01E2) same wire layout as EmoteText
- ServerMessage (0xF7E0) { string16 message, u32 chatType }
- PlayerKilled (0x019E) { string16 deathMessage, u32 victimGuid, u32 killerGuid }
Shared StringReader.cs has the CP1252 String16L primitive.
3. WorldSession dispatch. ProcessDatagram adds branches for the four
new top-level opcodes + fires session-level events (EmoteHeard,
SoulEmoteHeard, ServerMessageReceived, PlayerKilledReceived).
0x0295 SetTurbineChatChannels stubbed with TODO for parallel I.6.
4. GameEventWiring routes WeenieError + WeenieErrorWithString
(parsers existed but were unrouted) -> chat.OnWeenieError.
5. ChatLog adapters: Emote / SoulEmote ChatKind values, OnEmote,
OnSoulEmote, OnPlayerKilled, OnWeenieError. OnLocalSpeech now
substitutes empty sender -> "You" per holtburger client/messages.rs.
ChatVM.FormatEntry handles new kinds (asterisk + sender + text).
22 new tests covering parser round-trips + reject-bad-opcode +
ChatLog adapter coverage + Win-1252 round-trip with non-ASCII chars.
Solution total: 881 green (210->225 in Core.Net.Tests, 606->613 in Core.Tests).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
using System.Text;
|
|
using AcDream.Core.Net.Messages;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Net.Tests.Messages;
|
|
|
|
/// <summary>
|
|
/// Phase I.5: 0x019E PlayerKilled parser. Wire layout per holtburger
|
|
/// PlayerKilledData: string16L deathMessage + u32 victimGuid + u32
|
|
/// killerGuid.
|
|
/// </summary>
|
|
public sealed class PlayerKilledTests
|
|
{
|
|
[Fact]
|
|
public void TryParse_RoundTrips_AllThreeFields()
|
|
{
|
|
// Synthetic payload mirroring holtburger's test_player_killed_fixture
|
|
// (combat/types.rs lines 100-115). Death message = "Test", victim =
|
|
// 0x12345678, killer = 0x90ABCDEF.
|
|
byte[] msg = PackString16L("Test");
|
|
byte[] body = new byte[4 + msg.Length + 8];
|
|
int pos = 0;
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(pos), PlayerKilled.Opcode); pos += 4;
|
|
Array.Copy(msg, 0, body, pos, msg.Length); pos += msg.Length;
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(pos), 0x12345678u); pos += 4;
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(pos), 0x90ABCDEFu);
|
|
|
|
var parsed = PlayerKilled.TryParse(body);
|
|
Assert.NotNull(parsed);
|
|
Assert.Equal("Test", parsed!.Value.DeathMessage);
|
|
Assert.Equal(0x12345678u, parsed.Value.VictimGuid);
|
|
Assert.Equal(0x90ABCDEFu, parsed.Value.KillerGuid);
|
|
}
|
|
|
|
[Fact]
|
|
public void TryParse_WrongOpcode_ReturnsNull()
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, 0xDEADBEEFu);
|
|
Assert.Null(PlayerKilled.TryParse(body));
|
|
}
|
|
|
|
[Fact]
|
|
public void TryParse_TruncatedAfterMessage_ReturnsNull()
|
|
{
|
|
byte[] msg = PackString16L("died");
|
|
byte[] body = new byte[4 + msg.Length + 4]; // only one guid present
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, PlayerKilled.Opcode);
|
|
Array.Copy(msg, 0, body, 4, msg.Length);
|
|
Assert.Null(PlayerKilled.TryParse(body));
|
|
}
|
|
|
|
private static byte[] PackString16L(string s)
|
|
{
|
|
byte[] data = Encoding.GetEncoding(1252).GetBytes(s);
|
|
int recordSize = 2 + data.Length;
|
|
int padding = (4 - (recordSize & 3)) & 3;
|
|
byte[] result = new byte[recordSize + padding];
|
|
BinaryPrimitives.WriteUInt16LittleEndian(result, (ushort)data.Length);
|
|
Array.Copy(data, 0, result, 2, data.Length);
|
|
return result;
|
|
}
|
|
}
|