RynthDreamWeave: web destinations and the launch reply's wire text

DreamWeaveWeb (constants-only destinations and launch URL) and LaunchWire
(/weblogin request, [WEB] reply parser that refuses player-authored copies).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 14:41:13 -08:00
commit fbd6458a0f
5 changed files with 225 additions and 0 deletions

View file

@ -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;
/// <summary>One website page a DreamWeave button opens.</summary>
internal sealed record WebDestination(string Id, string Label, string Path, string Tooltip);
internal static class DreamWeaveWeb
{
public const string SiteBase = "https://www.acdreamweave.com";
/// <summary>The only host the panel or the browser may be sent to.</summary>
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;
}
/// <summary>The sign-in URL for a destination. The caller has already checked the code with LaunchWire.</summary>
public static string LaunchUrl(string code, WebDestination d)
=> SiteBase + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path);
}

View file

@ -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;
/// <summary>The chat line to send for a destination. One place to add an argument later.</summary>
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 == '_';
/// <summary>
/// True when <paramref name="text"/> is a [WEB] reply from the server: then either
/// <paramref name="code"/> is set (success) or <paramref name="refusal"/> 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.
/// </summary>
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<char> line = text.AsSpan(start);
if (line.StartsWith(SuccessLead.AsSpan(), StringComparison.Ordinal))
{
ReadOnlySpan<char> 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;
}
}

View file

@ -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>();
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<string>();
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();
}
}

View file

@ -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);
}
}

View file

@ -34,6 +34,9 @@
<Compile Include="$(RynthSuiteRoot)Plugins\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
<!-- The web opener's pure rules (allowlist, route). -->
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerWebOpen.cs" Link="Plugin\ServerWebOpen.cs" />
<!-- DreamWeave's web destinations and the launch reply's wire text (pure). -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\DreamWeaveWeb.cs" Link="DreamWeave\DreamWeaveWeb.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\LaunchWire.cs" Link="DreamWeave\LaunchWire.cs" />
<!-- RynthConquest's own features (pure parts) and the RynthOracle sources it links. -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestData.cs" Link="Conquest\ConquestData.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestFeature.cs" Link="Conquest\ConquestFeature.cs" />