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

XFESpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/XFESpaceNinjaServer

chore(webui): remove administratorNames entry when deleting account (#2820)

Closes #2819 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2820 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

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

代码差异

1 个文件 +28 -17
Modified src/controllers/custom/deleteAccountController.ts +28 -17
@@ -1,5 +1,5 @@
1 1 import type { RequestHandler } from "express";
2 import { getAccountIdForRequest } from "../../services/loginService.ts";
2 import { getAccountForRequest } from "../../services/loginService.ts";
3 3 import { Account, Ignore } from "../../models/loginModel.ts";
4 4 import { Inbox } from "../../models/inboxModel.ts";
5 5 import { Inventory } from "../../models/inventoryModels/inventoryModel.ts";
@@ -12,33 +12,44 @@ import { Leaderboard } from "../../models/leaderboardModel.ts";
12 12 import { deleteGuild } from "../../services/guildService.ts";
13 13 import { Friendship } from "../../models/friendModel.ts";
14 14 import { sendWsBroadcastTo } from "../../services/wsService.ts";
15 import { config } from "../../services/configService.ts";
16 import { saveConfig } from "../../services/configWriterService.ts";
15 17
16 18 export const deleteAccountController: RequestHandler = async (req, res) => {
17 const accountId = await getAccountIdForRequest(req);
19 const account = await getAccountForRequest(req);
20
21 // If this account is an admin, remove it from administratorNames
22 if (config.administratorNames) {
23 const adminIndex = config.administratorNames.indexOf(account.DisplayName);
24 if (adminIndex != -1) {
25 config.administratorNames.splice(adminIndex, 1);
26 await saveConfig();
27 }
28 }
18 29
19 30 // If account is the founding warlord of a guild, delete that guild as well.
20 const guildMember = await GuildMember.findOne({ accountId, rank: 0, status: 0 });
31 const guildMember = await GuildMember.findOne({ accountId: account._id, rank: 0, status: 0 });
21 32 if (guildMember) {
22 33 await deleteGuild(guildMember.guildId);
23 34 }
24 35
25 36 await Promise.all([
26 Account.deleteOne({ _id: accountId }),
27 Friendship.deleteMany({ owner: accountId }),
28 Friendship.deleteMany({ friend: accountId }),
29 GuildMember.deleteMany({ accountId: accountId }),
30 Ignore.deleteMany({ ignorer: accountId }),
31 Ignore.deleteMany({ ignoree: accountId }),
32 Inbox.deleteMany({ ownerId: accountId }),
33 Inventory.deleteOne({ accountOwnerId: accountId }),
34 Leaderboard.deleteMany({ ownerId: accountId }),
35 Loadout.deleteOne({ loadoutOwnerId: accountId }),
36 PersonalRooms.deleteOne({ personalRoomsOwnerId: accountId }),
37 Ship.deleteMany({ ShipOwnerId: accountId }),
38 Stats.deleteOne({ accountOwnerId: accountId })
37 Account.deleteOne({ _id: account._id }),
38 Friendship.deleteMany({ owner: account._id }),
39 Friendship.deleteMany({ friend: account._id }),
40 GuildMember.deleteMany({ accountId: account._id }),
41 Ignore.deleteMany({ ignorer: account._id }),
42 Ignore.deleteMany({ ignoree: account._id }),
43 Inbox.deleteMany({ ownerId: account._id }),
44 Inventory.deleteOne({ accountOwnerId: account._id }),
45 Leaderboard.deleteMany({ ownerId: account._id }),
46 Loadout.deleteOne({ loadoutOwnerId: account._id }),
47 PersonalRooms.deleteOne({ personalRoomsOwnerId: account._id }),
48 Ship.deleteMany({ ShipOwnerId: account._id }),
49 Stats.deleteOne({ accountOwnerId: account._id })
39 50 ]);
40 51
41 sendWsBroadcastTo(accountId, { logged_out: true });
52 sendWsBroadcastTo(account._id.toString(), { logged_out: true });
42 53
43 54 res.end();
44 55 };