diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs
new file mode 100644
index 0000000..6e8ce44
--- /dev/null
+++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs
@@ -0,0 +1,38 @@
+// DreamWeave's website destinations: where each button goes. The host and the paths are constants
+// (the site's registry: dreamweave-market Source/ACE.Market/Site/SiteTools.cs and HostRouting.cs);
+// nothing here is ever read from chat. Pure, so RynthServerPack.Tests compiles it directly.
+using System;
+
+namespace RynthCore.Plugin.RynthDreamWeave;
+
+/// One website page a DreamWeave button opens.
+internal sealed record WebDestination(string Id, string Label, string Path, string Tooltip);
+
+internal static class DreamWeaveWeb
+{
+ public const string SiteBase = "https://www.acdreamweave.com";
+
+ /// The only host the panel or the browser may be sent to.
+ public static readonly string[] AllowedHosts = { "www.acdreamweave.com" };
+
+ public const string PanelTitle = "DreamWeave";
+
+ public static readonly WebDestination[] Destinations =
+ {
+ new("market", "Market", "/market", "The player market, logged in as this account."),
+ new("suit", "Suit Builder", "/tools/suit", "Plan a suit from this account's characters."),
+ new("abilities", "Ability Planner", "/tools/abilities", "Plan a class ability build."),
+ };
+
+ public static WebDestination? ById(string? id)
+ {
+ if (string.IsNullOrEmpty(id)) return null;
+ foreach (WebDestination d in Destinations)
+ if (string.Equals(d.Id, id, StringComparison.OrdinalIgnoreCase)) return d;
+ return null;
+ }
+
+ /// The sign-in URL for a destination. The caller has already checked the code with LaunchWire.
+ public static string LaunchUrl(string code, WebDestination d)
+ => SiteBase + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path);
+}
diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/LaunchWire.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/LaunchWire.cs
new file mode 100644
index 0000000..90b2e20
--- /dev/null
+++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/LaunchWire.cs
@@ -0,0 +1,53 @@
+// The wire text of DreamWeave's website sign-in: the "/weblogin" request and ACE's reply line.
+// The code comes from chat; nothing else does. The line that carries it is eaten by the caller
+// and the code is never logged, saved or chatted.
+// Success: "[WEB] Launch code: <43 chars A-Za-z0-9_-> (single use, expires in 60 seconds)".
+// Any other "[WEB] " line is a refusal worded for the player.
+using System;
+using RynthCore.Plugin.Shared;
+
+namespace RynthCore.Plugin.RynthDreamWeave;
+
+internal static class LaunchWire
+{
+ public const string RequestCommand = "/weblogin";
+ public const string ReplyLead = "[WEB] ";
+ public const string SuccessLead = "[WEB] Launch code: ";
+ public const int CodeLength = 43;
+ public const long ReplyTimeoutMs = 10_000, MinIntervalMs = 3_000;
+
+ /// The chat line to send for a destination. One place to add an argument later.
+ public static string RequestFor(WebDestination d) => RequestCommand;
+
+ public static bool IsCodeChar(char c)
+ => (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_';
+
+ ///
+ /// True when is a [WEB] reply from the server: then either
+ /// is set (success) or is (a refusal).
+ /// False for anything else, and for a player's copy of the line. A line that starts like a
+ /// success but whose code is malformed is false, never a refusal and never a code.
+ ///
+ public static bool TryParse(string? text, int chatType, out string code, out string refusal)
+ {
+ code = "";
+ refusal = "";
+ if (text == null || ChatSource.IsPlayerAuthored(chatType)) return false;
+ if (!ChatSource.StartsWithMarker(text, ReplyLead)) return false;
+
+ int start = ChatSource.ContentStart(text);
+ ReadOnlySpan line = text.AsSpan(start);
+ if (line.StartsWith(SuccessLead.AsSpan(), StringComparison.Ordinal))
+ {
+ ReadOnlySpan rest = line.Slice(SuccessLead.Length);
+ if (rest.Length <= CodeLength || rest[CodeLength] != ' ') return false;
+ for (int i = 0; i < CodeLength; i++)
+ if (!IsCodeChar(rest[i])) return false;
+ code = rest.Slice(0, CodeLength).ToString();
+ return true;
+ }
+
+ refusal = line.Slice(ReplyLead.Length).ToString();
+ return true;
+ }
+}
diff --git a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs
new file mode 100644
index 0000000..eeb81b1
--- /dev/null
+++ b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs
@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Xml.Linq;
+using RynthCore.Plugin.RynthDreamWeave;
+using RynthCore.Plugin.ServerPack;
+using RynthCore.RynthAiTests.Harness;
+
+namespace RynthServerPack.Tests;
+
+// DreamWeave's web buttons, the pure part: the destinations and the "/weblogin" reply's wire text.
+internal static class DreamWeaveWebTests
+{
+ public static void Register(Runner r)
+ {
+ r.Add("dreamweave web: a player's copy of the launch line is never taken", PlayerCopy);
+ r.Add("dreamweave web: the launch URL is built from constants and a clean code", UrlFromConstants);
+ r.Add("dreamweave web: destination ids are verbs no one else uses", IdsAreFree);
+ r.Add("dreamweave web: ACE's refusals parse as refusals, other lines are ignored", Refusals);
+ }
+
+ private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars
+ private const string Line = "[WEB] Launch code: " + Code + " (single use, expires in 60 seconds)";
+
+ private static bool Parse(string? text, int type, out string code, out string refusal)
+ => LaunchWire.TryParse(text, type, out code, out refusal);
+
+ private static void PlayerCopy()
+ {
+ Check.Eq(Code.Length, LaunchWire.CodeLength, "fixture code is 43 chars");
+
+ foreach (int type in new[] { 0x02, 0x03, 0x08, 0x0C, 0x13 })
+ Check.True(!Parse(Line, type, out _, out _), "player-authored chat type 0x" + type.ToString("X2") + " refused");
+
+ Check.True(!Parse("Bob tells you, " + Line, 0x05, out _, out _), "a tell wrapper with a system type refused");
+ Check.True(!Parse("hello " + Line, 0x05, out _, out _), "the lead mid-line refused");
+
+ Check.True(Parse(Line, 0x05, out string code, out string refusal), "valid line, system type");
+ Check.Eq(code, Code, "the code");
+ Check.Eq(refusal, "", "no refusal on success");
+ Check.True(Parse(Line, -1, out code, out _), "unknown type: the anchor alone protects");
+ Check.Eq(code, Code, "the code (type -1)");
+ Check.True(!Parse(null, 0x05, out _, out _), "null refused");
+ Check.True(!Parse("", 0x05, out _, out _), "empty refused");
+ }
+
+ private static void UrlFromConstants()
+ {
+ string head = "[WEB] Launch code: ";
+ Check.True(!Parse(head + Code.Substring(1) + " (single use)", 0x05, out _, out _), "42-char code refused");
+ Check.True(!Parse(head + Code + "A (single use)", 0x05, out _, out _), "44-char run (no space after 43) refused");
+ Check.True(!Parse(head + Code + "&to=//evil.com", 0x05, out _, out _), "code followed by &to= refused");
+ Check.True(!Parse(head + Code, 0x05, out _, out _), "no trailing space refused");
+ Check.True(!Parse(head + Code.Substring(0, 42) + "! (single use)", 0x05, out _, out _), "bad code char refused");
+ Check.True(!Parse(head + Code.Substring(0, 42) + "% (single use)", 0x05, out _, out _), "percent in code refused");
+
+ // None of the malformed success lines may leak out as a refusal either.
+ Check.True(!Parse(head + Code.Substring(1) + " x", 0x05, out _, out string r1) && r1 == "", "malformed success is not a refusal");
+
+ WebDestination suit = DreamWeaveWeb.ById("suit")!;
+ string url = DreamWeaveWeb.LaunchUrl(Code, suit);
+ Check.True(url.StartsWith(DreamWeaveWeb.SiteBase + "/launch?code=", StringComparison.Ordinal), "url starts with the base");
+ Check.Eq(url, DreamWeaveWeb.SiteBase + "/launch?code=" + Code + "&to=%2Ftools%2Fsuit", "exact suit url");
+ Check.True(url.EndsWith("%2Ftools%2Fsuit", StringComparison.Ordinal), "ends with the escaped path");
+ Check.Eq(url.Split("&to=").Length - 1, 1, "exactly one &to=");
+
+ foreach (WebDestination d in DreamWeaveWeb.Destinations)
+ {
+ string u = DreamWeaveWeb.LaunchUrl(Code, d);
+ Check.True(ServerWebOpen.IsAllowedUrl(u, DreamWeaveWeb.AllowedHosts), d.Id + ": url passes the allowlist");
+ Check.True(d.Path.StartsWith("/", StringComparison.Ordinal) && !d.Path.StartsWith("//", StringComparison.Ordinal), d.Id + ": path is rooted, not //");
+ Check.True(d.Path.IndexOfAny(new[] { '?', '#', '\\' }) < 0, d.Id + ": no ? # or backslash in path");
+ Check.True(d.Label.Length > 0 && d.Tooltip.Length > 0, d.Id + ": label and tooltip");
+ }
+ Check.True(DreamWeaveWeb.ById("SUIT") == suit, "ById is case-insensitive");
+ Check.True(DreamWeaveWeb.ById("nope") == null && DreamWeaveWeb.ById(null) == null && DreamWeaveWeb.ById("") == null, "unknown id -> null");
+ Check.Eq(LaunchWire.RequestFor(suit), "/weblogin", "request is /weblogin");
+ }
+
+ private static void IdsAreFree()
+ {
+ var seen = new HashSet();
+ string[] serverIds = ServerPluginIds();
+ Check.True(serverIds.Length > 0, "found the server plugin ids");
+ foreach (WebDestination d in DreamWeaveWeb.Destinations)
+ {
+ Check.True(d.Id.Length >= 1 && d.Id.Length <= 16 && d.Id.All(c => c >= 'a' && c <= 'z'), d.Id + ": 1-16 chars [a-z]");
+ Check.True(Array.IndexOf(ServerPackCommands.SharedVerbs, d.Id) < 0, d.Id + ": not a shared verb");
+ Check.True(Array.IndexOf(serverIds, d.Id) < 0, d.Id + ": not a server plugin id");
+ Check.True(seen.Add(d.Id), d.Id + ": unique");
+ }
+ }
+
+ private static void Refusals()
+ {
+ string[] lines =
+ {
+ "[WEB] Signing in to the website from the game is turned off on this server.",
+ "[WEB] The website sign-in service is not available right now.",
+ "[WEB] You are requesting website sign-in codes too quickly. Wait a minute and try again.",
+ };
+ foreach (string l in lines)
+ {
+ Check.True(Parse(l, 0x05, out string code, out string refusal), "refusal parses: " + l);
+ Check.Eq(code, "", "no code in a refusal");
+ Check.Eq(refusal, l.Substring(LaunchWire.ReplyLead.Length), "refusal text after the lead");
+ Check.True(!Parse(l, 0x02, out _, out _), "a player's copy of a refusal is ignored");
+ }
+ Check.True(!Parse("You say, \"hi\"", 0x05, out _, out _), "other chat ignored");
+ Check.True(!Parse("[WEBX] Launch code: " + Code, 0x05, out _, out _), "lookalike lead ignored");
+ }
+
+ private static string[] ServerPluginIds()
+ {
+ string? dir = AppContext.BaseDirectory;
+ while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
+ dir = Path.GetDirectoryName(dir);
+ if (dir == null) throw new DirectoryNotFoundException("Plugins not found above " + AppContext.BaseDirectory);
+ var ids = new List();
+ foreach (string p in Directory.GetDirectories(Path.Combine(dir, "Plugins"), "RynthCore.Plugin.Rynth*"))
+ {
+ string csproj = Path.Combine(p, Path.GetFileName(p) + ".csproj");
+ if (!File.Exists(csproj)) continue;
+ string id = XDocument.Load(csproj).Descendants("RynthPluginServerId").FirstOrDefault()?.Value.Trim() ?? "";
+ if (id.Length > 0) ids.Add(id);
+ }
+ return ids.ToArray();
+ }
+}
diff --git a/Tools/RynthServerPack.Tests/Program.cs b/Tools/RynthServerPack.Tests/Program.cs
index 88e690e..36323eb 100644
--- a/Tools/RynthServerPack.Tests/Program.cs
+++ b/Tools/RynthServerPack.Tests/Program.cs
@@ -23,6 +23,7 @@ internal static class Program
DreamWeaveSkillsTests.Register(runner);
DreamWeaveTests.Register(runner);
ServerWebOpenTests.Register(runner);
+ DreamWeaveWebTests.Register(runner);
return runner.Run("RynthServerPack tests", args.Length > 0 ? args[0] : null);
}
}
diff --git a/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj b/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj
index 67ccd9a..a0fc97d 100644
--- a/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj
+++ b/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj
@@ -34,6 +34,9 @@
+
+
+