Private
Public Access
1
0

refacto: Replaced useless DB queries by websocket calls + patching WS auth-token leak

This commit is contained in:
gauvainboiche
2026-04-01 18:47:37 +02:00
parent e28a2d6e9c
commit f161ccb0f0
33 changed files with 6246 additions and 43 deletions

View File

@@ -6,8 +6,11 @@ import {
setElementBonus,
} from "./db/gameDb.js";
import { computeTeamIncome, computeTeamElementBonus } from "./helpers/economy.js";
import { buildRealtimeSnapshot } from "./realtimeSnapshot.js";
import { broadcast } from "./ws/hub.js";
const TICK_SECONDS = 5;
let lastTickSeed = null;
/**
* Starts the server-side economy tick loop.
@@ -19,6 +22,11 @@ export function startEconTick() {
setInterval(async () => {
try {
const worldSeed = await ensureSeedEpoch();
if (lastTickSeed && lastTickSeed !== worldSeed) {
broadcast("seed-changed", { worldSeed });
}
lastTickSeed = worldSeed;
const rows = await getGridCells(worldSeed);
const cfg = getConfig();
@@ -41,6 +49,9 @@ export function startEconTick() {
await setElementBonus(worldSeed, "blue", blueBonus);
await setElementBonus(worldSeed, "red", redBonus);
const snapshot = await buildRealtimeSnapshot(worldSeed);
broadcast("snapshot", snapshot);
} catch (e) {
console.error("[econ tick]", e.message);
}