diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs index b4ca7b1..6cf8ee1 100644 --- a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs +++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/DreamWeaveWeb.cs @@ -14,9 +14,30 @@ internal static class DreamWeaveWeb { public const string SiteBase = "https://www.acdreamweave.com"; - /// The only host the panel or the browser may be sent to. + /// The only host the panel or the browser may be sent to on the live world. public static readonly string[] AllowedHosts = { "www.acdreamweave.com" }; + /// + /// 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.) + /// + public const string StageSiteBase = "https://www-stage.acdreamweave.com"; + + /// The only host the panel or the browser may be sent to on the stage world. + public static readonly string[] StageAllowedHosts = { "www-stage.acdreamweave.com" }; + + /// The stage server's world name (ACE deploy/stage/Config.js.template). + public const string StageWorldName = "DreamWeave-Stage"; + + /// True for the stage world. Anything else, unknown included, is the live site. + 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 static readonly WebDestination[] Destinations = @@ -70,6 +91,6 @@ internal static class DreamWeaveWeb } /// The sign-in URL for a destination. The caller has already checked the code with LaunchWire. - public static string LaunchUrl(string code, WebDestination d) - => SiteBase + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path); + public static string LaunchUrl(string code, WebDestination d, string? worldName = null) + => SiteBaseFor(worldName) + "/launch?code=" + code + "&to=" + Uri.EscapeDataString(d.Path); } diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs index d690cc5..89f8f36 100644 --- a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs +++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeaveWebTools.cs @@ -193,7 +193,8 @@ public sealed partial class ServerPackPlugin WebOpenFailed(d, generation, WebButtons.NotDreamWeave); 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; } } @@ -205,17 +206,21 @@ public sealed partial class ServerPackPlugin } } + /// The connected world's name, or null when the engine can't say (then the live site is used). + private string? WorldName() => Host.TryGetWorldName(out string w) ? w : null; + /// /// Opens the launch URL (pump thread). is the request the code answered; /// the open's answer replaces its "Opening X..." status (SetResult), so the card never stays on it. + /// is the world the URL was built for; the allowlist comes from the same value. /// - 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); try { 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); bool panel = PanelAvailable; WebBrowserWhy why = ServerWebOpen.Route(request, panel) != WebOpenRoute.Browser ? WebBrowserWhy.PanelFellBack diff --git a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs index 0855812..25d97cd 100644 --- a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs +++ b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs @@ -403,6 +403,10 @@ internal static class DreamWeaveWebTests 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"); + // 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. List 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")!), 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) { string u = DreamWeaveWeb.LaunchUrl(Code, d);