Fix game timer: cycle-key tracking, wall-clock only, active gate
games_sp.log is not wiped on restart, so old J; lines from prior sessions were poisoning the anchor. Now the scanner walks the tail backward to the LATEST InitGame and only considers lines after it, returning an opaque cycle key (the first J; line) plus a state. The worker stamps game_started_at/ended_at with Date.now() at observation time instead of inferring from the log's own timestamps. Same-players game restarts produce a new key and cleanly re-anchor. When the server transitions to 0 players, game state is cleared server-side and the UI also gates the timer display on activeSince. Adds servers.game_cycle_key column with additive migration.
This commit is contained in:
@@ -38,8 +38,9 @@ CREATE TABLE IF NOT EXISTS servers (
|
||||
-- and resume from the same anchor when the server comes back.
|
||||
active_since TEXT, -- ISO ts of last 0 -> >0 player transition
|
||||
inactive_since TEXT, -- ISO ts of last >0 -> 0 player transition
|
||||
game_started_at TEXT, -- ISO ts we first observed InitGame: for the current match
|
||||
game_ended_at TEXT, -- ISO ts we observed ExitLevel/ShutdownGame ending it
|
||||
game_started_at TEXT, -- wall-clock ISO when we first saw a J; line for the current match cycle
|
||||
game_ended_at TEXT, -- wall-clock ISO when we first saw ExitLevel/ShutdownGame end it
|
||||
game_cycle_key TEXT, -- opaque marker for the currently-tracked cycle (the first J; line after the latest InitGame); lets us detect same-players game restarts
|
||||
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user