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: auto-detect 'my address', only use config as fallback (#1125)

This is useful for LAN usage where we can use localhost on our own machine but have to use 192.168.x.y on other devices. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1125

3da02385
Sainan <sainan@calamity.inc>
提交于

代码差异

1 个文件 +8 -6
Modified src/controllers/api/loginController.ts +8 -6
@@ -19,6 +19,8 @@ export const loginController: RequestHandler = async (request, response) => {
19 19 ? request.query.buildLabel.split(" ").join("+")
20 20 : buildConfig.buildLabel;
21 21
22 const myAddress = request.host.indexOf("warframe.com") == -1 ? request.host : config.myAddress;
23
22 24 if (!account && config.autoCreateAccount && loginRequest.ClientType != "webui") {
23 25 try {
24 26 const nameFromEmail = loginRequest.email.substring(0, loginRequest.email.indexOf("@"));
@@ -44,7 +46,7 @@ export const loginController: RequestHandler = async (request, response) => {
44 46 LatestEventMessageDate: new Date(0)
45 47 });
46 48 logger.debug("created new account");
47 response.json(createLoginResponse(newAccount, buildLabel));
49 response.json(createLoginResponse(myAddress, newAccount, buildLabel));
48 50 return;
49 51 } catch (error: unknown) {
50 52 if (error instanceof Error) {
@@ -67,10 +69,10 @@ export const loginController: RequestHandler = async (request, response) => {
67 69 }
68 70 await account.save();
69 71
70 response.json(createLoginResponse(account.toJSON(), buildLabel));
72 response.json(createLoginResponse(myAddress, account.toJSON(), buildLabel));
71 73 };
72 74
73 const createLoginResponse = (account: IDatabaseAccountJson, buildLabel: string): ILoginResponse => {
75 const createLoginResponse = (myAddress: string, account: IDatabaseAccountJson, buildLabel: string): ILoginResponse => {
74 76 return {
75 77 id: account.id,
76 78 DisplayName: account.DisplayName,
@@ -84,9 +86,9 @@ const createLoginResponse = (account: IDatabaseAccountJson, buildLabel: string):
84 86 TrackedSettings: account.TrackedSettings,
85 87 Nonce: account.Nonce,
86 88 Groups: [],
87 IRC: config.myIrcAddresses ?? [config.myAddress],
88 platformCDNs: [`https://${config.myAddress}/`],
89 HUB: `https://${config.myAddress}/api/`,
89 IRC: config.myIrcAddresses ?? [myAddress],
90 platformCDNs: [`https://${myAddress}/`],
91 HUB: `https://${myAddress}/api/`,
90 92 NRS: config.NRS,
91 93 DTLS: 99,
92 94 BuildLabel: buildLabel,