WIP: DreamWeave: declare the Dereth Network chat tab #6

Draft
AwfulWaffle wants to merge 2 commits from AwfulWaffle/RynthServers:chat/dreamweave-network-tab into main
4 changed files with 126 additions and 2 deletions

View file

@ -69,6 +69,17 @@ internal static class ServerData
new ServerCommand("/charsheet", "publish a web character sheet (off, rotate)"), new ServerCommand("/charsheet", "publish a web character sheet (off, rotate)"),
new ServerCommand("/fi", "resend nearby monsters and NPCs (invisible creatures), once a minute"), new ServerCommand("/fi", "resend nearby monsters and NPCs (invisible creatures), once a minute"),
}, },
// The Network tab: tells that come from another world (name@world, or a Discord relay) and
// the live Global room (RynthChat finds which one by a remote speaker's line).
ChatTabs = new[]
{
new ServerChatTab("dereth-network", "Network", true, "Roleplay", new[]
{
new ServerChatRule("copy", "type:3", "", "^[^\"]+@[a-z0-9-]+( \\(discord\\))? tells you, \""),
new ServerChatRule("copy", "type:4", "", "^You tell [^\"]+@[a-z0-9-]+( \\(discord\\))?, \""),
new ServerChatRule("copy", "", "startswith", "", GlobalRoom: true),
}, new ServerChatNetwork("dereth", "derethnetwork")),
},
Discord = "https://discord.gg/p2h3yca4BD", Discord = "https://discord.gg/p2h3yca4BD",
Wiki = "https://wiki.acdreamweave.com", Wiki = "https://wiki.acdreamweave.com",
Source = "public AC server list (acresources/serverslist), checked 2026-10-13; features and commands from " + Source = "public AC server list (acresources/serverslist), checked 2026-10-13; features and commands from " +

View file

@ -45,6 +45,27 @@ internal sealed record ServerSalvage(string Bench, int Material, string Effect,
bool Prepared = false, int Order = 0, bool AfterCap = false, bool Prepared = false, int Order = 0, bool AfterCap = false,
string StackGroup = "", int StackCap = 0); string StackGroup = "", int StackCap = 0);
/// <summary>
/// One rule of a default chat tab the server declares (RynthChat reads it from the sections manifest's
/// "chatTabs"). <paramref name="Pattern"/> is regex text when <paramref name="Mode"/> is empty.
/// </summary>
/// <param name="Action">"copy" (the line also stays in Chat) or "move".</param>
/// <param name="When">The engine's When condition ("type:3" = a tell to you, "type:4" = a tell you sent); "" = any line.</param>
/// <param name="Mode">"" = regex; "startswith" and the engine's other literal modes.</param>
/// <param name="Pattern">The text or regex; "" for a Global room rule (the engine fills it in).</param>
/// <param name="GlobalRoom">The engine discovers which Global room is live and writes its prefix as the pattern.</param>
internal sealed record ServerChatRule(string Action, string When, string Mode, string Pattern, bool GlobalRoom = false);
/// <summary>The cross-world network a chat tab fronts: "dereth" with the server command that joins and sends (without the slash).</summary>
internal sealed record ServerChatNetwork(string Kind, string Command);
/// <summary>A default chat tab the server declares: a named tab with its rules, optionally pinned.</summary>
/// <param name="Id">Stable id within this server (lowercase letters, digits, dashes); owns the tab's rules.</param>
/// <param name="GlobalRoomFallback">The Global room used until one is discovered: "General", "Trade", "LFG" or "Roleplay".</param>
/// <param name="Network">The network the tab fronts (join, status and sends go through its command); null = none.</param>
internal sealed record ServerChatTab(string Id, string Name, bool Pinned, string GlobalRoomFallback, ServerChatRule[] Rules,
ServerChatNetwork? Network = null);
internal sealed class ServerPackInfo internal sealed class ServerPackInfo
{ {
public ServerPackInfo(string id, string name, string[] hosts, string[] worldNames) public ServerPackInfo(string id, string name, string[] hosts, string[] worldNames)
@ -78,6 +99,8 @@ internal sealed class ServerPackInfo
public ServerCommand[] Commands { get; init; } = Array.Empty<ServerCommand>(); public ServerCommand[] Commands { get; init; } = Array.Empty<ServerCommand>();
/// <summary>The server's own tinkering salvage (only recipes known to exist); empty = none defined.</summary> /// <summary>The server's own tinkering salvage (only recipes known to exist); empty = none defined.</summary>
public ServerSalvage[] Salvage { get; init; } = Array.Empty<ServerSalvage>(); public ServerSalvage[] Salvage { get; init; } = Array.Empty<ServerSalvage>();
/// <summary>Default chat tabs for RynthChat (sections manifest "chatTabs"); empty = none, and no key is written.</summary>
public ServerChatTab[] ChatTabs { get; init; } = Array.Empty<ServerChatTab>();
/// <summary> /// <summary>
/// Jewelry that is a trinket on this server (the Crafting tab's Trinkets bench, not Jewelry): name /// Jewelry that is a trinket on this server (the Crafting tab's Trinkets bench, not Jewelry): name
/// words, case-insensitive, and words that rule a name out again ("top" but not "topaz"). Empty: /// words, case-insensitive, and words that rule a name out again ("top" but not "topaz"). Empty:

View file

@ -205,8 +205,37 @@ internal sealed class ServerPackModel
sb.Append('}'); sb.Append('}');
// The server's own windows (ServerWindows, ServerPackWindows.cs, 2026-11-07). // The server's own windows (ServerWindows, ServerPackWindows.cs, 2026-11-07).
if (windows != null) sb.Append(ServerPackWindows.Json(windows, info.Id, frameless)); if (windows != null) sb.Append(ServerPackWindows.Json(windows, info.Id, frameless));
sb.Append("]}"); sb.Append(']');
return sb.ToString(); // The server's default RynthChat tabs; an engine without chatTabs support ignores the key.
if (info.ChatTabs.Length > 0)
{
sb.Append(",\"chatTabs\":[");
for (int i = 0; i < info.ChatTabs.Length; i++)
{
ServerChatTab tab = info.ChatTabs[i];
sb.Append(i == 0 ? "" : ",").Append("{\"server\":").Append(Q(info.Id));
sb.Append(",\"id\":").Append(Q(tab.Id));
sb.Append(",\"name\":").Append(Q(tab.Name));
sb.Append(",\"pinned\":").Append(tab.Pinned ? "true" : "false");
sb.Append(",\"globalRoomFallback\":").Append(Q(tab.GlobalRoomFallback));
sb.Append(",\"rules\":[");
for (int j = 0; j < tab.Rules.Length; j++)
{
ServerChatRule rule = tab.Rules[j];
sb.Append(j == 0 ? "" : ",").Append("{\"action\":").Append(Q(rule.Action));
sb.Append(",\"when\":").Append(Q(rule.When));
sb.Append(",\"mode\":").Append(Q(rule.Mode));
sb.Append(",\"pattern\":").Append(Q(rule.Pattern));
sb.Append(",\"globalRoom\":").Append(rule.GlobalRoom ? "true" : "false").Append('}');
}
sb.Append(']');
if (tab.Network != null)
sb.Append(",\"network\":{\"kind\":").Append(Q(tab.Network.Kind)).Append(",\"command\":").Append(Q(tab.Network.Command)).Append('}');
sb.Append('}');
}
sb.Append(']');
}
sb.Append('}'); return sb.ToString();
} }
/// <summary> /// <summary>

View file

@ -20,6 +20,7 @@ internal static class ServerPackModelTests
r.Add("server pack: before any push the world name decides", WorldFallback); r.Add("server pack: before any push the world name decides", WorldFallback);
r.Add("server pack: override commands are checked before sending", ForceCommands); r.Add("server pack: override commands are checked before sending", ForceCommands);
r.Add("server pack: the sections manifest declares the server and a server-only card", SectionsJson); r.Add("server pack: the sections manifest declares the server and a server-only card", SectionsJson);
r.Add("server pack: a declared chat tab reaches the engine parser as given", SectionsJson_ChatTabs);
r.Add("server pack: no bar menu writes no barMenu key", NoBarMenuKey); r.Add("server pack: no bar menu writes no barMenu key", NoBarMenuKey);
r.Add("server pack: the bar menu items reach the engine parser as given", BarMenuRoundTrip); r.Add("server pack: the bar menu items reach the engine parser as given", BarMenuRoundTrip);
r.Add("server pack: a bar menu tooltip with quotes and backslashes round-trips", BarMenuEscapes); r.Add("server pack: a bar menu tooltip with quotes and backslashes round-trips", BarMenuEscapes);
@ -229,6 +230,66 @@ internal static class ServerPackModelTests
new ServerBarMenuItem("abilities", "Class Abilities", ((char)0xE6A2).ToString(), "/rserver abilities"), new ServerBarMenuItem("abilities", "Class Abilities", ((char)0xE6A2).ToString(), "/rserver abilities"),
}; };
private static void SectionsJson_ChatTabs()
{
// The two tell patterns, as raw regex text (what the engine compiles), asserted byte for byte.
const string TellIn = @"^[^""]+@[a-z0-9-]+( \(discord\))? tells you, """;
const string TellOut = @"^You tell [^""]+@[a-z0-9-]+( \(discord\))?, """;
Check.Eq(TellIn, "^[^\"]+@[a-z0-9-]+( \\(discord\\))? tells you, \"", "tell-in literal, two spellings");
Check.Eq(TellOut, "^You tell [^\"]+@[a-z0-9-]+( \\(discord\\))?, \"", "tell-out literal, two spellings");
ServerPackInfo info = new("dreamweave", "DreamWeave", new[] { "play.example" }, new[] { "DreamWeave" })
{
ChatTabs = new[]
{
new ServerChatTab("dereth-network", "Network", true, "Roleplay", new[]
{
new ServerChatRule("copy", "type:3", "", TellIn),
new ServerChatRule("copy", "type:4", "", TellOut),
new ServerChatRule("copy", "", "startswith", "", GlobalRoom: true),
}, new ServerChatNetwork("dereth", "derethnetwork")),
},
};
string json = ServerPackModel.BuildSectionsJson(info, "RynthDreamWeave");
Console.WriteLine("chatTabs json: " + json.Substring(json.IndexOf("\"chatTabs\"", StringComparison.Ordinal)));
SectionManifest m = SectionManifestParser.Parse("RynthDreamWeave", json, out string error);
Check.Eq(error, string.Empty, "parses clean: " + error);
Check.Eq(m.ChatTabs.Length, 1, "one chat tab");
SectionChatTabDecl t = m.ChatTabs[0];
Check.Eq(t.Server, info.Id, "server is the info id");
Check.Eq(t.Id, "dereth-network", "id");
Check.Eq(t.Name, "Network", "name");
Check.True(t.Pinned, "pinned");
Check.Eq(t.GlobalRoomFallback, "Roleplay", "fallback room");
Check.Eq(t.Rules.Length, 3, "three rules");
Check.Eq(t.Rules[0].Pattern, TellIn, "tell-in pattern byte for byte");
Check.Eq(t.Rules[1].Pattern, TellOut, "tell-out pattern byte for byte");
Check.Eq(t.Rules[0].When, "type:3", "tell-in when");
Check.Eq(t.Rules[1].When, "type:4", "tell-out when");
Check.Eq(t.Rules[0].Action, "copy", "action");
Check.True(t.Rules[2].GlobalRoom, "third rule is the Global room rule");
Check.False(t.Rules[0].GlobalRoom, "first rule is not");
Check.Eq(t.Rules[2].Mode, "startswith", "global mode");
Check.Eq(t.Rules[2].Pattern, string.Empty, "global pattern empty");
Check.True(t.Network != null, "network parsed");
Check.Eq(t.Network!.Kind, "dereth", "network kind");
Check.Eq(t.Network.Command, "derethnetwork", "network command");
Check.True(json.Contains("\"network\":{\"kind\":\"dereth\",\"command\":\"derethnetwork\"}"), "network key written");
// An entry without a network emits no network key.
ServerPackInfo plain = new("dreamweave", "DreamWeave", new[] { "play.example" }, new[] { "DreamWeave" })
{
ChatTabs = new[] { new ServerChatTab("t", "T", false, "General", new[] { new ServerChatRule("copy", "", "startswith", "x") }) },
};
string plainJson = ServerPackModel.BuildSectionsJson(plain, "RynthDreamWeave");
Check.False(plainJson.Contains("\"network\""), "no network key without a network");
Check.True(SectionManifestParser.Parse("RynthDreamWeave", plainJson, out string e2).ChatTabs[0].Network == null && e2 == string.Empty, "no network parsed: " + e2);
// A pack without chat tabs emits no key.
Check.False(ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve").Contains("chatTabs"), "no chatTabs key by default");
}
private static void NoBarMenuKey() private static void NoBarMenuKey()
{ {
string plain = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve"); string plain = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve");