返回提交历史
Modified
src/controllers/api/loginController.ts
+1
-1
Modified
src/controllers/custom/tunablesController.ts
+2
-3
Modified
src/services/configWatcherService.ts
+3
-1
Modified
src/services/tunablesService.ts
+2
-2
Modified
src/services/wsService.ts
+3
-0
XFEstudio/SpaceNinjaServer
feat: %THIS_MACHINE% substitution for udpProxyUpstream (#3191)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3191 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
b443d3e9
代码差异
5 个文件
+11
-7
@@ -219,7 +219,7 @@ const createLoginResponse = (request: Request, account: IDatabaseAccountJson, bu
219
219
clientMod.startsWith("OpenWF Bootstrapper v") &&
220
220
version_compare(clientMod.substring(21), "0.12.0") >= 0
221
221
) {
222
const tunables = getTunablesForClient((request.socket.address() as AddressInfo).address);
222
const tunables = getTunablesForClient((request.socket.address() as AddressInfo).address, myAddress);
223
223
if (version_compare(buildLabel, gameToBuildVersion["16.5.5"]) < 0) {
224
224
tunables.irc = config.ircAddress ?? myAddress;
225
225
}
@@ -1,11 +1,10 @@
1
1
import type { RequestHandler } from "express";
2
import type { ITunables } from "../../types/bootstrapperTypes.ts";
3
2
import { getTunablesForClient } from "../../services/tunablesService.ts";
4
3
import type { AddressInfo } from "node:net";
4
import { getReflexiveAddress } from "../../services/configService.ts";
5
5
6
6
// This endpoint is specific to the OpenWF Bootstrapper: https://openwf.io/bootstrapper-manual
7
7
8
8
export const tunablesController: RequestHandler = (req, res) => {
9
const tunables: ITunables = getTunablesForClient((req.socket.address() as AddressInfo).address);
10
res.json(tunables);
9
res.json(getTunablesForClient((req.socket.address() as AddressInfo).address, getReflexiveAddress(req).myAddress));
11
10
};
@@ -34,7 +34,9 @@ chokidar.watch(configPath).on("change", () => {
34
34
forEachWsClient(client => {
35
35
if (client.isGame) {
36
36
client.send(
37
JSON.stringify({ tunables: getTunablesForClient(client.address) } satisfies IWsMsgToClient)
37
JSON.stringify({
38
tunables: getTunablesForClient(client.address, client.reflexiveAddress)
39
} satisfies IWsMsgToClient)
38
40
);
39
41
}
40
42
});
@@ -17,7 +17,7 @@ export const getTokenForClient = (clientAddress: string): string => {
17
17
return crypto.createHmac("sha256", secret).update(clientAddress).digest("hex");
18
18
};
19
19
20
export const getTunablesForClient = (clientAddress: string): ITunables => {
20
export const getTunablesForClient = (clientAddress: string, reflexiveAddress: string): ITunables => {
21
21
const tunables: ITunables = {};
22
22
if (config.tunables?.useLoginToken) {
23
23
tunables.token = getTokenForClient(clientAddress);
@@ -41,7 +41,7 @@ export const getTunablesForClient = (clientAddress: string): ITunables => {
41
41
tunables.motd = config.tunables.motd;
42
42
}
43
43
if (config.tunables?.udpProxyUpstream) {
44
tunables.udp_proxy_upstream = config.tunables.udpProxyUpstream;
44
tunables.udp_proxy_upstream = config.tunables.udpProxyUpstream.split("%THIS_MACHINE%").join(reflexiveAddress);
45
45
}
46
46
return tunables;
47
47
};
@@ -10,6 +10,7 @@ import { logError, logger } from "../utils/logger.ts";
10
10
import type { Request } from "express";
11
11
import type { ITunables } from "../types/bootstrapperTypes.ts";
12
12
import type { AddressInfo } from "node:net";
13
import { config } from "./configService.ts";
13
14
14
15
let wsServer: WebSocketServer | undefined;
15
16
let wssServer: WebSocketServer | undefined;
@@ -50,6 +51,7 @@ let lastWsid: number = 0;
50
51
interface IWsCustomData extends WebSocket {
51
52
id: number;
52
53
address: string;
54
reflexiveAddress: string;
53
55
accountId?: string;
54
56
isGame?: boolean;
55
57
}
@@ -107,6 +109,7 @@ const wsOnConnect = (ws: WebSocket, req: http.IncomingMessage): void => {
107
109
108
110
(ws as IWsCustomData).id = ++lastWsid;
109
111
(ws as IWsCustomData).address = (req.socket.address() as AddressInfo).address;
112
(ws as IWsCustomData).reflexiveAddress = req.headers.host?.split(":")[0] ?? config.myAddress;
110
113
ws.send(JSON.stringify({ wsid: lastWsid } satisfies IWsMsgToClient));
111
114
112
115
// eslint-disable-next-line @typescript-eslint/no-misused-promises