Room codes also dodge orphaned files on disk
makeRoomCode checked only the in-memory map, which covers every live and restored room — but a file that failed to restore stays on disk with no map entry, and a new room taking its code would append a second game into the orphaned file, corrupting both. The generator now rerolls on disk presence too. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
bed29c4992
commit
28bc91c3ac
@@ -3,7 +3,7 @@
|
||||
// command. Because the engine is deterministic, replaying a file rebuilds
|
||||
// the exact game state — server restarts lose nothing.
|
||||
|
||||
import { appendFileSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
||||
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
export interface RoomMetaLine {
|
||||
@@ -60,6 +60,11 @@ export function ensureDataDir(): void {
|
||||
mkdirSync(DATA_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
/** A room file may exist even when the room failed to restore into memory. */
|
||||
export function roomFileExists(roomId: string): boolean {
|
||||
return existsSync(fileFor(roomId));
|
||||
}
|
||||
|
||||
export function appendLine(roomId: string, line: RoomLine): void {
|
||||
appendFileSync(fileFor(roomId), JSON.stringify(line) + "\n", "utf8");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user