DreamWeave: website links in the bar icon's dropdown #4

Open
AwfulWaffle wants to merge 29 commits from AwfulWaffle/RynthServers:dreamweave-bar-menu into main
3 changed files with 51 additions and 10 deletions
Showing only changes of commit d70f780e60 - Show all commits

RynthDreamWeave: Task 6 re-review, close the source-scan gaps

- Calls: one CallPattern for the lock and Draw allow-lists, which also
  reads "?." member chains and a type-argument list before "(", so
  Reply?.Fail( and Notify<int>( count as non-launcher calls.
- Monitor is banned in WebButtons.cs and DreamWeaveWebTools.cs; the host
  takes the launcher's lock in exactly 9 places, and each lock body is
  pinned exactly (no host property read under it either).
- ServerChatText: everything before its first lock is pinned exactly
  (declarations only), so no gate, return or throw can come before the
  launcher reads the line.
- WebLauncher.cs holds no Action, Func or delegate; any scanned file
  with a raw string literal fails, since the scan does not model them.
- Usage: "Market, Suit Builder or Ability Planner". The shared two lines
  are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Daniel Wallace 2026-11-07 15:31:21 -08:00

View file

@ -38,8 +38,9 @@ internal static class DreamWeaveWeb
var ids = new string[Destinations.Length];
var labels = new string[Destinations.Length];
for (int i = 0; i < Destinations.Length; i++) { ids[i] = Destinations[i].Id; labels[i] = Destinations[i].Label; }
return "/rserver " + string.Join(" | ", ids) + " - open the website's " + string.Join(", ", labels)
+ ", logged in as this account.";
string choices = labels.Length < 2 ? string.Join("", labels)
: string.Join(", ", labels, 0, labels.Length - 1) + " or " + labels[labels.Length - 1];
return "/rserver " + string.Join(" | ", ids) + " - open the website's " + choices + ", logged in as this account.";
}
/// <summary>The sign-in URL for a destination. The caller has already checked the code with LaunchWire.</summary>

View file

@ -176,15 +176,22 @@ internal static class DreamWeaveWebTests
return found;
}
/// <summary>
/// A call: an identifier or a member chain (".", "?."), an optional type-argument list, then "(".
/// Group 1 is the chain; the type arguments are left out of it ("Notify<int>(" is "Notify").
/// </summary>
private static readonly System.Text.RegularExpressions.Regex CallPattern = new(
@"(?<![A-Za-z0-9_.?])([A-Za-z_][A-Za-z0-9_]*(?:\s*\??\.\s*[A-Za-z_][A-Za-z0-9_]*)*)\s*(?:<[^<>();{}]*>)?\s*\(");
/// <summary>
/// Every call in <paramref name="body"/> that is not a member call on <paramref name="receiver"/>
/// ("_web.Begin(" is allowed; "Send(", "Helper(", "if (", "x._web.Begin(" are not).
/// ("_web.Begin(" is allowed; "Send(", "Helper(", "if (", "x._web.Begin(", "a?.Invoke(", "Notify<int>(" are not).
/// </summary>
internal static List<string> CallsNotOn(string body, string receiver)
{
var bad = new List<string>();
var allowed = new System.Text.RegularExpressions.Regex("^" + System.Text.RegularExpressions.Regex.Escape(receiver) + @"\.[A-Za-z_][A-Za-z0-9_]*$");
foreach (System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(body, @"(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_]*(?:\s*\.\s*[A-Za-z_][A-Za-z0-9_]*)*)\s*\("))
foreach (System.Text.RegularExpressions.Match m in CallPattern.Matches(body))
{
string chain = System.Text.RegularExpressions.Regex.Replace(m.Groups[1].Value, @"\s+", "");
if (!allowed.IsMatch(chain)) bad.Add(chain + "(");
@ -261,7 +268,21 @@ internal static class DreamWeaveWebTests
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 raw = File.ReadAllText(f);
// StripComments does not model raw string literals: a file with one must fail, not scan wrongly.
Check.False(raw.Contains("\"\"\"", StringComparison.Ordinal), Path.GetFileName(f) + ": no raw string literal (the scan does not support them)");
Check.False(processStart.IsMatch(StripComments(raw)), Path.GetFileName(f) + ": no Process.Start under Plugins (ShellExecuteW only)");
}
// Monitor would take the launcher's lock without a lock statement, out of the scan's sight.
var monitor = new System.Text.RegularExpressions.Regex(@"\bMonitor\s*\.");
foreach (string f in new[] { buttonsPath, hostPath })
Check.False(monitor.IsMatch(StripComments(File.ReadAllText(f))), Path.GetFileName(f) + ": no Monitor (lock statements only)");
// The launcher holds no callbacks, so nothing can run host code from inside its lock.
string launcher = StripComments(File.ReadAllText(Path.Combine(dw, "DreamWeave", "WebLauncher.cs")));
Check.False(System.Text.RegularExpressions.Regex.IsMatch(launcher, @"\b(Action|Func|delegate)\b"), "WebLauncher.cs: no Action, Func or delegate");
// WebButtons.cs calls only ImGui/SafeImGui, the launcher (under its lock) and the click it was handed.
string buttons = StripComments(File.ReadAllText(buttonsPath));
@ -270,7 +291,7 @@ internal static class DreamWeaveWebTests
string drawBody = draw < 0 ? "" : StatementAt(buttons, buttons.IndexOf(')', draw) + 1);
var drawAllowed = new System.Text.RegularExpressions.Regex(@"^(ImGui\.[A-Za-z]+|SafeImGui\.[A-Za-z]+|click|lock|if|foreach)\($");
var drawCalls = new List<string>();
foreach (System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(drawBody, @"(?<![A-Za-z0-9_.])([A-Za-z_][A-Za-z0-9_]*(?:\s*\.\s*[A-Za-z_][A-Za-z0-9_]*)*)\s*\("))
foreach (System.Text.RegularExpressions.Match m in CallPattern.Matches(drawBody))
{
string chain = Collapse(m.Groups[1].Value) + "(";
if (!drawAllowed.IsMatch(chain)) drawCalls.Add(chain);
@ -298,12 +319,26 @@ internal static class DreamWeaveWebTests
// Every lock in the host is on the launcher and holds launcher member calls only.
List<(string Target, string Body)> hostLocks = Locks(host);
Check.True(hostLocks.Count >= 5, "the host takes the launcher's lock (" + hostLocks.Count + " places)");
Check.Eq(hostLocks.Count, 9, "the host takes the launcher's lock in exactly 9 places");
foreach (var (target, body) in hostLocks)
{
Check.Eq(target, "_web.Gate", "every lock in the host is lock (_web.Gate)");
Check.Eq(string.Join(" ", CallsNotOn(body, "_web")), "", "only _web members under lock (_web.Gate): " + Collapse(body));
}
// Each lock body, exactly: launcher calls and reads, nothing else (no host property read either).
string[] lockBodies =
{
"{begun=_web.Begin(d,Environment.TickCount64);status=_web.Status;}", // StartLaunch
"_web.Cancel(notSent);", // StartLaunch, send failed
"{kind=_web.OnChatLine(text,chatType,Environment.TickCount64,outd,outlaunchCode,out_);status=_web.Status;generation=_web.Generation;}", // ServerChatText
"_web.SetResult(generation,text);", // SetWebResult
"{timedOut=_web.TakeTimedOut(Environment.TickCount64);status=_web.Status;}", // ServerTick
"status=_web.Status;", // ServerInfoLines
"_web.Reset();", // ServerLoginComplete
"_web.Reset();", // ServerLogout
"_web.Reset();", // ServerShutdown
};
Check.Eq(string.Join("\n", hostLocks.Select(l => Collapse(l.Body))), string.Join("\n", lockBodies), "the host's lock bodies, exactly");
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");
@ -319,8 +354,11 @@ internal static class DreamWeaveWebTests
string chat = chatHook.Count == 1 ? chatHook[0] : "";
int onChat = chat.IndexOf("OnChatLine(", StringComparison.Ordinal);
Check.True(onChat > 0, "ServerChatText calls OnChatLine");
Check.False(onChat > 0 && System.Text.RegularExpressions.Regex.IsMatch(chat.Substring(0, onChat), @"(?<![A-Za-z0-9_])Active(?![A-Za-z0-9_])"),
"ServerChatText checks no Active before OnChatLine (a code must be eaten whatever the world is now)");
// Everything before the lock, exactly: declarations only, so no gate, return or throw comes first.
System.Text.RegularExpressions.Match firstLock = System.Text.RegularExpressions.Regex.Match(chat, @"\block\s*\(");
Check.Eq(firstLock.Success ? Collapse(chat.Substring(0, firstLock.Index)) : "<no lock>",
"{LaunchLinekind=LaunchLine.NotOurs;try{WebDestination?d;stringlaunchCode;stringstatus;longgeneration;",
"ServerChatText: nothing but declarations before the launcher reads the line (a code must be eaten whatever the world is now)");
// Stale eats the line and does nothing else.
int stale = host.IndexOf("case LaunchLine.Stale:", StringComparison.Ordinal);
@ -387,6 +425,8 @@ internal static class DreamWeaveWebTests
Check.Eq(locks[1].Target, "other", "another target is reported as it is");
Check.Eq(string.Join(" ", CallsNotOn(locks[2].Body, "_web")), "if( b(", "keywords and helpers are not launcher calls");
Check.Eq(string.Join(" ", CallsNotOn("x._web.Begin(); _web.Begin(); _web.Gate.Foo();", "_web")), "x._web.Begin( _web.Gate.Foo(", "only a direct _web member call is allowed");
Check.Eq(string.Join(" ", CallsNotOn("a?.Invoke(x); Notify<int>(y); _web.Begin();", "_web")), "a?.Invoke( Notify(", "null-conditional and generic calls are calls");
Check.Eq(string.Join(" ", CallsNotOn("_web?.Begin(); _web.Begin<int>();", "_web")), "_web?.Begin(", "_web?. is not the allowed form; a generic _web member call is");
}
private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars

View file

@ -74,7 +74,7 @@ internal static class ServerPackCommandsTests
// DreamWeave's verbs follow the shared two.
string[] dw = ServerPackCommands.Usage("DreamWeave", new List<string> { RynthCore.Plugin.RynthDreamWeave.DreamWeaveWeb.UsageLine() });
Check.Eq(dw.Length, 3, "DreamWeave: three usage lines");
Check.Eq(dw[2], "/rserver market | suit | abilities - open the website's Market, Suit Builder, Ability Planner, logged in as this account.", "DreamWeave's own line");
Check.Eq(dw[2], "/rserver market | suit | abilities - open the website's Market, Suit Builder or Ability Planner, logged in as this account.", "DreamWeave's own line");
Check.True(dw[0] == ServerPackCommands.Usage("DreamWeave")[0] && dw[1] == ServerPackCommands.Usage("DreamWeave")[1], "the shared two come first, unchanged");
}