From 4be7a9e6c603ee14634fda115d457f4ad9bbbace Mon Sep 17 00:00:00 2001 From: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Date: Wed, 5 Nov 2025 01:10:39 -0800 Subject: [PATCH] feat: sync worldstate on config change (#2986) Reviewed-on: https://www.onlyg.it/OpenWF/SpaceNinjaServer/pulls/2986 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> --- src/controllers/custom/configController.ts | 5 ++++- src/services/wsService.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/custom/configController.ts b/src/controllers/custom/configController.ts index 70b61174..1b0eeecb 100644 --- a/src/controllers/custom/configController.ts +++ b/src/controllers/custom/configController.ts @@ -2,7 +2,7 @@ import type { RequestHandler } from "express"; import { config, syncConfigWithDatabase } from "../../services/configService.ts"; import { getAccountForRequest, isAdministrator } from "../../services/loginService.ts"; import { saveConfig } from "../../services/configWriterService.ts"; -import { sendWsBroadcastEx } from "../../services/wsService.ts"; +import { sendWsBroadcastEx, sendWsBroadcast } from "../../services/wsService.ts"; export const getConfigController: RequestHandler = async (req, res) => { const account = await getAccountForRequest(req); @@ -21,11 +21,14 @@ export const getConfigController: RequestHandler = async (req, res) => { export const setConfigController: RequestHandler = async (req, res) => { const account = await getAccountForRequest(req); if (isAdministrator(account)) { + let isWorldStateUpdate = false; for (const [id, value] of Object.entries(req.body as Record)) { + if (id.startsWith("worldState")) isWorldStateUpdate = true; const [obj, idx] = configIdToIndexable(id); obj[idx] = value; } sendWsBroadcastEx({ config_reloaded: true }, undefined, parseInt(String(req.query.wsid))); + if (isWorldStateUpdate) sendWsBroadcast({ sync_world_state: true }); syncConfigWithDatabase(); await saveConfig(); res.end(); diff --git a/src/services/wsService.ts b/src/services/wsService.ts index 6850e1a2..9538deb9 100644 --- a/src/services/wsService.ts +++ b/src/services/wsService.ts @@ -92,6 +92,7 @@ interface IWsMsgToClient { // to game/bootstrapper (https://openwf.io/bootstrapper-manual) sync_inventory?: boolean; + sync_world_state?: boolean; tunables?: ITunables; }