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: multiple binding servers (#3660)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3660 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

e3fd2192
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

8 个文件 +39 -30
Modified README.md +1 -1
@@ -16,7 +16,7 @@ SpaceNinjaServer requires a `config.json`. To set it up, you can copy the [confi
16 16 - `logger.level` can be `fatal`, `error`, `warn`, `info`, `http`, `debug`, or `trace`.
17 17 - `bindAddress`, `httpPort`, `httpsPort` are related to how SpaceNinjaServer is reached on the network. Under Docker, these options are unchangable; modify your `docker-compose.yml`, instead.
18 18 - `ircExecutable` and `hubExecutable` can be provided with relative paths to executables which will be ran as child processes of SpaceNinjaServer.
19 - `ircAddress`, `hubServers`, and `nrsAddress` configure how clients contact these secondary servers. For `ircAddress` and `nrsAddress`, a null value is equivalent to `%THIS_MACHINE%`, which should just work when SpaceNinjaServer and the secondary servers are on the same machine.
19 - `ircAddress`, `hubServers`, and `nrsAddresses` configure how clients contact these secondary servers. For `ircAddress`, a null value is equivalent to `%THIS_MACHINE%`, which should just work when SpaceNinjaServer and the secondary servers are on the same machine.
20 20 - `worldState.eidolonOverride` can be set to `day` or `night` to lock the time to day/fass and night/vome on Plains of Eidolon/Cambion Drift.
21 21 - `worldState.vallisOverride` can be set to `warm` or `cold` to lock the temperature on Orb Vallis.
22 22 - `worldState.duviriOverride` can be set to `joy`, `anger`, `envy`, `sorrow`, or `fear` to lock the Duviri spiral.
Modified config-vanilla.json +2 -2
@@ -11,7 +11,7 @@
11 11 "httpsCertFile": "static/cert/cert.pem",
12 12 "httpsKeyFile": "static/cert/key.pem",
13 13 "ircExecutable": null,
14 "ircAddress": null,
14 "ircAddress": "%THIS_MACHINE%",
15 15 "hubExecutable": null,
16 16 "hubServers": [
17 17 {
@@ -21,7 +21,7 @@
21 21 }
22 22 ],
23 23 "noHubDiscrimination": false,
24 "nrsAddress": null,
24 "nrsAddresses": [],
25 25 "dtls": null,
26 26 "administratorNames": [],
27 27 "autoCreateAccount": true,
Modified src/controllers/api/findSessionsController.ts +8 -6
@@ -2,7 +2,7 @@ import type { RequestHandler } from "express";
2 2 import { getSession } from "../../managers/sessionManager.ts";
3 3 import { logger } from "../../utils/logger.ts";
4 4 import type { IFindSessionRequest } from "../../types/session.ts";
5 import { getNrsAddress } from "../../services/configService.ts";
5 import { getNrsAddresses } from "../../services/configService.ts";
6 6
7 7 export const findSessionsController: RequestHandler = async (_req, res) => {
8 8 const req = JSON.parse(String(_req.body)) as IFindSessionRequest;
@@ -13,11 +13,13 @@ export const findSessionsController: RequestHandler = async (_req, res) => {
13 13 // (OpenWF-specific) Maybe NRS can tell us who the host of this session is...
14 14 logger.debug(`Unknown session id, asking NRS...`);
15 15 try {
16 const [nrsAddr, nrsPort] = getNrsAddress();
17 const res = await fetch(`http://${nrsAddr}:${nrsPort}/api/session/${req.id}`);
18 const json = (await res.json()) as INrsSessionInfo;
19 if (json.hid) {
20 sessions.push({ id: req.id, createdBy: json.hid });
16 for (const [nrsAddr, nrsPort] of getNrsAddresses()) {
17 const res = await fetch(`http://${nrsAddr}:${nrsPort}/api/session/${req.id}`);
18 const json = (await res.json()) as INrsSessionInfo;
19 if (json.hid) {
20 sessions.push({ id: req.id, createdBy: json.hid });
21 break;
22 }
21 23 }
22 24 } catch (e) {
23 25 /* empty */
Modified src/controllers/api/loginController.ts +1 -1
@@ -177,7 +177,7 @@ const createLoginResponse = (request: Request, account: IDatabaseAccountJson, bu
177 177 }
178 178 }
179 179 if (version_compare(buildLabel, gameToBuildVersion["15.14.1"]) >= 0) {
180 resp.NRS = [(config.nrsAddress || "%THIS_MACHINE%").split("%THIS_MACHINE%").join(myAddress)];
180 resp.NRS = (config.nrsAddresses ?? []).map(x => x.split("%THIS_MACHINE%").join(myAddress));
181 181 }
182 182 if (version_compare(buildLabel, gameToBuildVersion["16.5.5"]) >= 0) {
183 183 resp.IRC = [(config.ircAddress || "%THIS_MACHINE%").split("%THIS_MACHINE%").join(myAddress)];
Modified src/helpers/udp.ts +6 -8
@@ -1,5 +1,5 @@
1 1 import dgram from "node:dgram";
2 import { getNrsAddress } from "../services/configService.ts";
2 import { getNrsAddresses } from "../services/configService.ts";
3 3 import { crc32 } from "node:zlib";
4 4
5 5 export const sendUdpMessage = (host: string, port: number, message: Buffer | string): Promise<void> => {
@@ -16,13 +16,11 @@ export const sendUdpMessage = (host: string, port: number, message: Buffer | str
16 16 });
17 17 };
18 18
19 export const sendCustomMessageToNrs = (message: string): Promise<void> => {
20 const [nrsAddr, nrsPort] = getNrsAddress();
19 export const sendCustomMessageToNrs = async (message: string): Promise<void> => {
21 20 const msgbuf = Buffer.from("\x00" + message, "utf8");
22 21 const crc = crc32(Buffer.from("b471e49539930dc9b5a131e6247c7387A", "utf8"), crc32(msgbuf));
23 return sendUdpMessage(
24 nrsAddr,
25 nrsPort,
26 Buffer.concat([Buffer.from([0x00, crc >> 24, crc >> 16, crc >> 8, crc]), msgbuf])
27 );
22 const msg = Buffer.concat([Buffer.from([0x00, crc >> 24, crc >> 16, crc >> 8, crc]), msgbuf]);
23 for (const [nrsAddr, nrsPort] of getNrsAddresses()) {
24 await sendUdpMessage(nrsAddr, nrsPort, msg);
25 }
28 26 };
Modified src/services/configService.ts +14 -11
@@ -28,10 +28,11 @@ export interface IConfig {
28 28 ircExecutable?: string;
29 29 ircAddress?: string;
30 30 hubExecutable?: string;
31 hubAddress?: string;
31 /** @deprecated */ hubAddress?: string;
32 32 hubServers?: IHubServer[];
33 33 noHubDiscrimination?: boolean;
34 nrsAddress?: string;
34 /** @deprecated */ nrsAddress?: string;
35 nrsAddresses?: string[];
35 36 dtls?: number;
36 37 administratorNames?: string[];
37 38 autoCreateAccount?: boolean;
@@ -287,13 +288,15 @@ export const getWebServerParams = (): IWebServerParams => {
287 288 };
288 289 };
289 290
290 export const getNrsAddress = (): [string, number] => {
291 let nrsAddr = (config.nrsAddress || "%THIS_MACHINE%").split("%THIS_MACHINE%").join("127.0.0.1");
292 let nrsPort = 4950;
293 const colon = nrsAddr.indexOf(":");
294 if (colon != -1) {
295 nrsPort = parseInt(nrsAddr.substring(colon + 1));
296 nrsAddr = nrsAddr.substring(0, colon);
297 }
298 return [nrsAddr, nrsPort];
291 export const getNrsAddresses = (): [string, number][] => {
292 return (config.nrsAddresses ?? []).map(nrsAddr => {
293 nrsAddr = nrsAddr.split("%THIS_MACHINE%").join("127.0.0.1");
294 let nrsPort = 4950;
295 const colon = nrsAddr.indexOf(":");
296 if (colon != -1) {
297 nrsPort = parseInt(nrsAddr.substring(colon + 1));
298 nrsAddr = nrsAddr.substring(0, colon);
299 }
300 return [nrsAddr, nrsPort];
301 });
299 302 };
Modified src/services/configWatcherService.ts +6 -0
@@ -1,3 +1,4 @@
1 /* eslint-disable @typescript-eslint/no-deprecated */
1 2 import chokidar from "chokidar";
2 3 import { logger } from "../utils/logger.ts";
3 4 import {
@@ -89,6 +90,11 @@ export const validateConfig = (): void => {
89 90 }
90 91 modified = true;
91 92 }
93 if (config.nrsAddress) {
94 config.nrsAddresses = [config.nrsAddress];
95 delete config.nrsAddress;
96 modified = true;
97 }
92 98 if (config.administratorNames) {
93 99 if (!Array.isArray(config.administratorNames)) {
94 100 config.administratorNames = [config.administratorNames];
Modified src/services/tunablesService.ts +1 -1
@@ -20,7 +20,7 @@ export const getTokenForClient = (clientAddress: string): string => {
20 20 export const getTunablesForClient = (clientAddress: string, reflexiveAddress: string): ITunables => {
21 21 const tunables: ITunables = {
22 22 // To successfully update the NRS address for pre-U15.14 clients, this needs to be set before login.
23 nrs: (config.nrsAddress || "%THIS_MACHINE%").split("%THIS_MACHINE%").join(reflexiveAddress),
23 nrs: ((config.nrsAddresses ?? [])[0] || "%THIS_MACHINE%").split("%THIS_MACHINE%").join(reflexiveAddress),
24 24
25 25 // if (version_compare(buildLabel, gameToBuildVersion["16.5.5"]) < 0) {
26 26 irc: (config.ircAddress || "%THIS_MACHINE%").split("%THIS_MACHINE%").join(reflexiveAddress)