From a2308ce3333b368a9e4eac70272c377557d9dd50 Mon Sep 17 00:00:00 2001 From: zj1022 Date: Wed, 18 Nov 2026 17:09:35 +0800 Subject: [PATCH] fix: browse accounts in relational saves Read current character, ascendancy and stash rows while keeping offline mutations on the existing storage contract. The reported layout failure was reproduced while checking mingyue8621/Waypoint commit cc32bd7. --- docs/launcher.md | 1 + docs/runtime-contract.md | 2 + scripts/AccountData.py | 55 ++++++++++++++++++- src/Launcher.Core/Resources/Strings.resx | 3 + src/Launcher.Core/Resources/Strings.ru.resx | 3 + .../Resources/Strings.zh-CN.resx | 3 + tests/AccountData.Tests.py | 37 +++++++++++++ 7 files changed, 102 insertions(+), 2 deletions(-) diff --git a/docs/launcher.md b/docs/launcher.md index 942662c..d1b86c8 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -1530,6 +1530,7 @@ A Gateway built before the mode would start for real, so Waypoint first asks `co The list is read from the checkout's save database (`auth.db` and `characters.db` from LocalExile's database split on, or an old `saves.db` until the servers migrate it) through the adapter, with nothing running or built: every account with its characters, nothing secret. Showing the section reads it; **Reload accounts** reads it again. +The relational save layout supports browsing accounts, characters, ascendancies and stash counts in this section. **Register** and **Create** are the dev protocol's `register`, `login` and `create_character` (the server's GettingStarted step 8), so they work beside running servers. The character is created in Standard; the game's own creation screen offers diff --git a/docs/runtime-contract.md b/docs/runtime-contract.md index 3edc465..8e0427d 100644 --- a/docs/runtime-contract.md +++ b/docs/runtime-contract.md @@ -44,6 +44,8 @@ loading code. Old builds launched after a newer app cannot be forced to particip `QueryAccounts` returns an optional typed `AccountData` inventory and never initializes/migrates storage. Browsing uses one read-only SQLite snapshot; it exposes names, IDs, character summaries and opaque revision tokens, never credential verifiers. A snapshot's `AccountWriteBlockedReason` explains runtime blockers, including the account service. +For the relational save layout, browsing uses `auth.accounts`, current character and ascendancy rows, and stash tab headers. +The relational layout is read-only in the offline account helper. `ManageAccount` accepts a reviewed `AccountDataRequest` on UTF-8 stdin. Its required `ExpectedDatabase` must match the selected profile's resolved database before backup or mutation; desktop registration requests carry the same diff --git a/scripts/AccountData.py b/scripts/AccountData.py index 54ba326..64eb5a9 100644 --- a/scripts/AccountData.py +++ b/scripts/AccountData.py @@ -2,7 +2,8 @@ Storage contract: LocalExile main 89b7aa908213ac8eb9b5ac5aa7ae54c14189c3e9 (one saves.db), and from the database split on (LocalExile/LocalExile#758) characters.db with the accounts in auth.db, which this helper attaches as `auth` the way the -servers do. A change across both files commits in each file on its own: RuntimeBridge backs both up first. +servers do. The relational characters database is supported for browsing. A change across both files commits in +each file on its own: RuntimeBridge backs both up first. This helper never initializes schemas, runs emulator code, or manages processes/backups. RuntimeBridge supplies ownership checks, writer serialization and the backup policy. """ @@ -232,11 +233,56 @@ def catalog(accounts, writable, root, can_register=False): "Ascendancy": asc, "League": data.get("League", ""), "LastPlayedUtc": data.get("LastPlayedUtc", ""), "HasProgress": ch["save"] is not None}) result.append({"Id": a["id"], "Name": a["name"], "CreatedUtc": a["data"].get("CreatedUtc", ""), - "Revision": a["revision"], "Characters": characters, "StashTabs": len(a["tabs"])}) + "Revision": a["revision"], "Characters": characters, "StashTabs": a.get("tab_count", len(a["tabs"]))}) return {"Exists": True, "Writable": writable, "CanRegister": can_register, "Notice": "" if writable else "This storage layout can be browsed, but account changes are disabled because its schema or import state is unfamiliar.", "Accounts": result} +def relational_catalog(db, root): + """Read the current layout without using the retained pre-migration character and stash rows.""" + accounts = [] + for row in db.execute("SELECT id,name,account FROM auth.accounts ORDER BY name COLLATE NOCASE,id LIMIT 2001"): + entry = record(row["account"]) + require(entry.get("Id") == row["id"] and entry.get("Name") == row["name"], "Account identity columns and JSON disagree.") + accounts.append({"id": identity(row["id"]), "name": row["name"], "data": entry, + "characters": [], "tabs": [], "tab_count": 0, "revision": ""}) + require(len(accounts) <= 2000, "Too many accounts for this version of the account manager.") + owners = {a["id"]: a for a in accounts} + by_name = {fold(a["name"]): a for a in accounts} + require(len(owners) == len(accounts) and len(by_name) == len(accounts), "Account identities or names are not unique.") + characters = db.execute(""" + SELECT c.id, c.account_id, c.name, c.class, c.level, c.league, c.last_played_utc, + s.id AS active_save, a.family, a.ascendancy + FROM main.account_characters c + LEFT JOIN main.character_saves s ON s.name=c.name AND s.deleted_utc IS NULL + LEFT JOIN main.character_ascendancies a ON a.save=s.id + ORDER BY c.created_utc,c.id LIMIT 48001 + """).fetchall() + require(len(characters) <= 48000, "Too many characters for this version of the account manager.") + for row in characters: + identity(row["id"]) + require(row["account_id"] in owners, "A character points to an account that is missing.") + selection = {"Id": row["ascendancy"], "Family": row["family"]} + owners[row["account_id"]]["characters"].append({ + "id": row["id"], "name": row["name"], "save": row["active_save"], + "data": {"Class": row["class"], "Level": row["level"], "League": row["league"], "LastPlayedUtc": row["last_played_utc"]}, + "progress": {"MainAscendancy": {"Selection": selection}}, + }) + for key, count in db.execute(""" + SELECT s.account, COUNT(*) FROM main.stash_saves s + JOIN main.stash_tab_headers t ON t.stash=s.id GROUP BY s.id + """): + plain = key[6:] if fold(key).startswith("guild:") else key + candidates = {plain, plain.split(" (", 1)[0]} if plain.endswith(")") else {plain} + matches = [by_name[fold(n)] for n in candidates if fold(n) in by_name] + require(len(matches) <= 1, "A stash key has ambiguous account ownership.") + if matches: + matches[0]["tab_count"] += count + result = catalog(accounts, False, root) + result["Notice"] = "This save format supports browsing here. Use LocalExile to manage accounts." + return result + + def credentials(password): require(isinstance(password, str), "Password must contain 4-1024 characters.") try: @@ -361,6 +407,11 @@ def run(path, root, request, auth=None): db.execute("PRAGMA foreign_keys=ON") db.execute("BEGIN" if action == "List" else "BEGIN IMMEDIATE") try: + if split(db) and db.execute("SELECT 1 FROM main.sqlite_master WHERE type='table' AND name='character_saves'").fetchone(): + require(action == "List", "Account changes are disabled for this unfamiliar storage layout or pending account import.") + result = relational_catalog(db, root) + db.execute("COMMIT") + return result accounts, writable = snapshot(db) if action != "List": require(writable, "Account changes are disabled for this unfamiliar storage layout or pending account import.") diff --git a/src/Launcher.Core/Resources/Strings.resx b/src/Launcher.Core/Resources/Strings.resx index 5961f99..5a5c35b 100644 --- a/src/Launcher.Core/Resources/Strings.resx +++ b/src/Launcher.Core/Resources/Strings.resx @@ -2118,6 +2118,9 @@ This checkout has modified tracked files. Trap gauntlet + + This save format supports browsing here. Use LocalExile to manage accounts. + Appearance diff --git a/src/Launcher.Core/Resources/Strings.ru.resx b/src/Launcher.Core/Resources/Strings.ru.resx index 32a45e7..97b32c1 100644 --- a/src/Launcher.Core/Resources/Strings.ru.resx +++ b/src/Launcher.Core/Resources/Strings.ru.resx @@ -2118,6 +2118,9 @@ Коридор ловушек + + Здесь можно просматривать сохранения этого формата. Управляйте аккаунтами в LocalExile. + Оформление diff --git a/src/Launcher.Core/Resources/Strings.zh-CN.resx b/src/Launcher.Core/Resources/Strings.zh-CN.resx index 96ca2fd..12a8dff 100644 --- a/src/Launcher.Core/Resources/Strings.zh-CN.resx +++ b/src/Launcher.Core/Resources/Strings.zh-CN.resx @@ -2118,6 +2118,9 @@ 陷阱通道 + + 此存档格式支持在此浏览。请在 LocalExile 中管理账号。 + 外观 diff --git a/tests/AccountData.Tests.py b/tests/AccountData.Tests.py index 8c174e7..32eddf4 100644 --- a/tests/AccountData.Tests.py +++ b/tests/AccountData.Tests.py @@ -91,6 +91,43 @@ def test_missing_database_is_not_created(self): self.assertFalse(data.run(path, self.root, {"Action": "List"})["Exists"]) self.assertFalse(path.exists()) + def test_relational_listing_uses_active_saves_and_keeps_both_databases_read_only(self): + auth = self.root / "auth.db" + characters = self.root / "characters.db" + with connect(auth) as db: + db.execute("CREATE TABLE accounts(id TEXT PRIMARY KEY,name TEXT,account TEXT)") + db.execute("INSERT INTO accounts VALUES(?,?,?)", (self.account, "Alpha", json.dumps({ + "Id": self.account, "Name": "Alpha", "PasswordHash": "private-verifier", + }))) + with connect(characters) as db: + db.executescript(""" + CREATE TABLE account_characters(id TEXT PRIMARY KEY, account_id TEXT, name TEXT, class INTEGER, + level INTEGER, league TEXT, created_utc TEXT, last_played_utc TEXT); + CREATE TABLE character_saves(id INTEGER PRIMARY KEY, name TEXT COLLATE NOCASE, deleted_utc TEXT); + CREATE TABLE character_ascendancies(save INTEGER PRIMARY KEY, family TEXT, ascendancy TEXT); + CREATE TABLE stash_saves(id INTEGER PRIMARY KEY, account TEXT); + CREATE TABLE stash_tab_headers(stash INTEGER, tab INTEGER, PRIMARY KEY(stash,tab)); + INSERT INTO character_saves VALUES (1,'newhero','deleted'), (2,'newhero',NULL); + INSERT INTO character_ascendancies VALUES (1,'Normal','OldWitch'), (2,'Normal','Witch3'); + INSERT INTO stash_saves VALUES (1,'Alpha (Allflame)'), (2,'AlphaOther'); + INSERT INTO stash_tab_headers VALUES (1,0), (1,1), (2,0); + """) + db.execute("INSERT INTO account_characters VALUES(?,?,?,?,?,?,?,?)", + (self.char, self.account, "NewHero", 3, 77, "Allflame", "2026-01-01", "2026-02-01")) + before = (auth.read_bytes(), characters.read_bytes()) + view = data.run(characters, self.root, {"Action": "List"}, auth) + self.assertFalse(view["Writable"]) + self.assertFalse(view["CanRegister"]) + account, = view["Accounts"] + self.assertEqual(account["StashTabs"], 2) + char, = account["Characters"] + self.assertEqual((char["Name"], char["Ascendancy"], char["Level"], char["HasProgress"]), + ("NewHero", "Elementalist", 77, True)) + self.assertNotIn("private-verifier", json.dumps(view)) + with self.assertRaisesRegex(data.AccountError, "Account changes are disabled"): + data.run(characters, self.root, {"Action": "Rename"}, auth) + self.assertEqual(before, (auth.read_bytes(), characters.read_bytes())) + def test_ascendancy_fallback_and_phrecia(self): with connect(self.path) as db: value = json.loads(db.execute("SELECT save FROM characters").fetchone()[0])