返回提交历史
Modified
src/controllers/api/loginController.ts
+9
-3
Modified
src/models/loginModel.ts
+2
-1
Modified
src/types/loginTypes.ts
+2
-1
XFEstudio/SpaceNinjaServer
chore: improve lang & CountryCode handling at login (#4057)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4057 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
d04f01de
代码差异
3 个文件
+13
-5
@@ -82,7 +82,7 @@ export const loginController: RequestHandler = async (request, response) => {
82
82
email: loginRequest.email,
83
83
password: loginRequest.password,
84
84
DisplayName: name,
85
CountryCode: loginRequest.lang?.toUpperCase() ?? "EN",
85
Language: loginRequest.lang,
86
86
ClientType: loginRequest.ClientType,
87
87
GoogleTokenId: loginRequest.GoogleTokenId,
88
88
Nonce: createNonce(),
@@ -125,13 +125,16 @@ export const loginController: RequestHandler = async (request, response) => {
125
125
126
126
account.ClientType = loginRequest.ClientType;
127
127
account.Nonce = createNonce();
128
account.CountryCode = loginRequest.lang?.toUpperCase() ?? "EN";
128
if (loginRequest.lang) {
129
account.Language = loginRequest.lang;
130
}
129
131
account.BuildLabel = buildLabel;
130
132
account.LastLogin = new Date();
131
133
account.LastPlatform = isAndroid ? Platform.Android : Platform.Windows;
132
134
account.Dropped = undefined;
133
135
134
136
// These fields used to be set by default but are really not needed
137
account.CountryCode = undefined;
135
138
account.ConsentNeeded = undefined;
136
139
account.TrackedSettings = undefined;
137
140
account.ForceLogoutVersion = undefined;
@@ -176,7 +179,10 @@ const createLoginResponse = (request: Request, account: IDatabaseAccountJson, bu
176
179
}
177
180
if (version_compare(buildLabel, gameToBuildVersion["12.5.2"]) >= 0) {
178
181
// U12.5 and up
179
resp.CountryCode = account.CountryCode;
182
183
// CountryCode should be based on the IP address so the client can pick a good matchmaking region automatically.
184
// An IP-country database might be a bit overkill, so we just let the client pick based on system language, instead.
185
resp.CountryCode = "";
180
186
} else {
181
187
// U12.4 and down
182
188
@@ -14,7 +14,8 @@ const databaseAccountSchema = new Schema<IDatabaseAccountJson>(
14
14
email: { type: String, required: true, unique: true },
15
15
password: { type: String, required: true },
16
16
DisplayName: { type: String, required: true, unique: true, maxLength: MAX_NAME_LENGTH },
17
CountryCode: { type: String, default: "" },
17
CountryCode: { type: String },
18
Language: { type: String },
18
19
ClientType: { type: String },
19
20
CrossPlatformAllowed: Boolean,
20
21
ForceLogoutVersion: Number,
@@ -24,6 +24,7 @@ export interface IAccountAndLoginResponseCommons {
24
24
export interface IDatabaseAccountRequiredFields extends IAccountAndLoginResponseCommons {
25
25
email: string;
26
26
password: string;
27
Language?: string;
27
28
BuildLabel?: string;
28
29
LastLogin: Date;
29
30
}
@@ -54,7 +55,7 @@ export interface ILoginRequest {
54
55
password: string;
55
56
time: number;
56
57
s?: string;
57
lang?: string;
58
lang?: string; // >= U17
58
59
date: number;
59
60
ClientType?: string;
60
61
PS?: string;