Network tab sends
ChatNetwork.Rewrite sends a plain line typed on a network tab as /<command> global <text> while on the network (not sent off it); commands are unchanged. ChatModel.OnSend applies it only on a tab owned by an active chatTabs entry that declares network. On is unknown (treated as on) until the join status exists. The input placeholder follows the state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fea33eb41b
commit
726e0287f2
5 changed files with 116 additions and 1 deletions
|
|
@ -431,7 +431,7 @@ internal sealed class ChatFace : IImGuiPanel
|
|||
if (text.Length == 0 && !typing)
|
||||
{
|
||||
_inputScroll = 0;
|
||||
dl.AddText(new Vector2(p.X + 5, ty), Faded(Mute), ChatModel.InputHint ?? "Press Enter to chat…");
|
||||
dl.AddText(new Vector2(p.X + 5, ty), Faded(Mute), ChatModel.InputPlaceholder ?? "Press Enter to chat…");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1278,6 +1278,10 @@ internal static class ChatModel
|
|||
public static int InputCursor => Volatile.Read(ref _input).Cursor;
|
||||
/// <summary>Shown in the empty input box instead of the usual hint (e.g. "select an NPC first").</summary>
|
||||
public static string? InputHint => Volatile.Read(ref _input).Hint;
|
||||
/// <summary>What the empty input box shows: the hint if one is set, else the network tab's line, else null (the face's usual one).</summary>
|
||||
public static string? InputPlaceholder =>
|
||||
InputHint ?? (CurrentNetwork() == null ? null
|
||||
: ChatNetwork.On == false ? "Join the network to chat here" : "Press Enter to chat in Global (Dereth Network)");
|
||||
public static long InputVersion => Interlocked.Read(ref _inputVersion);
|
||||
|
||||
/// <summary>Raised on AC's main thread after the input line changes.</summary>
|
||||
|
|
@ -1455,6 +1459,14 @@ internal static class ChatModel
|
|||
SetInput("", 0, null);
|
||||
IntPtr send = SendLinePtr;
|
||||
if (text.Length == 0 || send == IntPtr.Zero) return;
|
||||
// On a network tab (CurrentNetwork) a plain line goes through the network's command; off
|
||||
// the network it is not sent (the placeholder says so, InputHint). Commands go as typed.
|
||||
if (CurrentNetwork() is { } network)
|
||||
{
|
||||
string? rewritten = ChatNetwork.Rewrite(text, network.Command, ChatNetwork.OnOrUnknown);
|
||||
if (rewritten == null) return;
|
||||
text = rewritten;
|
||||
}
|
||||
IntPtr ptr = Marshal.StringToHGlobalAnsi(text);
|
||||
// RynthChat sends the line through Host.InvokeChatParser, on this thread: an engine /rc
|
||||
// command in it is the player's, so it answers in chat (RynthCoreChatCommands.PlayerLine).
|
||||
|
|
@ -1466,6 +1478,31 @@ internal static class ChatModel
|
|||
finally { Marshal.FreeHGlobal(ptr); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The network declaration of the current tab, or null when the tab is not a network tab: the
|
||||
/// tab is a server's seeded tab (tabServers), one of that server's active entries owns a rule
|
||||
/// that fills it, and the entry declares "network". Any thread.
|
||||
/// </summary>
|
||||
public static SectionNetworkDecl? CurrentNetwork() => NetworkOfTab(CurrentTab());
|
||||
|
||||
/// <summary>The network declaration of <paramref name="tab"/> (see CurrentNetwork), or null.</summary>
|
||||
public static SectionNetworkDecl? NetworkOfTab(string tab)
|
||||
{
|
||||
if (!Volatile.Read(ref _tabServers).TryGetValue(tab, out string? server)) return null;
|
||||
string[] active = _activeServers;
|
||||
if (!ChatRouter.ServerIn(active, server)) return null;
|
||||
foreach (SectionChatTabDecl d in _tabDecls)
|
||||
{
|
||||
if (d.Network == null || !string.Equals(d.Server, server, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
string key = ChatServerTabs.OwnerKey(d);
|
||||
foreach (ChatFilterRule rule in Filters)
|
||||
if (string.Equals(rule.Owner, key, StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(rule.Tab, tab, StringComparison.OrdinalIgnoreCase))
|
||||
return d.Network;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The creature selected in the game (an NPC or another player), for /tell.
|
||||
/// AC's main thread only. Never yourself, never an item.</summary>
|
||||
private static bool TryGetSelectedTellName(out string name)
|
||||
|
|
|
|||
44
src/RynthCore.Engine/UI/Data/ChatNetwork.cs
Normal file
44
src/RynthCore.Engine/UI/Data/ChatNetwork.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - UI/Data/ChatNetwork.cs
|
||||
// Chat network tabs (2026-11-15): a chatTabs entry with "network" is a tab for a chat
|
||||
// network (the Dereth Network). While that tab is current, a typed line that is not a
|
||||
// command is sent through the network's own command ("/<command> global <text>"), and
|
||||
// only while the player is on the network. Pure and engine-free: ChatModel.OnSend
|
||||
// calls Rewrite; tools/ChatFilterTests compiles this file as is.
|
||||
// ============================================================================
|
||||
|
||||
using System.Threading;
|
||||
|
||||
namespace RynthCore.Engine.UI.Data;
|
||||
|
||||
internal static class ChatNetwork
|
||||
{
|
||||
// -1 unknown, 0 off the network, 1 on it. An int so any thread can read and write it whole.
|
||||
private static int _on = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Is the player on the network this session? null = not known yet (Task 11 fills it; until then
|
||||
/// a line is sent as if on). Any thread.
|
||||
/// </summary>
|
||||
public static bool? On
|
||||
{
|
||||
get => Volatile.Read(ref _on) switch { 0 => false, 1 => true, _ => null };
|
||||
set => Volatile.Write(ref _on, value == null ? -1 : value.Value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>Is a line to be sent as if on the network? Unknown counts as on.</summary>
|
||||
public static bool OnOrUnknown => On != false;
|
||||
|
||||
/// <summary>
|
||||
/// What to send for a line typed on a network tab, or null when it must not be sent. The line is
|
||||
/// trimmed; empty is null; a line starting with / or @ is a command and goes unchanged; any other
|
||||
/// goes as "/<command> global <text>" while on the network, and is not sent off it.
|
||||
/// </summary>
|
||||
internal static string? Rewrite(string line, string command, bool onNetwork)
|
||||
{
|
||||
string text = (line ?? string.Empty).Trim();
|
||||
if (text.Length == 0) return null;
|
||||
if (text[0] == '/' || text[0] == '@') return text;
|
||||
return onNetwork ? "/" + command + " global " + text : null;
|
||||
}
|
||||
}
|
||||
|
|
@ -41,6 +41,8 @@
|
|||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatServerTabs.cs" Link="Engine\ChatServerTabs.cs" />
|
||||
<!-- 2026-11-15: pinned tab bookkeeping. -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatPins.cs" Link="Engine\ChatPins.cs" />
|
||||
<!-- 2026-11-15: network tab sends. -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatNetwork.cs" Link="Engine\ChatNetwork.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ internal static class Program
|
|||
ServerTabDiscovery();
|
||||
ServerTabPlans();
|
||||
PinBookkeeping();
|
||||
NetworkRewrite();
|
||||
SharedFileReload();
|
||||
LineColorTags();
|
||||
LineColorKinds();
|
||||
|
|
@ -1606,6 +1607,37 @@ internal static class Program
|
|||
}
|
||||
|
||||
// 2026-11-15: pinned tab bookkeeping (ChatPins), pure.
|
||||
private static void NetworkRewrite()
|
||||
{
|
||||
Case("Rewrite_PlainText");
|
||||
Check(ChatNetwork.Rewrite("hello all", "derethnetwork", true) == "/derethnetwork global hello all", "on the network: sent through the command");
|
||||
Check(ChatNetwork.Rewrite("hello all", "derethnetwork", false) == null, "off the network: not sent");
|
||||
|
||||
Case("Rewrite_CommandsPassThrough");
|
||||
Check(ChatNetwork.Rewrite("/tell Bob@coldeve, hi", "dn", true) == "/tell Bob@coldeve, hi", "/tell unchanged on");
|
||||
Check(ChatNetwork.Rewrite("/tell Bob@coldeve, hi", "dn", false) == "/tell Bob@coldeve, hi", "/tell unchanged off");
|
||||
Check(ChatNetwork.Rewrite("@derethnetwork on", "dn", true) == "@derethnetwork on", "@command unchanged on");
|
||||
Check(ChatNetwork.Rewrite("@derethnetwork on", "dn", false) == "@derethnetwork on", "@command unchanged off");
|
||||
|
||||
Case("Rewrite_Trimmed");
|
||||
Check(ChatNetwork.Rewrite(" hi there ", "dn", true) == "/dn global hi there", "leading and trailing spaces trimmed");
|
||||
Check(ChatNetwork.Rewrite(" /tell Bob, hi ", "dn", true) == "/tell Bob, hi", "a command after spaces is still a command");
|
||||
Check(ChatNetwork.Rewrite(" @dn on", "dn", false) == "@dn on", "an @command after spaces is still a command");
|
||||
|
||||
Case("Rewrite_Empty");
|
||||
Check(ChatNetwork.Rewrite("", "dn", true) == null && ChatNetwork.Rewrite("", "dn", false) == null, "empty is never sent");
|
||||
Check(ChatNetwork.Rewrite(" \t ", "dn", true) == null && ChatNetwork.Rewrite(" ", "dn", false) == null, "whitespace only is never sent");
|
||||
|
||||
Case("NetworkState_DefaultsUnknown");
|
||||
Check(ChatNetwork.On == null && ChatNetwork.OnOrUnknown, "unknown by default and treated as on");
|
||||
ChatNetwork.On = false;
|
||||
Check(ChatNetwork.On == false && !ChatNetwork.OnOrUnknown, "off");
|
||||
ChatNetwork.On = true;
|
||||
Check(ChatNetwork.On == true && ChatNetwork.OnOrUnknown, "on");
|
||||
ChatNetwork.On = null;
|
||||
Check(ChatNetwork.On == null, "reset to unknown");
|
||||
}
|
||||
|
||||
private static void PinBookkeeping()
|
||||
{
|
||||
Case("Toggle_AddsAtEndAndRemoves");
|
||||
|
|
|
|||
Loading…
Reference in a new issue