RynthDreamWeave: Market, Suit Builder and Ability Planner buttons and /rserver verbs

DreamWeaveWebTools.cs wires the launcher into the ServerPack hooks: the card
buttons (render thread, draw only, a click queues StartLaunch with RunOnTick),
the /rserver market|suit|abilities verbs, the /weblogin reply read off chat
(Code, Refused and Stale eat the line; Stale does nothing else), the 10 s
timeout polled every tick, and Reset at login, logout and shutdown. Every
launcher call is under lock (Gate); Send, OpenWeb, Reply and the log are
always outside it. OpenWeb's answer replaces the "Opening X..." status.
WebButtons.cs draws the buttons and is the only ImGui code in the web tools.
A source-scan test pins the thread rules.

Rebased onto release 2026.11.8.1, which ships its own DreamWeavePlugin.cs
(bank check, Bank page) and DreamWeaveSkills.cs (Skills and Character
panels, /rserver skills). Those files keep the one implementation of each
shared hook and call the web tools' Web* method first; the web code lives
in DreamWeaveWebTools.cs. The ImGui scan covers the web tools' own files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 15:11:22 -08:00
commit f012dc5c69
7 changed files with 596 additions and 3 deletions

View file

@ -28,6 +28,207 @@ internal static class DreamWeaveWebTests
r.Add("dreamweave web: a late code is eaten while it could still be valid", LateCodeIsStale);
r.Add("dreamweave web: overlapping requests never leak a code to chat", OverlappingRequests);
r.Add("dreamweave web: profile keys separate accounts", ProfileKeys);
r.Add("dreamweave web: ImGui only in WebButtons, no context switching, no host calls from draw", ThreadRules);
r.Add("dreamweave web: the plugin's shared hooks hand off to the web tools first", HooksHandOff);
}
// -- Host wiring (source scan: the plugin is NativeAOT, so its host code can't run here) --
private static string PluginsRoot()
{
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);
return Path.Combine(dir, "Plugins");
}
private static IEnumerable<string> SourceFiles(string root)
=> Directory.GetFiles(root, "*.cs", SearchOption.AllDirectories)
.Where(p => !p.Contains(Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)
&& !p.Contains(Path.DirectorySeparatorChar + "obj" + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase));
/// <summary>
/// The website feature's own files, the ones its rules hold to: DreamWeaveWeb*.cs, Web*.cs and LaunchWire.cs.
/// The plugin's other features (the Skills and Character panels, the Bank page) draw with ImGui themselves.
/// </summary>
private static List<string> WebFiles(string dw)
{
var files = SourceFiles(dw).Where(p =>
{
string n = Path.GetFileName(p);
return n.StartsWith("DreamWeaveWeb", StringComparison.Ordinal) || n.StartsWith("Web", StringComparison.Ordinal) || n == "LaunchWire.cs";
}).ToList();
Check.True(files.Count >= 6, "the website feature's files are found (" + files.Count + ")");
return files;
}
/// <summary>The text with // comments removed (a "//" right after ':' is a URL, kept), so a rule named in a comment doesn't count.</summary>
private static string StripComments(string text)
{
var sb = new System.Text.StringBuilder(text.Length);
foreach (string line in text.Split('\n'))
{
int at = 0, cut = -1;
while ((at = line.IndexOf("//", at, StringComparison.Ordinal)) >= 0)
{
if (at == 0 || line[at - 1] != ':') { cut = at; break; }
at += 2;
}
sb.Append(cut >= 0 ? line.Substring(0, cut) : line).Append('\n');
}
return sb.ToString();
}
/// <summary>The statement after each <paramref name="head"/>: a balanced { } block, or up to the next ';'.</summary>
private static List<string> StatementsAfter(string code, string head)
{
var found = new List<string>();
int at = 0;
while ((at = code.IndexOf(head, at, StringComparison.Ordinal)) >= 0)
{
int i = at + head.Length;
while (i < code.Length && char.IsWhiteSpace(code[i])) i++;
if (i < code.Length && code[i] == '{')
{
int depth = 0, j = i;
for (; j < code.Length; j++)
{
if (code[j] == '{') depth++;
else if (code[j] == '}' && --depth == 0) break;
}
found.Add(code.Substring(i, Math.Min(j + 1, code.Length) - i));
}
else
{
int semi = code.IndexOf(';', i);
found.Add(code.Substring(i, (semi < 0 ? code.Length : semi + 1) - i));
}
at = i;
}
return found;
}
/// <summary>The token as a call or member access of its own: "ChatLine(" matches, "OnChatLine(" does not.</summary>
private static bool Mentions(string code, string token)
=> System.Text.RegularExpressions.Regex.IsMatch(code, @"(?<![A-Za-z0-9_])" + System.Text.RegularExpressions.Regex.Escape(token));
private static int CountOf(string text, string needle)
{
int n = 0, at = 0;
while ((at = text.IndexOf(needle, at, StringComparison.Ordinal)) >= 0) { n++; at += needle.Length; }
return n;
}
// DreamWeavePlugin.cs and DreamWeaveSkills.cs own the hooks the web tools share with the bank and the Skills
// panel: each hands off to its Web* method before its own code, so no gate of theirs comes first.
private static void HooksHandOff()
{
string dw = Path.Combine(PluginsRoot(), "RynthCore.Plugin.RynthDreamWeave");
string plugin = StripComments(File.ReadAllText(Path.Combine(dw, "DreamWeavePlugin.cs")));
string skills = StripComments(File.ReadAllText(Path.Combine(dw, "DreamWeaveSkills.cs")));
(string Code, string Head, string Call)[] hooks =
{
(plugin, "partial void ServerLoginComplete()", "WebLoginComplete();"),
(plugin, "partial void ServerLogout()", "WebLogout();"),
(plugin, "partial void ServerShutdown()", "WebShutdown();"),
(plugin, "partial void ServerChatText(string text, int chatType, ref bool eat)", "WebChatText(text, chatType, ref eat);"),
(plugin, "partial void ServerTick(bool active)", "WebTick();"),
(skills, "partial void ServerChatCommand(string[] parts, ref bool handled)", "WebChatCommand(parts, ref handled);"),
(skills, "partial void ServerCommandVerbs(List<string> verbs)", null!),
};
foreach (var (code, head, call) in hooks)
{
List<string> body = StatementsAfter(code, head);
Check.Eq(body.Count, 1, head + ": implemented once");
if (body.Count != 1 || call == null) continue;
Check.True(body[0].TrimStart('{', ' ', '\n', '\r').StartsWith(call, StringComparison.Ordinal), head + ": " + call + " comes first");
}
List<string> verbs = StatementsAfter(skills, "partial void ServerCommandVerbs(List<string> verbs)");
Check.True(verbs.Count == 1 && verbs[0].Contains("WebCommandVerbs(verbs);", StringComparison.Ordinal), "ServerCommandVerbs adds the web verbs");
List<string> info = StatementsAfter(plugin, "partial void ServerInfoLines(Action<string> line)");
Check.True(info.Count == 1 && info[0].Contains("WebInfoLines(line);", StringComparison.Ordinal), "ServerInfoLines adds the web tools' line");
// The web tools implement none of the hooks they are handed: one implementation each, in the hub files.
string web = StripComments(File.ReadAllText(Path.Combine(dw, "DreamWeaveWebTools.cs")));
foreach (string hook in new[] { "ServerLoginComplete", "ServerLogout", "ServerShutdown", "ServerChatText", "ServerTick", "ServerChatCommand", "ServerCommandVerbs", "ServerInfoLines" })
Check.False(web.Contains("partial void " + hook + "(", StringComparison.Ordinal), "DreamWeaveWebTools.cs leaves " + hook + " to the hub");
}
private static void ThreadRules()
{
string plugins = PluginsRoot();
string dw = Path.Combine(plugins, "RynthCore.Plugin.RynthDreamWeave");
string buttonsPath = Path.Combine(dw, "DreamWeave", "WebButtons.cs");
string hostPath = Path.Combine(dw, "DreamWeaveWebTools.cs");
Check.True(File.Exists(buttonsPath), "DreamWeave\\WebButtons.cs exists");
Check.True(File.Exists(hostPath), "DreamWeaveWebTools.cs exists");
if (!File.Exists(buttonsPath) || !File.Exists(hostPath)) return;
var bareImGui = new System.Text.RegularExpressions.Regex(@"(?<![A-Za-z0-9_])ImGui\.");
foreach (string f in WebFiles(dw))
{
string code = StripComments(File.ReadAllText(f));
string name = Path.GetFileName(f);
Check.False(code.Contains("SetCurrentContext", StringComparison.Ordinal), name + ": no SetCurrentContext (RenderEmbedded/OnRender own the context)");
bool isButtons = string.Equals(Path.GetFullPath(f), Path.GetFullPath(buttonsPath), StringComparison.OrdinalIgnoreCase);
if (!isButtons)
{
Check.False(bareImGui.IsMatch(code), name + ": no ImGui. calls outside WebButtons.cs");
Check.False(code.Contains("SafeImGui.", StringComparison.Ordinal), name + ": no SafeImGui. calls outside WebButtons.cs");
}
}
var processStart = new System.Text.RegularExpressions.Regex(@"\bProcess\s*\.\s*Start\b");
foreach (string f in SourceFiles(plugins))
Check.False(processStart.IsMatch(StripComments(File.ReadAllText(f))), Path.GetFileName(f) + ": no Process.Start under Plugins (ShellExecuteW only)");
string buttons = StripComments(File.ReadAllText(buttonsPath));
foreach (string banned in new[] { "Host.", "Send(", "OpenWeb(", "RunOnTick(", "Reply.", "ChatLine(", "ChatFail(", "LogTagged(", "ShellExecute" })
Check.False(Mentions(buttons, banned), "WebButtons.cs: no " + banned + " (draw only draws)");
Check.True(buttons.Contains("ImGui.SmallButton(d.Label + \"##dw_web_\" + d.Id)", StringComparison.Ordinal), "WebButtons.cs: one SmallButton per destination, id-suffixed");
Check.False(buttons.Contains("BeginDisabled", StringComparison.Ordinal) || buttons.Contains("EndDisabled", StringComparison.Ordinal), "WebButtons.cs: no Begin/EndDisabled pairs");
Check.False(buttons.Contains("Push", StringComparison.Ordinal) || buttons.Contains("Pop", StringComparison.Ordinal), "WebButtons.cs: no ImGui push/pop pairs");
List<string> drawLocks = StatementsAfter(buttons, "lock (l.Gate)");
Check.Eq(drawLocks.Count, 1, "WebButtons.cs: one lock, to copy Pending and Status out");
foreach (string s in drawLocks)
Check.False(bareImGui.IsMatch(s) || s.Contains("SafeImGui", StringComparison.Ordinal) || s.Contains("click(", StringComparison.Ordinal),
"WebButtons.cs: nothing is drawn or clicked under the lock");
string host = StripComments(File.ReadAllText(hostPath));
List<string> cardHook = StatementsAfter(host, "partial void ServerCardActions()");
Check.Eq(cardHook.Count, 1, "DreamWeaveWebTools.cs implements ServerCardActions once");
string clickPath = cardHook.Count == 1 ? cardHook[0] : "";
Check.True(clickPath.Contains("WebButtons.Draw(", StringComparison.Ordinal), "the card hook draws through WebButtons.Draw");
Check.True(host.Contains("RunOnTick(() => StartLaunch(d))", StringComparison.Ordinal), "the button path queues StartLaunch with RunOnTick");
Check.False(clickPath.Contains("StartLaunch(d)", StringComparison.Ordinal) && !clickPath.Contains("RunOnTick(", StringComparison.Ordinal),
"the card hook never calls StartLaunch directly");
// Every lock on the launcher holds launcher calls only: no send, open, reply or log under it.
List<string> hostLocks = StatementsAfter(host, "lock (_web.Gate)");
Check.True(hostLocks.Count >= 5, "the host takes the launcher's lock (" + hostLocks.Count + " places)");
foreach (string s in hostLocks)
foreach (string banned in new[] { "Send(", "OpenWeb(", "Reply.", "ChatLine(", "ChatFail(", "LogTagged(", "Host.", "ShellExecute", "CloseWeb(" })
Check.False(Mentions(s, banned), "no " + banned + " under lock (_web.Gate): " + s.Trim().Replace('\n', ' '));
Check.False(host.Contains("DateTime", StringComparison.Ordinal) || host.Contains("Stopwatch", StringComparison.Ordinal), "nowMs comes from Environment.TickCount64 only");
Check.True(host.Contains("Environment.TickCount64", StringComparison.Ordinal), "the host uses Environment.TickCount64");
// The code goes into the launch URL and nowhere else.
int uses = System.Text.RegularExpressions.Regex.Matches(host, @"\blaunchCode\b").Count;
Check.Eq(uses, 3, "launchCode: declared, filled by OnChatLine, used once (DreamWeaveWeb.LaunchUrl)");
Check.Eq(CountOf(host, "out launchCode"), 1, "launchCode is filled only by OnChatLine");
Check.True(host.Contains("DreamWeaveWeb.LaunchUrl(launchCode, ", StringComparison.Ordinal), "the code's one use is the launch URL");
// Stale eats the line and does nothing else.
int stale = host.IndexOf("case LaunchLine.Stale:", StringComparison.Ordinal);
Check.True(stale >= 0, "the chat hook handles LaunchLine.Stale");
if (stale >= 0)
{
int end = host.IndexOf("return;", stale, StringComparison.Ordinal);
string arm = end < 0 ? "" : host.Substring(stale, end - stale);
Check.True(arm.Contains("eat = true;", StringComparison.Ordinal), "Stale eats the line");
foreach (string banned in new[] { "Reply.", "ChatLine(", "ChatFail(", "LogTagged(", "OpenWeb(", "Cancel(", "Host." })
Check.False(Mentions(arm, banned), "Stale does nothing else: no " + banned);
}
}
private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars