diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs index 78f21a7..a1ad55c 100644 --- a/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs +++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs @@ -69,6 +69,17 @@ internal static class ServerData new ServerCommand("/charsheet", "publish a web character sheet (off, rotate)"), 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", Wiki = "https://wiki.acdreamweave.com", Source = "public AC server list (acresources/serverslist), checked 2026-10-13; features and commands from " + diff --git a/Plugins/Shared/ServerPack/ServerPackInfo.cs b/Plugins/Shared/ServerPack/ServerPackInfo.cs index b7a6d8f..911ebc0 100644 --- a/Plugins/Shared/ServerPack/ServerPackInfo.cs +++ b/Plugins/Shared/ServerPack/ServerPackInfo.cs @@ -45,6 +45,27 @@ internal sealed record ServerSalvage(string Bench, int Material, string Effect, bool Prepared = false, int Order = 0, bool AfterCap = false, string StackGroup = "", int StackCap = 0); +/// +/// One rule of a default chat tab the server declares (RynthChat reads it from the sections manifest's +/// "chatTabs"). is regex text when is empty. +/// +/// "copy" (the line also stays in Chat) or "move". +/// The engine's When condition ("type:3" = a tell to you, "type:4" = a tell you sent); "" = any line. +/// "" = regex; "startswith" and the engine's other literal modes. +/// The text or regex; "" for a Global room rule (the engine fills it in). +/// The engine discovers which Global room is live and writes its prefix as the pattern. +internal sealed record ServerChatRule(string Action, string When, string Mode, string Pattern, bool GlobalRoom = false); + +/// The cross-world network a chat tab fronts: "dereth" with the server command that joins and sends (without the slash). +internal sealed record ServerChatNetwork(string Kind, string Command); + +/// A default chat tab the server declares: a named tab with its rules, optionally pinned. +/// Stable id within this server (lowercase letters, digits, dashes); owns the tab's rules. +/// The Global room used until one is discovered: "General", "Trade", "LFG" or "Roleplay". +/// The network the tab fronts (join, status and sends go through its command); null = none. +internal sealed record ServerChatTab(string Id, string Name, bool Pinned, string GlobalRoomFallback, ServerChatRule[] Rules, + ServerChatNetwork? Network = null); + internal sealed class ServerPackInfo { 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(); /// The server's own tinkering salvage (only recipes known to exist); empty = none defined. public ServerSalvage[] Salvage { get; init; } = Array.Empty(); + /// Default chat tabs for RynthChat (sections manifest "chatTabs"); empty = none, and no key is written. + public ServerChatTab[] ChatTabs { get; init; } = Array.Empty(); /// /// 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: diff --git a/Plugins/Shared/ServerPack/ServerPackModel.cs b/Plugins/Shared/ServerPack/ServerPackModel.cs index a863365..603b076 100644 --- a/Plugins/Shared/ServerPack/ServerPackModel.cs +++ b/Plugins/Shared/ServerPack/ServerPackModel.cs @@ -205,8 +205,37 @@ internal sealed class ServerPackModel sb.Append('}'); // The server's own windows (ServerWindows, ServerPackWindows.cs, 2026-11-07). if (windows != null) sb.Append(ServerPackWindows.Json(windows, info.Id, frameless)); - sb.Append("]}"); - return sb.ToString(); + sb.Append(']'); + // 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(); } /// diff --git a/Tools/RynthServerPack.Tests/ServerPackModelTests.cs b/Tools/RynthServerPack.Tests/ServerPackModelTests.cs index 7339d87..436790a 100644 --- a/Tools/RynthServerPack.Tests/ServerPackModelTests.cs +++ b/Tools/RynthServerPack.Tests/ServerPackModelTests.cs @@ -20,6 +20,7 @@ internal static class ServerPackModelTests 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: 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: 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); @@ -229,6 +230,66 @@ internal static class ServerPackModelTests 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() { string plain = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve");