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

feat: ignore list (#1711)

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

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

代码差异

9 个文件 +95 -16
Added src/controllers/api/addIgnoredUserController.ts +30 -0
@@ -0,0 +1,30 @@
1 import { toOid } from "@/src/helpers/inventoryHelpers";
2 import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 import { Account, Ignore } from "@/src/models/loginModel";
4 import { getAccountIdForRequest } from "@/src/services/loginService";
5 import { IFriendInfo } from "@/src/types/guildTypes";
6 import { RequestHandler } from "express";
7
8 export const addIgnoredUserController: RequestHandler = async (req, res) => {
9 const accountId = await getAccountIdForRequest(req);
10 const data = getJSONfromString<IAddIgnoredUserRequest>(String(req.body));
11 const ignoreeAccount = await Account.findOne(
12 { DisplayName: data.playerName.substring(0, data.playerName.length - 1) },
13 "_id"
14 );
15 if (ignoreeAccount) {
16 await Ignore.create({ ignorer: accountId, ignoree: ignoreeAccount._id });
17 res.json({
18 Ignored: {
19 _id: toOid(ignoreeAccount._id),
20 DisplayName: data.playerName
21 } satisfies IFriendInfo
22 });
23 } else {
24 res.status(400).end();
25 }
26 };
27
28 interface IAddIgnoredUserRequest {
29 playerName: string;
30 }
Modified src/controllers/api/getIgnoredUsersController.ts +16 -12
@@ -1,16 +1,20 @@
1 import { toOid } from "@/src/helpers/inventoryHelpers";
2 import { Account, Ignore } from "@/src/models/loginModel";
3 import { getAccountIdForRequest } from "@/src/services/loginService";
4 import { IFriendInfo } from "@/src/types/guildTypes";
5 import { parallelForeach } from "@/src/utils/async-utils";
1 6 import { RequestHandler } from "express";
2 7
3 const getIgnoredUsersController: RequestHandler = (_req, res) => {
4 res.writeHead(200, {
5 "Content-Type": "text/html",
6 "Content-Length": "3"
8 export const getIgnoredUsersController: RequestHandler = async (req, res) => {
9 const accountId = await getAccountIdForRequest(req);
10 const ignores = await Ignore.find({ ignorer: accountId });
11 const ignoredUsers: IFriendInfo[] = [];
12 await parallelForeach(ignores, async ignore => {
13 const ignoreeAccount = (await Account.findById(ignore.ignoree, "DisplayName"))!;
14 ignoredUsers.push({
15 _id: toOid(ignore.ignoree),
16 DisplayName: ignoreeAccount.DisplayName + ""
17 });
7 18 });
8 res.end(
9 Buffer.from([
10 0x7b, 0x22, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x38, 0x33, 0x30, 0x34, 0x30, 0x37, 0x37, 0x32, 0x32,
11 0x34, 0x30, 0x32, 0x32, 0x32, 0x36, 0x31, 0x35, 0x30, 0x31, 0x7d
12 ])
13 );
19 res.json({ IgnoredUsers: ignoredUsers });
14 20 };
15
16 export { getIgnoredUsersController };
Added src/controllers/api/removeIgnoredUserController.ts +21 -0
@@ -0,0 +1,21 @@
1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 import { Account, Ignore } from "@/src/models/loginModel";
3 import { getAccountForRequest } from "@/src/services/loginService";
4 import { RequestHandler } from "express";
5
6 export const removeIgnoredUserController: RequestHandler = async (req, res) => {
7 const accountId = await getAccountForRequest(req);
8 const data = getJSONfromString<IRemoveIgnoredUserRequest>(String(req.body));
9 const ignoreeAccount = await Account.findOne(
10 { DisplayName: data.playerName.substring(0, data.playerName.length - 1) },
11 "_id"
12 );
13 if (ignoreeAccount) {
14 await Ignore.deleteOne({ ignorer: accountId, ignoree: ignoreeAccount._id });
15 }
16 res.end();
17 };
18
19 interface IRemoveIgnoredUserRequest {
20 playerName: string;
21 }
Modified src/controllers/custom/deleteAccountController.ts +3 -1
@@ -1,6 +1,6 @@
1 1 import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { Account } from "@/src/models/loginModel";
3 import { Account, Ignore } from "@/src/models/loginModel";
4 4 import { Inbox } from "@/src/models/inboxModel";
5 5 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
6 6 import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
@@ -23,6 +23,8 @@ export const deleteAccountController: RequestHandler = async (req, res) => {
23 23 await Promise.all([
24 24 Account.deleteOne({ _id: accountId }),
25 25 GuildMember.deleteMany({ accountId: accountId }),
26 Ignore.deleteMany({ ignorer: accountId }),
27 Ignore.deleteMany({ ignoree: accountId }),
26 28 Inbox.deleteMany({ ownerId: accountId }),
27 29 Inventory.deleteOne({ accountOwnerId: accountId }),
28 30 Leaderboard.deleteMany({ ownerId: accountId }),
Modified src/models/loginModel.ts +11 -1
@@ -1,4 +1,4 @@
1 import { IDatabaseAccountJson } from "@/src/types/loginTypes";
1 import { IDatabaseAccountJson, IIgnore } from "@/src/types/loginTypes";
2 2 import { model, Schema, SchemaOptions } from "mongoose";
3 3
4 4 const opts = {
@@ -37,3 +37,13 @@ databaseAccountSchema.set("toJSON", {
37 37 });
38 38
39 39 export const Account = model<IDatabaseAccountJson>("Account", databaseAccountSchema);
40
41 const ignoreSchema = new Schema<IIgnore>({
42 ignorer: Schema.Types.ObjectId,
43 ignoree: Schema.Types.ObjectId
44 });
45
46 ignoreSchema.index({ ignorer: 1 });
47 ignoreSchema.index({ ignorer: 1, ignoree: 1 }, { unique: true });
48
49 export const Ignore = model<IIgnore>("Ignore", ignoreSchema);
Modified src/routes/api.ts +4 -0
@@ -4,6 +4,7 @@ import { abortDojoComponentController } from "@/src/controllers/api/abortDojoCom
4 4 import { abortDojoComponentDestructionController } from "@/src/controllers/api/abortDojoComponentDestructionController";
5 5 import { activateRandomModController } from "@/src/controllers/api/activateRandomModController";
6 6 import { addFriendImageController } from "@/src/controllers/api/addFriendImageController";
7 import { addIgnoredUserController } from "@/src/controllers/api/addIgnoredUserController";
7 8 import { addToAllianceController } from "@/src/controllers/api/addToAllianceController";
8 9 import { addToGuildController } from "@/src/controllers/api/addToGuildController";
9 10 import { arcaneCommonController } from "@/src/controllers/api/arcaneCommonController";
@@ -97,6 +98,7 @@ import { redeemPromoCodeController } from "@/src/controllers/api/redeemPromoCode
97 98 import { releasePetController } from "@/src/controllers/api/releasePetController";
98 99 import { removeFromAllianceController } from "@/src/controllers/api/removeFromAllianceController";
99 100 import { removeFromGuildController } from "@/src/controllers/api/removeFromGuildController";
101 import { removeIgnoredUserController } from "@/src/controllers/api/removeIgnoredUserController";
100 102 import { rerollRandomModController } from "@/src/controllers/api/rerollRandomModController";
101 103 import { retrievePetFromStasisController } from "@/src/controllers/api/retrievePetFromStasisController";
102 104 import { saveDialogueController } from "@/src/controllers/api/saveDialogueController";
@@ -202,6 +204,7 @@ apiRouter.get("/updateSession.php", updateSessionGetController);
202 204 apiRouter.post("/abortDojoComponent.php", abortDojoComponentController);
203 205 apiRouter.post("/activateRandomMod.php", activateRandomModController);
204 206 apiRouter.post("/addFriendImage.php", addFriendImageController);
207 apiRouter.post("/addIgnoredUser.php", addIgnoredUserController);
205 208 apiRouter.post("/addToAlliance.php", addToAllianceController);
206 209 apiRouter.post("/addToGuild.php", addToGuildController);
207 210 apiRouter.post("/arcaneCommon.php", arcaneCommonController);
@@ -266,6 +269,7 @@ apiRouter.post("/purchase.php", purchaseController);
266 269 apiRouter.post("/redeemPromoCode.php", redeemPromoCodeController);
267 270 apiRouter.post("/releasePet.php", releasePetController);
268 271 apiRouter.post("/removeFromGuild.php", removeFromGuildController);
272 apiRouter.post("/removeIgnoredUser.php", removeIgnoredUserController);
269 273 apiRouter.post("/rerollRandomMod.php", rerollRandomModController);
270 274 apiRouter.post("/retrievePetFromStasis.php", retrievePetFromStasisController);
271 275 apiRouter.post("/saveDialogue.php", saveDialogueController);
Modified src/types/guildTypes.ts +2 -2
@@ -103,12 +103,12 @@ export interface IGuildMemberDatabase {
103 103 ShipDecorationsContributed?: ITypeCount[];
104 104 }
105 105
106 interface IFriendInfo {
106 export interface IFriendInfo {
107 107 _id: IOid;
108 108 DisplayName?: string;
109 109 PlatformNames?: string[];
110 110 PlatformAccountId?: string;
111 Status: number;
111 Status?: number;
112 112 ActiveAvatarImageType?: string;
113 113 LastLogin?: IMongoDate;
114 114 PlayerLevel?: number;
Modified src/types/loginTypes.ts +7 -0
@@ -1,3 +1,5 @@
1 import { Types } from "mongoose";
2
1 3 export interface IAccountAndLoginResponseCommons {
2 4 DisplayName: string;
3 5 CountryCode: string;
@@ -56,3 +58,8 @@ export interface IGroup {
56 58 experiment: string;
57 59 experimentGroup: string;
58 60 }
61
62 export interface IIgnore {
63 ignorer: Types.ObjectId;
64 ignoree: Types.ObjectId;
65 }
Modified src/utils/async-utils.ts +1 -0
@@ -1,3 +1,4 @@
1 // Misnomer: We have concurrency, not parallelism - oh well!
1 2 export const parallelForeach = async <T>(data: T[], op: (datum: T) => Promise<void>): Promise<void> => {
2 3 const promises: Promise<void>[] = [];
3 4 for (const datum of data) {