DreamWeave: website links, logged in by launch code #2

Open
AwfulWaffle wants to merge 19 commits from AwfulWaffle/RynthServers:dreamweave-web-panel into main
7 changed files with 596 additions and 3 deletions
Showing only changes of commit f012dc5c69 - Show all commits

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>
Daniel Wallace 2026-11-07 15:11:22 -08:00

View file

@ -0,0 +1,55 @@
// The DreamWeave card's website buttons (Market, Suit Builder, Ability Planner). Render thread, inside
// the card hook only: this file draws and nothing else. It calls no host function, sends nothing and
// opens nothing; a click is handed to the caller, which queues the work for the tick (RunOnTick).
// It never switches the ImGui context (RenderEmbedded and OnRender own it), and it draws no
// Begin/End or Push/Pop pairs, so an exception part-way can't leave ImGui's stacks unbalanced.
using System;
using ImGuiNET;
using RynthCore.Plugin.Shared;
namespace RynthCore.Plugin.RynthDreamWeave;
internal static class WebButtons
{
/// <summary>Shown on the card, and answered to a verb, when RynthCore doesn't see the world as DreamWeave.</summary>
public const string NotDreamWeave = "The web tools are DreamWeave's; RynthCore doesn't see this world as DreamWeave.";
/// <summary>
/// One small button per destination on one row, each with its tooltip; while a request is pending,
/// the status line instead. The launcher's state is copied out under its lock first, then drawn.
/// </summary>
public static void Draw(WebLauncher l, bool active, Action<WebDestination> click)
{
if (!active)
{
SafeImGui.TextWrapped(NotDreamWeave);
return;
}
bool pending;
string status;
lock (l.Gate)
{
pending = l.Pending != null;
status = l.Status;
}
if (pending)
{
SafeImGui.TextDisabled(status);
return;
}
WebDestination? clicked = null;
bool first = true;
foreach (WebDestination d in DreamWeaveWeb.Destinations)
{
if (!first) ImGui.SameLine();
first = false;
if (ImGui.SmallButton(d.Label + "##dw_web_" + d.Id)) clicked = d;
if (ImGui.IsItemHovered()) SafeImGui.SetTooltip(d.Tooltip);
}
if (status.Length > 0) SafeImGui.TextWrapped(status);
if (clicked != null) click(clicked);
}
}

View file

@ -2,6 +2,9 @@
// (Plugins/Shared/ServerPack/ServerPackPlugin.cs): the every-minute bank check that gives Lum/hr its
// luminance on DreamWeave (DreamWeave/DreamWeaveBank.cs, 2026-11-02), published as the profile value
// "bankLuminance" for the session stats, and its Bank page (DreamWeave/DreamWeavePages.cs).
// The website buttons and verbs (DreamWeaveWebTools.cs) share these hooks: each one below hands off to
// its Web* method first, so a launch-code line is read whatever the world is and the bank's own gates
// stay as they were.
using System;
using RynthCore.Plugin.RynthDreamWeave;
@ -30,18 +33,25 @@ public sealed partial class ServerPackPlugin
partial void ServerLoginComplete()
{
WebLoginComplete();
lock (_bank.Gate) _bank.Login(Environment.TickCount64);
}
partial void ServerLogout()
{
WebLogout();
lock (_bank.Gate) _bank.Logout();
}
partial void ServerShutdown() => SaveDreamWeaveSettings();
partial void ServerShutdown()
{
WebShutdown();
SaveDreamWeaveSettings();
}
partial void ServerChatText(string text, int chatType, ref bool eat)
{
WebChatText(text, chatType, ref eat);
if (!Active) return;
bool ours;
long? value;
@ -62,6 +72,7 @@ public sealed partial class ServerPackPlugin
partial void ServerTick(bool active)
{
WebTick();
if (!active) return;
string? check;
lock (_bank.Gate)
@ -92,5 +103,6 @@ public sealed partial class ServerPackPlugin
string lum = _bank.Luminance is long l ? l.ToString("N0", System.Globalization.CultureInfo.InvariantCulture) : "not read yet";
line($"Bank check every minute {(_bank.CheckEveryMinute ? "on" : "off")}; banked luminance {lum}.");
}
WebInfoLines(line);
}
}

View file

@ -235,10 +235,16 @@ public sealed partial class ServerPackPlugin
// ── /rserver skills ─────────────────────────────────────────────────
partial void ServerCommandVerbs(List<string> verbs) => verbs.Add("skills");
partial void ServerCommandVerbs(List<string> verbs)
{
verbs.Add("skills");
WebCommandVerbs(verbs); // DreamWeaveWebTools.cs: the website verbs
}
partial void ServerChatCommand(string[] parts, ref bool handled)
{
WebChatCommand(parts, ref handled); // DreamWeaveWebTools.cs: a website verb
if (handled) return;
if (parts.Length < 2 || !parts[1].Equals("skills", StringComparison.OrdinalIgnoreCase)) return;
handled = true;
// "press character|titles": what AC's own Character button or Titles window does now (the engine runs it

View file

@ -0,0 +1,318 @@
// DreamWeaveWebTools.cs - RynthDreamWeave's website tools, through the shared server plugin's hooks
// (Plugins/Shared/ServerPack/ServerPackPlugin.cs): the card's Market, Suit Builder and Ability Planner
// buttons and "/rserver market | suit | abilities", which open the website logged in as this account.
// The hooks it shares with the bank and the Skills panel are implemented once, in DreamWeavePlugin.cs and
// DreamWeaveSkills.cs, and call the Web* methods here first.
//
// The flow: a button (render thread) queues StartLaunch for the tick; a verb runs it on the pump. It
// sends "/weblogin"; ACE answers "[WEB] Launch code: ..." and the chat hook eats that line and opens
// DreamWeaveWeb.LaunchUrl through OpenWeb (ServerPackWeb.cs). Only the code comes from chat; the host
// and the path are constants. The code is never logged, saved, chatted or put in a status line.
//
// Threads (WebLauncher's remark): every launcher call is made under lock (_web.Gate), and the lock is
// held around launcher calls only, never around Send, OpenWeb, Reply or the log. Times come from
// Environment.TickCount64. The card hook runs on the render thread and only draws (WebButtons); the
// chat, tick, command and login hooks run on the plugin pump; OpenWeb's `done` may run on its worker
// thread. No hook lets an exception out: this code runs inside acclient.
using System;
using System.Collections.Generic;
using System.Threading;
using RynthCore.Plugin.RynthDreamWeave;
namespace RynthCore.Plugin.ServerPack;
public sealed partial class ServerPackPlugin
{
private readonly WebLauncher _web = new();
// The card's click handler, made once (render thread only).
private Action<WebDestination>? _webClick;
// The "no in-game web panel" line, once per login (set from OpenWeb's done, any thread).
private int _webNoPanelNoted;
// The card's draw failure, logged once rather than every frame (render thread only).
private bool _webDrawFailed;
private enum WebBrowserWhy { PanelFellBack, NoPanel, NoAccount }
private void WebCommandVerbs(List<string> verbs)
{
try
{
foreach (WebDestination d in DreamWeaveWeb.Destinations) verbs.Add(d.Id);
}
catch (Exception)
{
// The constructor has no Host to log to yet; the verbs are constants, so this can't happen.
}
}
partial void ServerCardActions()
{
try
{
WebButtons.Draw(_web, Active, _webClick ??= d => RunOnTick(() => StartLaunch(d)));
}
catch (Exception ex)
{
if (!_webDrawFailed)
{
_webDrawFailed = true;
LogTagged("The web buttons failed to draw: " + ex.GetType().Name);
}
}
}
private void WebChatCommand(string[] parts, ref bool handled)
{
try
{
if (parts.Length < 2) return;
WebDestination? d = DreamWeaveWeb.ById(parts[1]);
if (d == null) return;
handled = true;
StartLaunch(d);
}
catch (Exception ex)
{
LogTagged("A web verb failed: " + ex.GetType().Name);
}
}
/// <summary>Asks DreamWeave for a login code for <paramref name="d"/>. Pump thread (a verb, or a button's RunOnTick).</summary>
private void StartLaunch(WebDestination d)
{
try
{
if (!Active)
{
Reply.Fail(WebButtons.NotDreamWeave);
return;
}
LaunchBegin begun;
string status;
lock (_web.Gate)
{
begun = _web.Begin(d, Environment.TickCount64);
status = _web.Status;
}
if (begun == LaunchBegin.Busy)
{
Reply.Fail("Already asking DreamWeave for a login code; wait a moment.");
return;
}
if (begun == LaunchBegin.TooSoon)
{
Reply.Fail("Wait a few seconds between web opens.");
return;
}
if (!Send(LaunchWire.RequestFor(d)))
{
const string notSent = "Couldn't send /weblogin (not in the world).";
lock (_web.Gate) _web.Cancel(notSent);
Reply.Fail(notSent);
return;
}
Reply.Ok(status);
}
catch (Exception ex)
{
LogTagged("Starting a web open failed: " + ex.GetType().Name);
}
}
private void WebChatText(string text, int chatType, ref bool eat)
{
LaunchLine kind = LaunchLine.NotOurs;
try
{
if (!Active) return;
WebDestination? d;
string launchCode;
string status;
lock (_web.Gate)
{
kind = _web.OnChatLine(text, chatType, Environment.TickCount64, out d, out launchCode, out _);
status = _web.Status;
}
switch (kind)
{
case LaunchLine.NotOurs:
return;
case LaunchLine.Stale:
// A late or repeated code: keep it out of chat and open nothing. No reply, no status, no log.
eat = true;
return;
case LaunchLine.Refused:
eat = true;
Reply.Fail(status);
return;
case LaunchLine.Code:
eat = true;
if (d != null) OpenLaunch(d, DreamWeaveWeb.LaunchUrl(launchCode, d), status);
return;
}
}
catch (Exception ex)
{
// The line that answered our request never reaches chat, whatever failed after it was read.
if (kind != LaunchLine.NotOurs) eat = true;
LogTagged("Reading a web reply failed: " + ex.GetType().Name);
}
}
/// <summary>
/// Opens the launch URL (pump thread). <paramref name="opening"/> is the status the launcher set on the
/// code ("Opening X..."); the answer replaces it, so the card never stays on it.
/// </summary>
private void OpenLaunch(WebDestination d, string url, string opening)
{
try
{
string? account = Host.TryGetAccountName(out string name) ? name : null;
var request = new WebOpenRequest(url, DreamWeaveWeb.AllowedHosts,
WebProfile.Key(Info.Id, account) ?? "", DreamWeaveWeb.PanelTitle);
bool panel = PanelAvailable;
WebBrowserWhy why = ServerWebOpen.Route(request, panel) != WebOpenRoute.Browser ? WebBrowserWhy.PanelFellBack
: panel ? WebBrowserWhy.NoAccount : WebBrowserWhy.NoPanel;
OpenWeb(request, outcome => WebOpened(d, outcome, why, opening));
}
catch (Exception ex)
{
LogTagged("Opening a web page failed: " + ex.GetType().Name);
WebOpenFailed(d, "Couldn't open " + d.Label + ".", opening);
}
}
/// <summary>OpenWeb's answer. Any thread (the browser opens on a worker thread).</summary>
private void WebOpened(WebDestination d, WebOpenOutcome outcome, WebBrowserWhy why, string opening)
{
try
{
if (!outcome.Ok)
{
WebOpenFailed(d, "Couldn't open " + d.Label + ": " + outcome.Message, opening);
return;
}
string text;
string? note = null;
if (outcome.Route != WebOpenRoute.Browser) text = "Opened " + d.Label + ".";
else if (why == WebBrowserWhy.NoPanel)
{
text = "Opened " + d.Label + ".";
if (Interlocked.Exchange(ref _webNoPanelNoted, 1) == 0)
note = "This RynthCore has no in-game web panel, so " + d.Label + " opened in your browser.";
}
else if (why == WebBrowserWhy.NoAccount)
text = "Opened " + d.Label + " in your browser, not the web panel: RynthCore didn't report the account name.";
else
text = "Opened " + d.Label + " in your browser: the web panel didn't take it.";
ReplaceOpeningStatus(opening, text);
Reply.Ok(text);
if (note != null) Reply.Ok(note);
}
catch (Exception)
{
// OpenWeb's Finish swallows this too; nothing here may reach the engine.
}
}
private void WebOpenFailed(WebDestination d, string text, string opening)
{
try
{
ReplaceOpeningStatus(opening, text);
Reply.Fail(text);
}
catch (Exception)
{
}
}
/// <summary>
/// Puts the answer in the card's status, unless a newer request has taken over the launcher since the
/// code came in (then its own status stands). Cancel is the launcher's status setter; with nothing
/// pending it only sets the status.
/// </summary>
private void ReplaceOpeningStatus(string opening, string text)
{
lock (_web.Gate)
{
if (_web.Pending == null && _web.Status == opening) _web.Cancel(text);
}
}
private void WebTick()
{
try
{
WebDestination? timedOut;
string status = "";
lock (_web.Gate)
{
timedOut = _web.TakeTimedOut(Environment.TickCount64);
if (timedOut != null) status = _web.Status;
}
if (timedOut != null) Reply.Fail(status);
}
catch (Exception ex)
{
LogTagged("The web request timer failed: " + ex.GetType().Name);
}
}
private void WebInfoLines(Action<string> line)
{
try
{
string status;
lock (_web.Gate) status = _web.Status;
line("Web tools (/rserver market | suit | abilities): " + (status.Length > 0 ? status : "none opened this login."));
}
catch (Exception ex)
{
LogTagged("The web tools' info line failed: " + ex.GetType().Name);
}
}
private void WebLoginComplete()
{
try
{
lock (_web.Gate) _web.Reset();
Interlocked.Exchange(ref _webNoPanelNoted, 0);
}
catch (Exception ex)
{
LogTagged("Resetting the web tools at login failed: " + ex.GetType().Name);
}
}
private void WebLogout()
{
try
{
lock (_web.Gate) _web.Reset();
CloseWeb();
}
catch (Exception ex)
{
LogTagged("Closing the web tools at logout failed: " + ex.GetType().Name);
}
}
private void WebShutdown()
{
try
{
lock (_web.Gate) _web.Reset();
CloseWeb();
}
catch (Exception ex)
{
LogTagged("Closing the web tools at shutdown failed: " + ex.GetType().Name);
}
}
}

View file

@ -10,7 +10,7 @@
<RynthPluginServerName>DreamWeave</RynthPluginServerName>
<RynthPluginServerHosts>play.acdreamweave.com</RynthPluginServerHosts>
<RynthPluginServerWorldNames>DreamWeave|Dream Weave</RynthPluginServerWorldNames>
<RynthPluginDescription>DreamWeave only: the server card (rules, server features, player commands, links, account setup) in its own window on the RynthCore bar, the retail Character panel whose XP for next level keeps reading past level 275, and the bank check every minute that gives Lum/hr its luminance.</RynthPluginDescription>
<RynthPluginDescription>DreamWeave only: the server card (rules, server features, player commands, links, account setup) in its own window on the RynthCore bar, with Market, Suit Builder and Ability Planner buttons that open the website logged in as this account, the retail Character panel whose XP for next level keeps reading past level 275, and the bank check every minute that gives Lum/hr its luminance.</RynthPluginDescription>
</PropertyGroup>
<ItemGroup>

View file

@ -35,6 +35,7 @@ internal static class ServerData
"Experience bonuses: gear, augmentations, alt-character catch-up and offline (/bonus).",
"Fast tick opt-in: faster spell release, fast-chug and melee stick-to-target (/fasttick).",
"Web character sheet you can publish (/charsheet).",
"Market, Suit Builder and Ability Planner open logged in from this card (/rserver market | suit | abilities).",
},
Commands = new[]
{

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