DreamWeave: web links open the stage site on the stage world #5

Open
AwfulWaffle wants to merge 1 commit from AwfulWaffle/RynthServers:dreamweave-stage-site into main
3 changed files with 53 additions and 6 deletions
Showing only changes of commit ceb2c6a14b - Show all commits

DreamWeave: web links open the stage site on the stage world

A launch code is minted in the shard of the world that answered /weblogin, so a DreamWeave-Stage code opened on www.acdreamweave.com reports "expired or already used". The plugin now picks www-stage.acdreamweave.com and a stage-only allowlist when the engine reports world DreamWeave-Stage; any other or unknown world keeps the live site. The world is read once so the URL and allowlist always agree. Tests pin the helpers and the plugin wiring.

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

View file

@ -14,9 +14,30 @@ internal static class DreamWeaveWeb
{ {
public const string SiteBase = "https://www.acdreamweave.com"; public const string SiteBase = "https://www.acdreamweave.com";
/// <summary>The only host the panel or the browser may be sent to.</summary> /// <summary>The only host the panel or the browser may be sent to on the live world.</summary>
public static readonly string[] AllowedHosts = { "www.acdreamweave.com" }; public static readonly string[] AllowedHosts = { "www.acdreamweave.com" };
/// <summary>
/// The stage world's site. A launch code is minted in the shard of the world that answered
/// "/weblogin", so it only redeems on that world's site: a stage code sent to the live site is
/// "expired or already used". (market-stage.acdreamweave.com only 301s to www-stage.)
/// </summary>
public const string StageSiteBase = "https://www-stage.acdreamweave.com";
/// <summary>The only host the panel or the browser may be sent to on the stage world.</summary>
public static readonly string[] StageAllowedHosts = { "www-stage.acdreamweave.com" };
/// <summary>The stage server's world name (ACE deploy/stage/Config.js.template).</summary>
public const string StageWorldName = "DreamWeave-Stage";
/// <summary>True for the stage world. Anything else, unknown included, is the live site.</summary>
public static bool IsStageWorld(string? worldName)
=> worldName != null && string.Equals(worldName.Trim(), StageWorldName, StringComparison.OrdinalIgnoreCase);
public static string SiteBaseFor(string? worldName) => IsStageWorld(worldName) ? StageSiteBase : SiteBase;
public static string[] AllowedHostsFor(string? worldName) => IsStageWorld(worldName) ? StageAllowedHosts : AllowedHosts;
public const string PanelTitle = "DreamWeave"; public const string PanelTitle = "DreamWeave";
public static readonly WebDestination[] Destinations = public static readonly WebDestination[] Destinations =
@ -70,6 +91,6 @@ internal static class DreamWeaveWeb
} }
/// <summary>The sign-in URL for a destination. The caller has already checked the code with LaunchWire.</summary> /// <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) public static string LaunchUrl(string code, WebDestination d, string? worldName = null)
=> SiteBase + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path); => SiteBaseFor(worldName) + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path);
} }

View file

@ -193,7 +193,8 @@ public sealed partial class ServerPackPlugin
WebOpenFailed(d, generation, WebButtons.NotDreamWeave); WebOpenFailed(d, generation, WebButtons.NotDreamWeave);
return; return;
} }
OpenLaunch(d, DreamWeaveWeb.LaunchUrl(launchCode, d), generation); string? world = WorldName(); // read once: the URL and the allowlist always name the same site
OpenLaunch(d, DreamWeaveWeb.LaunchUrl(launchCode, d, world), world, generation);
return; return;
} }
} }
@ -205,17 +206,21 @@ public sealed partial class ServerPackPlugin
} }
} }
/// <summary>The connected world's name, or null when the engine can't say (then the live site is used).</summary>
private string? WorldName() => Host.TryGetWorldName(out string w) ? w : null;
/// <summary> /// <summary>
/// Opens the launch URL (pump thread). <paramref name="generation"/> is the request the code answered; /// 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. /// the open's answer replaces its "Opening X..." status (SetResult), so the card never stays on it.
/// <paramref name="world"/> is the world the URL was built for; the allowlist comes from the same value.
/// </summary> /// </summary>
private void OpenLaunch(WebDestination d, string url, long generation) private void OpenLaunch(WebDestination d, string url, string? world, long generation)
{ {
int epoch = Volatile.Read(ref _webLoginEpoch); int epoch = Volatile.Read(ref _webLoginEpoch);
try try
{ {
string? account = Host.TryGetAccountName(out string name) ? name : null; string? account = Host.TryGetAccountName(out string name) ? name : null;
var request = new WebOpenRequest(url, DreamWeaveWeb.AllowedHosts, var request = new WebOpenRequest(url, DreamWeaveWeb.AllowedHostsFor(world),
WebProfile.Key(Info.Id, account) ?? "", DreamWeaveWeb.PanelTitle); WebProfile.Key(Info.Id, account) ?? "", DreamWeaveWeb.PanelTitle);
bool panel = PanelAvailable; bool panel = PanelAvailable;
WebBrowserWhy why = ServerWebOpen.Route(request, panel) != WebOpenRoute.Browser ? WebBrowserWhy.PanelFellBack WebBrowserWhy why = ServerWebOpen.Route(request, panel) != WebOpenRoute.Browser ? WebBrowserWhy.PanelFellBack

View file

@ -403,6 +403,10 @@ internal static class DreamWeaveWebTests
Check.Eq(uses, 3, "launchCode: declared, filled by OnChatLine, used once (DreamWeaveWeb.LaunchUrl)"); 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.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"); Check.True(host.Contains("DreamWeaveWeb.LaunchUrl(launchCode, ", StringComparison.Ordinal), "the code's one use is the launch URL");
// Stage routing: the URL and the allowlist both come from the one world read.
Check.True(host.Contains("DreamWeaveWeb.LaunchUrl(launchCode, d, world)", StringComparison.Ordinal), "the launch URL is built for the connected world");
Check.True(host.Contains("DreamWeaveWeb.AllowedHostsFor(world)", StringComparison.Ordinal), "the allowlist is the same world's");
Check.False(System.Text.RegularExpressions.Regex.IsMatch(host, @"DreamWeaveWeb\.AllowedHosts\s*[,)]"), "the live-only allowlist is never passed directly");
// The chat hook reads every line through the launcher, whatever the world: no Active before OnChatLine. // The chat hook reads every line through the launcher, whatever the world: no Active before OnChatLine.
List<string> chatHook = StatementsAfter(host, "private void WebChatText(string text, int chatType, ref bool eat)"); List<string> chatHook = StatementsAfter(host, "private void WebChatText(string text, int chatType, ref bool eat)");
@ -587,6 +591,23 @@ internal static class DreamWeaveWebTests
Check.Eq(DreamWeaveWeb.LaunchUrl(Code, DreamWeaveWeb.ById("abilities")!), Check.Eq(DreamWeaveWeb.LaunchUrl(Code, DreamWeaveWeb.ById("abilities")!),
DreamWeaveWeb.SiteBase + "/launch?code=" + Code + "&to=%2Fplay%2Fabilities", "abilities opens the live class ability page"); DreamWeaveWeb.SiteBase + "/launch?code=" + Code + "&to=%2Fplay%2Fabilities", "abilities opens the live class ability page");
// The stage world's code only redeems on the stage site, and the stage panel may only go there.
Check.Eq(DreamWeaveWeb.LaunchUrl(Code, DreamWeaveWeb.ById("abilities")!, "DreamWeave-Stage"),
"https://www-stage.acdreamweave.com/launch?code=" + Code + "&to=%2Fplay%2Fabilities", "stage world -> stage site");
Check.True(DreamWeaveWeb.IsStageWorld(" dreamweave-stage "), "stage match is trimmed and case-insensitive");
foreach (string? live in new[] { "DreamWeave", "Dream Weave", "", null, "DreamWeave-Stage2" })
{
Check.Eq(DreamWeaveWeb.SiteBaseFor(live), DreamWeaveWeb.SiteBase, "'" + live + "' -> live site");
Check.True(DreamWeaveWeb.AllowedHostsFor(live) == DreamWeaveWeb.AllowedHosts, "'" + live + "' -> live allowlist");
}
foreach (WebDestination d in DreamWeaveWeb.Destinations)
{
string su = DreamWeaveWeb.LaunchUrl(Code, d, DreamWeaveWeb.StageWorldName);
Check.True(ServerWebOpen.IsAllowedUrl(su, DreamWeaveWeb.AllowedHostsFor(DreamWeaveWeb.StageWorldName)), d.Id + ": stage url passes the stage allowlist");
Check.True(!ServerWebOpen.IsAllowedUrl(su, DreamWeaveWeb.AllowedHosts), d.Id + ": stage url refused by the live allowlist");
Check.True(!ServerWebOpen.IsAllowedUrl(DreamWeaveWeb.LaunchUrl(Code, d), DreamWeaveWeb.StageAllowedHosts), d.Id + ": live url refused by the stage allowlist");
}
foreach (WebDestination d in DreamWeaveWeb.Destinations) foreach (WebDestination d in DreamWeaveWeb.Destinations)
{ {
string u = DreamWeaveWeb.LaunchUrl(Code, d); string u = DreamWeaveWeb.LaunchUrl(Code, d);