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: update for bootstrapper v0.12.0 (#3079)

The IRC config now works for pre-U17 versions. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3079 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

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

代码差异

6 个文件 +35 -17
Modified config-vanilla.json +2 -1
@@ -76,7 +76,8 @@
76 76 "prohibitFovOverride": false,
77 77 "prohibitFreecam": false,
78 78 "prohibitTeleport": false,
79 "prohibitScripts": false
79 "prohibitScripts": false,
80 "motd": null
80 81 },
81 82 "dev": {
82 83 "keepVendorsExpired": false
Modified src/controllers/api/loginController.ts +22 -13
@@ -1,4 +1,4 @@
1 import type { RequestHandler } from "express";
1 import type { Request, RequestHandler } from "express";
2 2
3 3 import { config, getReflexiveAddress } from "../../services/configService.ts";
4 4 import { buildConfig } from "../../services/buildConfigService.ts";
@@ -12,7 +12,7 @@ import { handleNonceInvalidation } from "../../services/wsService.ts";
12 12 import { getInventory } from "../../services/inventoryService.ts";
13 13 import { createMessage } from "../../services/inboxService.ts";
14 14 import { fromStoreItem } from "../../services/itemDataService.ts";
15 import { getTokenForClient } from "../../services/tunablesService.ts";
15 import { getTokenForClient, getTunablesForClient } from "../../services/tunablesService.ts";
16 16 import type { AddressInfo } from "node:net";
17 17
18 18 export const loginController: RequestHandler = async (request, response) => {
@@ -32,8 +32,6 @@ export const loginController: RequestHandler = async (request, response) => {
32 32 ? request.query.buildLabel.split(" ").join("+")
33 33 : buildConfig.buildLabel;
34 34
35 const { myAddress, myUrlBase } = getReflexiveAddress(request);
36
37 35 if (
38 36 !account &&
39 37 ((config.autoCreateAccount && loginRequest.ClientType != "webui") ||
@@ -52,7 +50,7 @@ export const loginController: RequestHandler = async (request, response) => {
52 50 LastLogin: new Date()
53 51 });
54 52 logger.debug("created new account");
55 response.json(createLoginResponse(myAddress, myUrlBase, newAccount, buildLabel));
53 response.send(createLoginResponse(request, newAccount, buildLabel)).end();
56 54 return;
57 55 } catch (error: unknown) {
58 56 if (error instanceof Error) {
@@ -106,15 +104,13 @@ export const loginController: RequestHandler = async (request, response) => {
106 104 await inventory.save();
107 105 }
108 106
109 response.json(createLoginResponse(myAddress, myUrlBase, account.toJSON(), buildLabel));
107 response.send(createLoginResponse(request, account.toJSON(), buildLabel)).end();
110 108 };
111 109
112 const createLoginResponse = (
113 myAddress: string,
114 myUrlBase: string,
115 account: IDatabaseAccountJson,
116 buildLabel: string
117 ): ILoginResponse => {
110 const createLoginResponse = (request: Request, account: IDatabaseAccountJson, buildLabel: string): string => {
111 const { myAddress, myUrlBase } = getReflexiveAddress(request);
112 const clientMod = request.query.clientMod as string | undefined;
113
118 114 const resp: ILoginResponse = {
119 115 id: account.id,
120 116 DisplayName: account.DisplayName,
@@ -179,5 +175,18 @@ const createLoginResponse = (
179 175 resp.platformCDNs = [`${myUrlBase}/`];
180 176 }
181 177 }
182 return resp;
178
179 let raw = JSON.stringify(resp);
180 if (
181 clientMod &&
182 clientMod.startsWith("OpenWF Bootstrapper v") &&
183 version_compare(clientMod.substring(21), "0.12.0") >= 0
184 ) {
185 const tunables = getTunablesForClient((request.socket.address() as AddressInfo).address);
186 if (version_compare(buildLabel, "2015.05.14.16.29") < 0) {
187 tunables.irc = config.ircAddress ?? myAddress;
188 }
189 raw += "\t" + JSON.stringify(tunables);
190 }
191 return raw;
183 192 };
Modified src/helpers/inventoryHelpers.ts +3 -2
@@ -14,8 +14,9 @@ export const version_compare = (a: string, b: string): number => {
14 14 .split(".")
15 15 .map(x => parseInt(x));
16 16 for (let i = 0; i != a_digits.length; ++i) {
17 if (a_digits[i] != b_digits[i]) {
18 return a_digits[i] > b_digits[i] ? 1 : -1;
17 const b_digit = b_digits[i] ?? 0;
18 if (a_digits[i] != b_digit) {
19 return a_digits[i] > b_digit ? 1 : -1;
19 20 }
20 21 }
21 22 return 0;
Modified src/services/configService.ts +1 -0
@@ -84,6 +84,7 @@ export interface IConfig {
84 84 prohibitFreecam?: boolean;
85 85 prohibitTeleport?: boolean;
86 86 prohibitScripts?: boolean;
87 motd?: string;
87 88 };
88 89 dev?: {
89 90 keepVendorsExpired?: boolean;
Modified src/services/tunablesService.ts +3 -0
@@ -37,5 +37,8 @@ export const getTunablesForClient = (clientAddress: string): ITunables => {
37 37 if (config.tunables?.prohibitScripts) {
38 38 tunables.prohibit_scripts = true;
39 39 }
40 if (config.tunables?.motd) {
41 tunables.motd = config.tunables.motd;
42 }
40 43 return tunables;
41 44 };
Modified src/types/bootstrapperTypes.ts +4 -1
@@ -1,9 +1,12 @@
1 1 // This is specific to the OpenWF Bootstrapper: https://openwf.io/bootstrapper-manual
2 2 export interface ITunables {
3 token?: string;
4 3 prohibit_skip_mission_start_timer?: boolean;
5 4 prohibit_fov_override?: boolean;
6 5 prohibit_freecam?: boolean;
7 6 prohibit_teleport?: boolean;
8 7 prohibit_scripts?: boolean;
8 disable_websocket?: boolean;
9 motd?: string;
10 token?: string;
11 irc?: string;
9 12 }