fix(chat): BuildTell wire field order + retail-style FormatEntry + suppress duplicate Channel echo

Three follow-up fixes from the 2026-04-25 live verify session.

1. CRITICAL: BuildTell wire field order. Our outbound layout was
   [target_name, message] but ACE's GameActionTell.Handle reads
   [message, target_name] (verified against
   references/ACE/.../GameActionTell.cs:17-18 verbatim). Result: every
   /tell since Phase I.3 has been failing with WeenieError 0x052B
   (CharacterNotAvailable) because ACE was looking up the message
   text as the recipient name. Swapped the field order in
   ChatRequests.BuildTell so message is written first; updated the
   pinned BuildTell test to expect the corrected layout. The
   WorldSessionChatTests round-trip continues to pass since SendTell
   delegates to BuildTell.

2. Retail-style FormatEntry. The user asked for the canonical retail
   strings:
     /say (own):       You say, "text"
     /say (incoming):  Name says, "text"
     /tell (own echo): You tell Caith, "text"
     /tell (incoming): Caith tells you, "text"
     channel:          [Trade] +Acdream says, "text"
     /shout (own):     You shout, "text"
     /shout (incoming):Name shouts, "text"

   Discriminators: SenderGuid == 0 distinguishes our own outbound
   echoes (set by OnSelfSent) from real incoming whispers (carry the
   sender's player guid). Sender == "" or "You" distinguishes our own
   /say echoes (OnLocalSpeech substitutes "You" when the wire sender
   is empty per holtburger client/messages.rs:476-487).

   ChatEntry gains a new ChannelName slot so Channel-kind entries
   render with the friendly room name ("Trade") instead of "ch 3".
   Falls back to "ch {ChannelId}" when ChannelName isn't populated
   (legacy ChatChannel inbound or older callers).

3. Suppress optimistic Channel echo. The user saw duplicates per
   /trade /lfg in the live trace:
     [ch 0] Trade: hello                     <-- our optimistic
     [ch 3] +Acdream: [Trade] hello          <-- ACE's TurbineChat broadcast
   ACE's TurbineChatHandler at Network/Handlers/TurbineChatHandler.cs
   broadcasts EventSendToRoom to ALL recipients in the room including
   the sender, so the canonical echo always arrives via 0xF7DE. Drop
   the optimistic OnSelfSent for Turbine kinds in GameWindow's
   SendChatCmd handler; trust the server. Legacy ChatChannel paths
   (Fellowship / Allegiance / Patron / Monarch / Vassals / CoVassals)
   keep the optimistic echo because the legacy 0x0147 broadcast may
   not always come back to the sender.

   Inbound TurbineChat also stops embedding "[Trade] " into the
   message text — passes the friendly name out-of-band via the new
   channelName parameter on ChatLog.OnChannelBroadcast.

11 tests updated for the new format strings (8 in ChatVMTests, 1 in
ChatVMCombatTests, 1 BuildTell, plus the format additions cover
incoming/outgoing variants per kind). Solution total: 1007 green
(243 + 114 + 650), 0 warnings.

Tells should now actually deliver. Channel echoes show as
[Trade] +Acdream says, "hello" without the duplicate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-25 20:49:02 +02:00
parent e17caa2942
commit 3f7821c18d
7 changed files with 204 additions and 47 deletions

View file

@ -128,15 +128,26 @@ public sealed class ChatLog
ChannelId: errorId));
}
/// <summary>GameEvent ChannelBroadcast (0x0147).</summary>
public void OnChannelBroadcast(uint channelId, string sender, string text)
/// <summary>
/// Channel broadcast — legacy <c>ChatChannel (0x0147)</c> or the
/// TurbineChat (<c>0xF7DE</c>) global community channels (General,
/// Trade, LFG, Roleplay, Society, Olthoi). Pass
/// <paramref name="channelName"/> when the caller knows the
/// friendly room name (TurbineChat dispatch always does); the
/// <c>ChatVM</c> formatter renders entries as
/// <c>"[ChannelName] Sender says, \"text\""</c> when set.
/// </summary>
public void OnChannelBroadcast(uint channelId, string sender, string text, string channelName = "")
{
Append(new ChatEntry(
Kind: ChatKind.Channel,
Sender: sender,
Text: text,
SenderGuid: 0,
ChannelId: channelId));
ChannelId: channelId)
{
ChannelName = channelName,
});
}
/// <summary>GameEvent Tell (0x02BD) — whisper received.</summary>
@ -196,15 +207,43 @@ public sealed class ChatLog
});
}
/// <summary>Echo the player's own outbound message after local send.</summary>
/// <summary>
/// Echo the player's own outbound message after local send.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item><b>Say</b>: pass <paramref name="targetOrChannel"/> as
/// empty; the formatter renders <c>"You say, \"text\""</c>.</item>
/// <item><b>Tell</b>: pass the target name; the formatter
/// renders <c>"You tell {target}, \"text\""</c>.</item>
/// <item><b>Channel</b>: <i>do not call</i> for global community
/// channels — the server (ACE TurbineChatHandler) echoes the
/// broadcast back to the sender already, so optimistic-echoing
/// would double-print. For legacy channels (Fellowship,
/// Allegiance) where the server may not echo, pass the
/// channel name as <paramref name="targetOrChannel"/>; it
/// becomes the entry's <c>ChannelName</c>.</item>
/// </list>
/// <c>SenderGuid == 0</c> on the resulting entry is the
/// discriminator the formatter uses to render outgoing-vs-incoming
/// (a real incoming Tell carries the sender's player guid).
/// </remarks>
public void OnSelfSent(ChatKind kind, string text, string targetOrChannel = "")
{
Append(new ChatEntry(
Kind: kind,
Sender: targetOrChannel, // used as "to whom" for Tell / channel name for Channel
// For Tell, Sender carries the target name (so the formatter
// can render "You tell {Sender}..."). For LocalSpeech, we
// leave Sender empty and let the formatter substitute "You".
// For Channel callers, Sender stays empty too — ChannelName
// (below) carries the friendly name.
Sender: kind == ChatKind.Tell ? targetOrChannel : "",
Text: text,
SenderGuid: 0,
ChannelId: 0));
ChannelId: 0)
{
ChannelName = kind == ChatKind.Channel ? targetOrChannel : "",
});
}
private void Append(ChatEntry entry)
@ -256,4 +295,13 @@ public readonly record struct ChatEntry(
/// <see cref="ChatPanel"/>'s <c>TextColored</c> color choice.
/// </summary>
public Combat.CombatLineKind? CombatKind { get; init; }
/// <summary>
/// Friendly name of the channel for <see cref="ChatKind.Channel"/>
/// entries (e.g. "General", "Trade", "LFG", "Fellowship"). Empty
/// for non-Channel kinds. Used by <c>ChatVM.FormatEntry</c> to
/// render lines as <c>"[ChannelName] Sender says, \"text\""</c>.
/// Falls back to <c>"ch {ChannelId}"</c> if not populated.
/// </summary>
public string ChannelName { get; init; } = "";
}