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>
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
|
|
namespace AcDream.Core.Net.Messages;
|
|
|
|
/// <summary>
|
|
/// Inbound <c>0xF7E0 ServerMessage</c> top-level GameMessage.
|
|
/// General-purpose server-broadcast text — admin announcements,
|
|
/// combat logs, and routine error messages routed by the server
|
|
/// instead of via WeenieError.
|
|
///
|
|
/// <para>
|
|
/// This is a standalone GameMessage — NOT wrapped in 0xF7B0
|
|
/// GameEvent envelope. Dispatched directly from
|
|
/// <see cref="WorldSession.ProcessDatagram"/>.
|
|
/// </para>
|
|
///
|
|
/// <para>
|
|
/// Wire layout (port from holtburger
|
|
/// <c>references/holtburger/.../messages/chat/types.rs::ServerMessageData</c>,
|
|
/// see also opcodes.rs:167):
|
|
/// <code>
|
|
/// u32 opcode // 0xF7E0
|
|
/// string16L message
|
|
/// u32 chatType // ChatMessageType (Broadcast / System / etc)
|
|
/// </code>
|
|
/// </para>
|
|
/// </summary>
|
|
public static class ServerMessage
|
|
{
|
|
public const uint Opcode = 0xF7E0u;
|
|
|
|
public readonly record struct Parsed(string Message, uint ChatType);
|
|
|
|
public static Parsed? TryParse(byte[] body)
|
|
{
|
|
if (body is null || body.Length < 8) return null;
|
|
uint opcode = BinaryPrimitives.ReadUInt32LittleEndian(body);
|
|
if (opcode != Opcode) return null;
|
|
|
|
try
|
|
{
|
|
int pos = 4;
|
|
string message = StringReader.ReadString16L(body, ref pos);
|
|
if (body.Length - pos < 4) return null;
|
|
uint chatType = BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(pos));
|
|
return new Parsed(message, chatType);
|
|
}
|
|
catch { return null; }
|
|
}
|
|
}
|