refacto: Replaced useless DB queries by websocket calls + patching WS auth-token leak
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user