diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs index 7c2f57a..a1ad55c 100644 --- a/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs +++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/ServerData.cs @@ -78,7 +78,7 @@ internal static class ServerData 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", diff --git a/Plugins/Shared/ServerPack/ServerPackInfo.cs b/Plugins/Shared/ServerPack/ServerPackInfo.cs index 7692f95..911ebc0 100644 --- a/Plugins/Shared/ServerPack/ServerPackInfo.cs +++ b/Plugins/Shared/ServerPack/ServerPackInfo.cs @@ -56,10 +56,15 @@ internal sealed record ServerSalvage(string Bench, int Material, string Effect, /// 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". -internal sealed record ServerChatTab(string Id, string Name, bool Pinned, string GlobalRoomFallback, ServerChatRule[] Rules); +/// 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 { diff --git a/Plugins/Shared/ServerPack/ServerPackModel.cs b/Plugins/Shared/ServerPack/ServerPackModel.cs index 53bf499..603b076 100644 --- a/Plugins/Shared/ServerPack/ServerPackModel.cs +++ b/Plugins/Shared/ServerPack/ServerPackModel.cs @@ -228,7 +228,10 @@ internal sealed class ServerPackModel sb.Append(",\"pattern\":").Append(Q(rule.Pattern)); sb.Append(",\"globalRoom\":").Append(rule.GlobalRoom ? "true" : "false").Append('}'); } - sb.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(']'); } diff --git a/Tools/RynthServerPack.Tests/ServerPackModelTests.cs b/Tools/RynthServerPack.Tests/ServerPackModelTests.cs index 3aa3066..436790a 100644 --- a/Tools/RynthServerPack.Tests/ServerPackModelTests.cs +++ b/Tools/RynthServerPack.Tests/ServerPackModelTests.cs @@ -247,7 +247,7 @@ internal static class ServerPackModelTests 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"); @@ -272,6 +272,20 @@ internal static class ServerPackModelTests 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"); }