返回提交历史
Modified
src/controllers/api/getRecentPlayersController.ts
+17
-11
Modified
src/services/loginService.ts
+7
-0
XFEstudio/XFESpaceNinjaServer
fix: handle getRecentPlayers with unknown accounts (#3667)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3667 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
fa3316f0
代码差异
2 个文件
+24
-11
@@ -9,21 +9,27 @@ import { Account } from "../../models/loginModel.ts";
9
9
export const getRecentPlayersController: RequestHandler = async (req, res): Promise<void> => {
10
10
const account = await getAccountForRequest(req);
11
11
const payload = getJSONfromString<IRecentPlayersPayload>(String(req.body));
12
const promises: Promise<void>[] = [];
12
const results: IFriendInfo[] = [];
13
13
for (const info of payload.RecentPlayers) {
14
if (!fromOid(info._id)) {
15
// U18 may provide an empty $id but with a DisplayName for us to look us.
16
const otherAccount = await Account.findOne({ DisplayName: info.DisplayName }, "_id");
17
if (!otherAccount) {
18
continue;
14
try {
15
if (!fromOid(info._id)) {
16
// U18 may provide an empty $id but with a DisplayName for us to look us.
17
const otherAccount = await Account.findOne({ DisplayName: info.DisplayName }, "_id");
18
if (!otherAccount) {
19
continue;
20
}
21
info._id = toOid2(otherAccount._id, account.BuildLabel);
19
22
}
20
info._id = toOid2(otherAccount._id, account.BuildLabel);
23
await Promise.all([
24
addAccountDataToFriendInfo(info, account.BuildLabel),
25
addInventoryDataToFriendInfo(info)
26
]);
27
results.push(info);
28
} catch (_) {
29
/* empty */
21
30
}
22
promises.push(addAccountDataToFriendInfo(info, account.BuildLabel));
23
promises.push(addInventoryDataToFriendInfo(info));
24
31
}
25
await Promise.all(promises);
26
res.json(payload);
32
res.json({ RecentPlayers: results });
27
33
};
28
34
29
35
interface IRecentPlayersPayload {
@@ -152,3 +152,10 @@ export const getUnicodeName = (account: TAccountDocument, buildLabel: string | u
152
152
const platformId = getOriginalPlatform(account);
153
153
return account.DisplayName + String.fromCharCode(0xe000 + platformId);
154
154
};
155
156
export const stripUnicodeSuffix = (name: string): string => {
157
if (name.charCodeAt(name.length) >= 0xe000) {
158
name = name.substring(0, name.length - 1);
159
}
160
return name;
161
};