diff --git a/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/WebProfile.cs b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/WebProfile.cs
new file mode 100644
index 0000000..d799222
--- /dev/null
+++ b/Plugins/RynthCore.Plugin.RynthDreamWeave/DreamWeave/WebProfile.cs
@@ -0,0 +1,23 @@
+// The per-account web profile key: each account gets its own WebView2 profile folder, so website
+// cookies never cross accounts. Pure, so RynthServerPack.Tests compiles it directly.
+using System;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace RynthCore.Plugin.RynthDreamWeave;
+
+internal static class WebProfile
+{
+ ///
+ /// "serverId/" plus the first 32 lowercase hex chars of SHA-256(UTF-8(serverId + "\n" + the trimmed,
+ /// lower-cased account)); null when there is no account. The server id (not the world name) keeps
+ /// one site's cookies together. The hash keeps the account name out of the folder name. The result
+ /// passes ServerWebOpen.IsValidProfileKey when serverId matches ^[a-z0-9-]{1,32}$.
+ ///
+ public static string? Key(string serverId, string? account)
+ {
+ if (string.IsNullOrWhiteSpace(account)) return null;
+ byte[] hash = SHA256.HashData(Encoding.UTF8.GetBytes(serverId + "\n" + account.Trim().ToLowerInvariant()));
+ return serverId + "/" + Convert.ToHexString(hash).ToLowerInvariant().Substring(0, 32);
+ }
+}
diff --git a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs
index 3fb1378..dfbc215 100644
--- a/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs
+++ b/Tools/RynthServerPack.Tests/DreamWeaveWebTests.cs
@@ -27,6 +27,7 @@ internal static class DreamWeaveWebTests
r.Add("dreamweave web: reset keeps the throttle", ResetKeepsThrottle);
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);
}
private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars
@@ -354,6 +355,30 @@ internal static class DreamWeaveWebTests
Check.True(u.OnChatLine(Line, 0x05, 70_000, out _, out _, out _) == LaunchLine.NotOurs, "+70,000 not ours");
}
+ private static void ProfileKeys()
+ {
+ string? a = WebProfile.Key("dreamweave", "Alice");
+ string? b = WebProfile.Key("dreamweave", "Bob");
+ Check.True(a != null && b != null, "keys exist");
+ Check.True(a != b, "different accounts -> different keys");
+ Check.Eq(WebProfile.Key("dreamweave", " alice "), a, "trimmed and case-folded");
+ Check.Eq(WebProfile.Key("dreamweave", "ALICE"), a, "case-folded");
+ Check.Eq(WebProfile.Key("dreamweave", "Alice"), a, "stable across calls");
+ Check.True(WebProfile.Key("coldeve", "Alice") != a, "same account, other server -> different key");
+ Check.True(a!.StartsWith("dreamweave/", StringComparison.Ordinal), "prefixed by the server id");
+ string[] accounts = { "Alice", "Bob", "a", "x y", "caf" + (char)0xE9, "A-very-long-account-name-0123456789-0123456789-0123456789" };
+ foreach (string acct in accounts)
+ {
+ string? k = WebProfile.Key("dreamweave", acct);
+ Check.True(ServerWebOpen.IsValidProfileKey(k), "valid key for " + acct.Length + " chars");
+ // A 1-2 char account could appear in the server id or the hex by chance; the rest cannot.
+ if (acct.Length >= 3) Check.True(!k!.Contains(acct.Trim().ToLowerInvariant()), "key never contains the account text");
+ }
+ Check.True(WebProfile.Key("dreamweave", null) == null, "null account -> null");
+ Check.True(WebProfile.Key("dreamweave", "") == null, "empty account -> null");
+ Check.True(WebProfile.Key("dreamweave", " ") == null, "blank account -> null");
+ }
+
private static void OverlappingRequests()
{
// Scenario 1: request 1 times out, request 2 begins, request 1's late code arrives.
diff --git a/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj b/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj
index 1fb19fa..68c8d8a 100644
--- a/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj
+++ b/Tools/RynthServerPack.Tests/RynthServerPack.Tests.csproj
@@ -38,6 +38,7 @@
+