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

SpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/SpaceNinjaServer

chore: verify that httpsPort has actually been bound by us (#2243)

I'm not the biggest fan of this, but it's a semi-regular problem and this should help affected users quickly discover it. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2243 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

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

代码差异

3 个文件 +244 -1
Modified package-lock.json +204 -0
@@ -11,6 +11,7 @@
11 11 "dependencies": {
12 12 "@types/express": "^5",
13 13 "@types/morgan": "^1.9.9",
14 "@types/websocket": "^1.0.10",
14 15 "@types/ws": "^8.18.1",
15 16 "crc-32": "^1.2.2",
16 17 "express": "^5",
@@ -21,6 +22,7 @@
21 22 "typescript": "^5.5",
22 23 "warframe-public-export-plus": "^0.5.68",
23 24 "warframe-riven-info": "^0.1.2",
25 "websocket": "^1.0.35",
24 26 "winston": "^3.17.0",
25 27 "winston-daily-rotate-file": "^5.0.0",
26 28 "ws": "^8.18.2"
@@ -382,6 +384,15 @@
382 384 "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==",
383 385 "license": "MIT"
384 386 },
387 "node_modules/@types/websocket": {
388 "version": "1.0.10",
389 "resolved": "https://registry.npmjs.org/@types/websocket/-/websocket-1.0.10.tgz",
390 "integrity": "sha512-svjGZvPB7EzuYS94cI7a+qhwgGU1y89wUgjT6E2wVUfmAGIvRfT7obBvRtnhXCSsoMdlG4gBFGE7MfkIXZLoww==",
391 "license": "MIT",
392 "dependencies": {
393 "@types/node": "*"
394 }
395 },
385 396 "node_modules/@types/whatwg-url": {
386 397 "version": "11.0.5",
387 398 "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz",
@@ -910,6 +921,19 @@
910 921 "node": ">=16.20.1"
911 922 }
912 923 },
924 "node_modules/bufferutil": {
925 "version": "4.0.9",
926 "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.9.tgz",
927 "integrity": "sha512-WDtdLmJvAuNNPzByAYpRo2rF1Mmradw6gvWsQKf63476DDXmomT9zUiGypLcG4ibIM67vhAj8jJRdbmEws2Aqw==",
928 "hasInstallScript": true,
929 "license": "MIT",
930 "dependencies": {
931 "node-gyp-build": "^4.3.0"
932 },
933 "engines": {
934 "node": ">=6.14.2"
935 }
936 },
913 937 "node_modules/bytes": {
914 938 "version": "3.1.2",
915 939 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
@@ -1128,6 +1152,19 @@
1128 1152 "node": ">= 8"
1129 1153 }
1130 1154 },
1155 "node_modules/d": {
1156 "version": "1.0.2",
1157 "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz",
1158 "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==",
1159 "license": "ISC",
1160 "dependencies": {
1161 "es5-ext": "^0.10.64",
1162 "type": "^2.7.2"
1163 },
1164 "engines": {
1165 "node": ">=0.12"
1166 }
1167 },
1131 1168 "node_modules/debug": {
1132 1169 "version": "4.4.0",
1133 1170 "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
@@ -1239,6 +1276,46 @@
1239 1276 "node": ">= 0.4"
1240 1277 }
1241 1278 },
1279 "node_modules/es5-ext": {
1280 "version": "0.10.64",
1281 "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz",
1282 "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==",
1283 "hasInstallScript": true,
1284 "license": "ISC",
1285 "dependencies": {
1286 "es6-iterator": "^2.0.3",
1287 "es6-symbol": "^3.1.3",
1288 "esniff": "^2.0.1",
1289 "next-tick": "^1.1.0"
1290 },
1291 "engines": {
1292 "node": ">=0.10"
1293 }
1294 },
1295 "node_modules/es6-iterator": {
1296 "version": "2.0.3",
1297 "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz",
1298 "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==",
1299 "license": "MIT",
1300 "dependencies": {
1301 "d": "1",
1302 "es5-ext": "^0.10.35",
1303 "es6-symbol": "^3.1.1"
1304 }
1305 },
1306 "node_modules/es6-symbol": {
1307 "version": "3.1.4",
1308 "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz",
1309 "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==",
1310 "license": "ISC",
1311 "dependencies": {
1312 "d": "^1.0.2",
1313 "ext": "^1.7.0"
1314 },
1315 "engines": {
1316 "node": ">=0.12"
1317 }
1318 },
1242 1319 "node_modules/escape-html": {
1243 1320 "version": "1.0.3",
1244 1321 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
@@ -1400,6 +1477,21 @@
1400 1477 "node": "*"
1401 1478 }
1402 1479 },
1480 "node_modules/esniff": {
1481 "version": "2.0.1",
1482 "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz",
1483 "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==",
1484 "license": "ISC",
1485 "dependencies": {
1486 "d": "^1.0.1",
1487 "es5-ext": "^0.10.62",
1488 "event-emitter": "^0.3.5",
1489 "type": "^2.7.2"
1490 },
1491 "engines": {
1492 "node": ">=0.10"
1493 }
1494 },
1403 1495 "node_modules/espree": {
1404 1496 "version": "9.6.1",
1405 1497 "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz",
@@ -1473,6 +1565,16 @@
1473 1565 "node": ">= 0.6"
1474 1566 }
1475 1567 },
1568 "node_modules/event-emitter": {
1569 "version": "0.3.5",
1570 "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz",
1571 "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==",
1572 "license": "MIT",
1573 "dependencies": {
1574 "d": "1",
1575 "es5-ext": "~0.10.14"
1576 }
1577 },
1476 1578 "node_modules/express": {
1477 1579 "version": "5.1.0",
1478 1580 "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz",
@@ -1515,6 +1617,15 @@
1515 1617 "url": "https://opencollective.com/express"
1516 1618 }
1517 1619 },
1620 "node_modules/ext": {
1621 "version": "1.7.0",
1622 "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz",
1623 "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==",
1624 "license": "ISC",
1625 "dependencies": {
1626 "type": "^2.7.2"
1627 }
1628 },
1518 1629 "node_modules/fast-deep-equal": {
1519 1630 "version": "3.1.3",
1520 1631 "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -2044,6 +2155,12 @@
2044 2155 "url": "https://github.com/sponsors/sindresorhus"
2045 2156 }
2046 2157 },
2158 "node_modules/is-typedarray": {
2159 "version": "1.0.0",
2160 "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
2161 "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==",
2162 "license": "MIT"
2163 },
2047 2164 "node_modules/isexe": {
2048 2165 "version": "2.0.0",
2049 2166 "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
@@ -2449,6 +2566,23 @@
2449 2566 "node": ">= 0.6"
2450 2567 }
2451 2568 },
2569 "node_modules/next-tick": {
2570 "version": "1.1.0",
2571 "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz",
2572 "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==",
2573 "license": "ISC"
2574 },
2575 "node_modules/node-gyp-build": {
2576 "version": "4.8.4",
2577 "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz",
2578 "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==",
2579 "license": "MIT",
2580 "bin": {
2581 "node-gyp-build": "bin.js",
2582 "node-gyp-build-optional": "optional.js",
2583 "node-gyp-build-test": "build-test.js"
2584 }
2585 },
2452 2586 "node_modules/object-hash": {
2453 2587 "version": "3.0.0",
2454 2588 "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
@@ -3239,6 +3373,12 @@
3239 3373 "dev": true,
3240 3374 "license": "0BSD"
3241 3375 },
3376 "node_modules/type": {
3377 "version": "2.7.3",
3378 "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz",
3379 "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==",
3380 "license": "ISC"
3381 },
3242 3382 "node_modules/type-check": {
3243 3383 "version": "0.4.0",
3244 3384 "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
@@ -3279,6 +3419,15 @@
3279 3419 "node": ">= 0.6"
3280 3420 }
3281 3421 },
3422 "node_modules/typedarray-to-buffer": {
3423 "version": "3.1.5",
3424 "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
3425 "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
3426 "license": "MIT",
3427 "dependencies": {
3428 "is-typedarray": "^1.0.0"
3429 }
3430 },
3282 3431 "node_modules/typescript": {
3283 3432 "version": "5.8.3",
3284 3433 "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz",
@@ -3317,6 +3466,19 @@
3317 3466 "punycode": "^2.1.0"
3318 3467 }
3319 3468 },
3469 "node_modules/utf-8-validate": {
3470 "version": "5.0.10",
3471 "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.10.tgz",
3472 "integrity": "sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==",
3473 "hasInstallScript": true,
3474 "license": "MIT",
3475 "dependencies": {
3476 "node-gyp-build": "^4.3.0"
3477 },
3478 "engines": {
3479 "node": ">=6.14.2"
3480 }
3481 },
3320 3482 "node_modules/util-deprecate": {
3321 3483 "version": "1.0.2",
3322 3484 "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
@@ -3351,6 +3513,38 @@
3351 3513 "node": ">=12"
3352 3514 }
3353 3515 },
3516 "node_modules/websocket": {
3517 "version": "1.0.35",
3518 "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.35.tgz",
3519 "integrity": "sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==",
3520 "license": "Apache-2.0",
3521 "dependencies": {
3522 "bufferutil": "^4.0.1",
3523 "debug": "^2.2.0",
3524 "es5-ext": "^0.10.63",
3525 "typedarray-to-buffer": "^3.1.5",
3526 "utf-8-validate": "^5.0.2",
3527 "yaeti": "^0.0.6"
3528 },
3529 "engines": {
3530 "node": ">=4.0.0"
3531 }
3532 },
3533 "node_modules/websocket/node_modules/debug": {
3534 "version": "2.6.9",
3535 "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
3536 "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
3537 "license": "MIT",
3538 "dependencies": {
3539 "ms": "2.0.0"
3540 }
3541 },
3542 "node_modules/websocket/node_modules/ms": {
3543 "version": "2.0.0",
3544 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
3545 "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
3546 "license": "MIT"
3547 },
3354 3548 "node_modules/whatwg-url": {
3355 3549 "version": "14.2.0",
3356 3550 "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz",
@@ -3471,6 +3665,16 @@
3471 3665 }
3472 3666 }
3473 3667 },
3668 "node_modules/yaeti": {
3669 "version": "0.0.6",
3670 "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
3671 "integrity": "sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==",
3672 "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
3673 "license": "MIT",
3674 "engines": {
3675 "node": ">=0.10.32"
3676 }
3677 },
3474 3678 "node_modules/yocto-queue": {
3475 3679 "version": "0.1.0",
3476 3680 "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
Modified package.json +2 -0
@@ -20,6 +20,7 @@
20 20 "dependencies": {
21 21 "@types/express": "^5",
22 22 "@types/morgan": "^1.9.9",
23 "@types/websocket": "^1.0.10",
23 24 "@types/ws": "^8.18.1",
24 25 "crc-32": "^1.2.2",
25 26 "express": "^5",
@@ -30,6 +31,7 @@
30 31 "typescript": "^5.5",
31 32 "warframe-public-export-plus": "^0.5.68",
32 33 "warframe-riven-info": "^0.1.2",
34 "websocket": "^1.0.35",
33 35 "winston": "^3.17.0",
34 36 "winston-daily-rotate-file": "^5.0.0",
35 37 "ws": "^8.18.2"
Modified src/services/webService.ts +38 -1
@@ -10,6 +10,7 @@ import { Account } from "../models/loginModel";
10 10 import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "./loginService";
11 11 import { IDatabaseAccountJson } from "../types/loginTypes";
12 12 import { HydratedDocument } from "mongoose";
13 import websocket from "websocket";
13 14
14 15 let httpServer: http.Server | undefined;
15 16 let httpsServer: https.Server | undefined;
@@ -44,6 +45,37 @@ export const startWebServer = (): void => {
44 45 logger.info(
45 46 "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
46 47 );
48
49 void runWsSelfTest("wss", httpsPort).then(ok => {
50 if (!ok) {
51 logger.warn(`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`);
52 if (process.platform == "win32") {
53 logger.warn(
54 `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
55 );
56 }
57 }
58 });
59 });
60 });
61 };
62
63 const runWsSelfTest = (protocol: "ws" | "wss", port: number): Promise<boolean> => {
64 return new Promise(resolve => {
65 const client = new websocket.client({ tlsOptions: { rejectUnauthorized: false } });
66 client.connect(`${protocol}://localhost:${port}/custom/selftest`);
67 client.on("connect", connection => {
68 connection.on("message", msg => {
69 if (msg.type == "utf8" && msg.utf8Data == "SpaceNinjaServer") {
70 resolve(true);
71 }
72 });
73 connection.on("close", () => {
74 resolve(false);
75 });
76 });
77 client.on("connectFailed", () => {
78 resolve(false);
47 79 });
48 80 });
49 81 };
@@ -128,7 +160,12 @@ interface IWsMsgToClient {
128 160 update_inventory?: boolean;
129 161 }
130 162
131 const wsOnConnect = (ws: ws, _req: http.IncomingMessage): void => {
163 const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
164 if (req.url == "/custom/selftest") {
165 ws.send("SpaceNinjaServer");
166 ws.close();
167 return;
168 }
132 169 // eslint-disable-next-line @typescript-eslint/no-misused-promises
133 170 ws.on("message", async msg => {
134 171 const data = JSON.parse(String(msg)) as IWsMsgFromClient;