RynthDreamWeave: Task 6 review fixes (code never to chat, allow-list scan, result generation)

- ServerChatText reads every line through the launcher, with no Active
  gate first: a code answering our request is eaten whatever the world is
  now, and opens nothing when the world is no longer DreamWeave.
- WebLauncher: a generation token (Begin when Started, Reset) and
  SetResult(generation, status), which replaces the status compare and
  the use of Cancel as a status setter. The no-panel note is once per
  login epoch, so an answer from an earlier login can't spend it.
- An open failure reads "Market: Couldn't open your browser (code N)."
- StartLaunch's catch answers "Couldn't start the web open."
- ServerUsageLines: an optional shared hook for a server's own usage
  lines; DreamWeave lists market | suit | abilities. Hookless servers
  print the same two lines as before (pinned on Coldeve).
- The source scan is allow-lists: every lock is on the launcher's Gate
  and calls only its members, the Stale arm is exactly eat = true, Draw
  calls only ImGui, SafeImGui and click. Comments are stripped without
  touching string literals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 15:22:09 -08:00
commit 5fbbf4e654
5 changed files with 297 additions and 80 deletions

View file

@ -26,8 +26,10 @@ 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;
// Counts logins, so an answer from before a relog never spends this login's "no web panel" line.
private int _webLoginEpoch;
// The login that has had the "no in-game web panel" line (set from OpenWeb's done, any thread).
private int _webNoPanelNotedEpoch;
// The card's draw failure, logged once rather than every frame (render thread only).
private bool _webDrawFailed;
@ -45,6 +47,18 @@ public sealed partial class ServerPackPlugin
}
}
partial void ServerUsageLines(Action<string> add)
{
try
{
add(DreamWeaveWeb.UsageLine());
}
catch (Exception)
{
// The constructor has no Host to log to yet; the destinations are constants.
}
}
partial void ServerCardActions()
{
try
@ -117,23 +131,33 @@ public sealed partial class ServerPackPlugin
}
catch (Exception ex)
{
LogTagged("Starting a web open failed: " + ex.GetType().Name);
try
{
LogTagged("Starting a web open failed: " + ex.GetType().Name);
Reply.Fail("Couldn't start the web open.");
}
catch (Exception)
{
}
}
}
private void WebChatText(string text, int chatType, ref bool eat)
{
// No Active check before the launcher: only a request it began (or its stale window) is ever
// not NotOurs, and a code that answers one must be eaten whatever the world is now.
LaunchLine kind = LaunchLine.NotOurs;
try
{
if (!Active) return;
WebDestination? d;
string launchCode;
string status;
long generation;
lock (_web.Gate)
{
kind = _web.OnChatLine(text, chatType, Environment.TickCount64, out d, out launchCode, out _);
status = _web.Status;
generation = _web.Generation;
}
switch (kind)
{
@ -149,7 +173,13 @@ public sealed partial class ServerPackPlugin
return;
case LaunchLine.Code:
eat = true;
if (d != null) OpenLaunch(d, DreamWeaveWeb.LaunchUrl(launchCode, d), status);
if (d == null) return;
if (!Active)
{
WebOpenFailed(d, generation, WebButtons.NotDreamWeave);
return;
}
OpenLaunch(d, DreamWeaveWeb.LaunchUrl(launchCode, d), generation);
return;
}
}
@ -162,11 +192,12 @@ public sealed partial class ServerPackPlugin
}
/// <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.
/// Opens the launch URL (pump thread). <paramref name="generation"/> is the request the code answered;
/// the open's answer replaces its "Opening X..." status (SetResult), so the card never stays on it.
/// </summary>
private void OpenLaunch(WebDestination d, string url, string opening)
private void OpenLaunch(WebDestination d, string url, long generation)
{
int epoch = Volatile.Read(ref _webLoginEpoch);
try
{
string? account = Host.TryGetAccountName(out string name) ? name : null;
@ -175,23 +206,23 @@ public sealed partial class ServerPackPlugin
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));
OpenWeb(request, outcome => WebOpened(d, outcome, why, generation, epoch));
}
catch (Exception ex)
{
LogTagged("Opening a web page failed: " + ex.GetType().Name);
WebOpenFailed(d, "Couldn't open " + d.Label + ".", opening);
WebOpenFailed(d, generation, "Couldn't open " + d.Label + ".");
}
}
/// <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)
private void WebOpened(WebDestination d, WebOpenOutcome outcome, WebBrowserWhy why, long generation, int epoch)
{
try
{
if (!outcome.Ok)
{
WebOpenFailed(d, "Couldn't open " + d.Label + ": " + outcome.Message, opening);
WebOpenFailed(d, generation, d.Label + ": " + outcome.Message);
return;
}
@ -201,7 +232,8 @@ public sealed partial class ServerPackPlugin
else if (why == WebBrowserWhy.NoPanel)
{
text = "Opened " + d.Label + ".";
if (Interlocked.Exchange(ref _webNoPanelNoted, 1) == 0)
// Once per login, and never spent by an answer from an earlier login.
if (epoch == Volatile.Read(ref _webLoginEpoch) && Interlocked.Exchange(ref _webNoPanelNotedEpoch, epoch) != epoch)
note = "This RynthCore has no in-game web panel, so " + d.Label + " opened in your browser.";
}
else if (why == WebBrowserWhy.NoAccount)
@ -209,7 +241,7 @@ public sealed partial class ServerPackPlugin
else
text = "Opened " + d.Label + " in your browser: the web panel didn't take it.";
ReplaceOpeningStatus(opening, text);
SetWebResult(generation, text);
Reply.Ok(text);
if (note != null) Reply.Ok(note);
}
@ -219,11 +251,11 @@ public sealed partial class ServerPackPlugin
}
}
private void WebOpenFailed(WebDestination d, string text, string opening)
private void WebOpenFailed(WebDestination d, long generation, string text)
{
try
{
ReplaceOpeningStatus(opening, text);
SetWebResult(generation, text);
Reply.Fail(text);
}
catch (Exception)
@ -231,17 +263,10 @@ public sealed partial class ServerPackPlugin
}
}
/// <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)
/// <summary>The open's answer as the card's status, unless a newer request (or a relog) has taken over since.</summary>
private void SetWebResult(long generation, string text)
{
lock (_web.Gate)
{
if (_web.Pending == null && _web.Status == opening) _web.Cancel(text);
}
lock (_web.Gate) _web.SetResult(generation, text);
}
private void WebTick()
@ -249,11 +274,11 @@ public sealed partial class ServerPackPlugin
try
{
WebDestination? timedOut;
string status = "";
string status;
lock (_web.Gate)
{
timedOut = _web.TakeTimedOut(Environment.TickCount64);
if (timedOut != null) status = _web.Status;
status = _web.Status;
}
if (timedOut != null) Reply.Fail(status);
}
@ -282,7 +307,7 @@ public sealed partial class ServerPackPlugin
try
{
lock (_web.Gate) _web.Reset();
Interlocked.Exchange(ref _webNoPanelNoted, 0);
Interlocked.Increment(ref _webLoginEpoch);
}
catch (Exception ex)
{