SpaceNinjaServer/src/controllers/dynamic/worldStateController.ts

24 lines
823 B
TypeScript
Raw Normal View History

2023-05-19 15:22:48 -03:00
import { RequestHandler } from "express";
import worldState from "@/static/fixed_responses/worldState.json";
2024-05-15 21:55:59 +02:00
import buildConfig from "@/static/data/buildConfig.json";
2024-06-17 03:31:49 +02:00
import { IWorldState } from "@/src/types/worldStateTypes";
import { config } from "@/src/services/configService";
import { getWorldState } from "@/src/services/worldStateService";
2023-05-19 15:22:48 -03:00
2024-06-17 03:31:49 +02:00
const worldStateController: RequestHandler = async (_req, res) => {
let ws: IWorldState = {}
if(config.useStaticWorldState){
ws = worldState;
ws.BuildLabel = buildConfig.buildLabel;
ws.Time = Math.round(Date.now() / 1000);
} else {
ws = (await getWorldState()).toJSON();
ws.BuildLabel = buildConfig.buildLabel;
ws.Time = Math.round(Date.now() / 1000);
}
res.json(ws);
2023-05-19 15:22:48 -03:00
};
export { worldStateController };