XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

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>

4be7a9e6
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

2 个文件 +5 -1
Modified src/controllers/custom/configController.ts +4 -1
@@ -2,7 +2,7 @@ import type { RequestHandler } from "express";
2 2 import { config, syncConfigWithDatabase } from "../../services/configService.ts";
3 3 import { getAccountForRequest, isAdministrator } from "../../services/loginService.ts";
4 4 import { saveConfig } from "../../services/configWriterService.ts";
5 import { sendWsBroadcastEx } from "../../services/wsService.ts";
5 import { sendWsBroadcastEx, sendWsBroadcast } from "../../services/wsService.ts";
6 6
7 7 export const getConfigController: RequestHandler = async (req, res) => {
8 8 const account = await getAccountForRequest(req);
@@ -21,11 +21,14 @@ export const getConfigController: RequestHandler = async (req, res) => {
21 21 export const setConfigController: RequestHandler = async (req, res) => {
22 22 const account = await getAccountForRequest(req);
23 23 if (isAdministrator(account)) {
24 let isWorldStateUpdate = false;
24 25 for (const [id, value] of Object.entries(req.body as Record<string, boolean | string | number>)) {
26 if (id.startsWith("worldState")) isWorldStateUpdate = true;
25 27 const [obj, idx] = configIdToIndexable(id);
26 28 obj[idx] = value;
27 29 }
28 30 sendWsBroadcastEx({ config_reloaded: true }, undefined, parseInt(String(req.query.wsid)));
31 if (isWorldStateUpdate) sendWsBroadcast({ sync_world_state: true });
29 32 syncConfigWithDatabase();
30 33 await saveConfig();
31 34 res.end();
Modified src/services/wsService.ts +1 -0
@@ -92,6 +92,7 @@ interface IWsMsgToClient {
92 92
93 93 // to game/bootstrapper (https://openwf.io/bootstrapper-manual)
94 94 sync_inventory?: boolean;
95 sync_world_state?: boolean;
95 96 tunables?: ITunables;
96 97 }
97 98