import { requireAuth } from '@/lib/auth'; import { tickNow } from '@/lib/sim/engine'; import { getStateSnapshot } from '@/lib/game/state'; // v1.1.0 (ISS-107): guarded — 401 without a live X-Flight-Session. // v1.3.0 (ISS-110): `account` carries the SESSION player's economy row. // v1.4.0 (ISS-112): full shared-world snapshot — ALL planes with owner info, packages with // carrierName; same projection as the SSE frames, so poll and push can never drift. export async function GET(req: Request) { const auth = await requireAuth(req); if (!auth.ok) return auth.response; try { // Tick-on-read (v0.7.0): advance the sim clock before snapshotting so every // read reflects current game time (expiry/finalize/spawn run inside the tick). await tickNow(); return Response.json(await getStateSnapshot(auth.player.id)); } catch (err) { console.error('failed to load game state', err); return Response.json({ error: 'failed to load game state' }, { status: 500 }); } }