Restored rooms wake their automatons
The bot pump only ran when a command or join arrived, so a server restart landing mid-bot-turn left the restored room waiting forever for a human to poke it — room 928D sat exactly there, its automaton holding a perfectly answerable stack. Boot now kicks the pump for every restored still-running room, two seconds after restore. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
2ac046611d
commit
4a75370de5
@@ -35,6 +35,7 @@ import {
|
|||||||
getRoom,
|
getRoom,
|
||||||
joinRoom,
|
joinRoom,
|
||||||
loadPersistedRooms,
|
loadPersistedRooms,
|
||||||
|
runningRooms,
|
||||||
addAutomaton,
|
addAutomaton,
|
||||||
addChat,
|
addChat,
|
||||||
driveOneAutomaton,
|
driveOneAutomaton,
|
||||||
@@ -70,6 +71,11 @@ const port = Number(process.env.PORT ?? 8787);
|
|||||||
// is not reachable from the internet. Dev default stays LAN-friendly.
|
// is not reachable from the internet. Dev default stays LAN-friendly.
|
||||||
const host = process.env.HOST ?? "0.0.0.0";
|
const host = process.env.HOST ?? "0.0.0.0";
|
||||||
loadPersistedRooms();
|
loadPersistedRooms();
|
||||||
|
// A restart can land mid-bot-turn: without a kick, a restored room whose
|
||||||
|
// current actor is an automaton waits forever for a human to poke it.
|
||||||
|
setTimeout(() => {
|
||||||
|
for (const room of runningRooms()) runBots(room);
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
// One process serves both the built client and the websocket, so production
|
// One process serves both the built client and the websocket, so production
|
||||||
// needs only a TLS proxy in front (or nothing, on a LAN).
|
// needs only a TLS proxy in front (or nothing, on a LAN).
|
||||||
|
|||||||
@@ -91,6 +91,11 @@ export function roomCount(): number {
|
|||||||
return rooms.size;
|
return rooms.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Every restored, still-running room — so boot can wake their bot pumps. */
|
||||||
|
export function runningRooms(): Room[] {
|
||||||
|
return [...rooms.values()].filter((r) => r.state && r.state.phase === "playing");
|
||||||
|
}
|
||||||
|
|
||||||
export function createRoom(hostId: PlayerId): { room: Room; token: string } {
|
export function createRoom(hostId: PlayerId): { room: Room; token: string } {
|
||||||
const token = randomBytes(16).toString("hex");
|
const token = randomBytes(16).toString("hex");
|
||||||
const room: Room = {
|
const room: Room = {
|
||||||
|
|||||||
Reference in New Issue
Block a user