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: use stricter schema validation for CurrentLoadOutIds (#3390)

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

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

代码差异

7 个文件 +19 -32
Modified src/controllers/api/nemesisController.ts +3 -7
@@ -1,4 +1,4 @@
1 import { fromDbOid, fromOid, toMongoDate, version_compare } from "../../helpers/inventoryHelpers.ts";
1 import { fromOid, toMongoDate, version_compare } from "../../helpers/inventoryHelpers.ts";
2 2 import type { IKnifeResponse } from "../../helpers/nemesisHelpers.ts";
3 3 import {
4 4 antivirusMods,
@@ -129,9 +129,7 @@ export const nemesisController: RequestHandler = async (req, res) => {
129 129 if (result1 == GUESS_CORRECT || result2 == GUESS_CORRECT || result3 == GUESS_CORRECT) {
130 130 let antivirusGain = 5;
131 131 const loadout = (await Loadout.findById(inventory.LoadOutPresets, "DATAKNIFE"))!;
132 const dataknifeLoadout = loadout.DATAKNIFE.id(
133 fromDbOid(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE])
134 );
132 const dataknifeLoadout = loadout.DATAKNIFE.id(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE]);
135 133 const dataknifeConfigIndex = dataknifeLoadout?.s?.mod ?? 0;
136 134 const dataknifeUpgrades = inventory.DataKnives[0].Configs[dataknifeConfigIndex].Upgrades!;
137 135 for (const upgrade of body.knife!.AttachedUpgrades) {
@@ -222,9 +220,7 @@ export const nemesisController: RequestHandler = async (req, res) => {
222 220
223 221 // Subtract a charge from all requiem mods installed on parazon
224 222 const loadout = (await Loadout.findById(inventory.LoadOutPresets, "DATAKNIFE"))!;
225 const dataknifeLoadout = loadout.DATAKNIFE.id(
226 fromDbOid(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE])
227 );
223 const dataknifeLoadout = loadout.DATAKNIFE.id(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE]);
228 224 const dataknifeConfigIndex = dataknifeLoadout?.s?.mod ?? 0;
229 225 const dataknifeUpgrades = inventory.DataKnives[0].Configs[dataknifeConfigIndex].Upgrades!;
230 226 for (let i = 3; i != 6; ++i) {
Modified src/controllers/dynamic/getProfileViewingDataController.ts +6 -6
@@ -1,4 +1,4 @@
1 import { fromDbOid, toMongoDate, toOid } from "../../helpers/inventoryHelpers.ts";
1 import { fromOid, toMongoDate, toOid } from "../../helpers/inventoryHelpers.ts";
2 2 import type { TGuildDatabaseDocument } from "../../models/guildModel.ts";
3 3 import { Guild, GuildMember } from "../../models/guildModel.ts";
4 4 import type { TInventoryDatabaseDocument } from "../../models/inventoryModels/inventoryModel.ts";
@@ -318,31 +318,31 @@ const populateLoadout = async (
318 318 if (inventory.CurrentLoadOutIds.length) {
319 319 const loadout = (await Loadout.findById(inventory.LoadOutPresets, "NORMAL"))!;
320 320 result.LoadOutPreset = loadout.NORMAL.id(
321 fromDbOid(inventory.CurrentLoadOutIds[LoadoutIndex.NORMAL])
321 inventory.CurrentLoadOutIds[LoadoutIndex.NORMAL]
322 322 )!.toJSON<ILoadoutConfigClient>();
323 323 result.LoadOutPreset.ItemId = undefined;
324 324 const skins = new Set<string>();
325 325 if (result.LoadOutPreset.s?.ItemId) {
326 326 result.LoadOutInventory.Suits = [
327 inventory.Suits.id(fromDbOid(result.LoadOutPreset.s.ItemId))!.toJSON<IEquipmentClient>()
327 inventory.Suits.id(fromOid(result.LoadOutPreset.s.ItemId))!.toJSON<IEquipmentClient>()
328 328 ];
329 329 resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.Suits[0]);
330 330 }
331 331 if (result.LoadOutPreset.p?.ItemId) {
332 332 result.LoadOutInventory.Pistols = [
333 inventory.Pistols.id(fromDbOid(result.LoadOutPreset.p.ItemId))!.toJSON<IEquipmentClient>()
333 inventory.Pistols.id(fromOid(result.LoadOutPreset.p.ItemId))!.toJSON<IEquipmentClient>()
334 334 ];
335 335 resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.Pistols[0]);
336 336 }
337 337 if (result.LoadOutPreset.l?.ItemId) {
338 338 result.LoadOutInventory.LongGuns = [
339 inventory.LongGuns.id(fromDbOid(result.LoadOutPreset.l.ItemId))!.toJSON<IEquipmentClient>()
339 inventory.LongGuns.id(fromOid(result.LoadOutPreset.l.ItemId))!.toJSON<IEquipmentClient>()
340 340 ];
341 341 resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.LongGuns[0]);
342 342 }
343 343 if (result.LoadOutPreset.m?.ItemId) {
344 344 result.LoadOutInventory.Melee = [
345 inventory.Melee.id(fromDbOid(result.LoadOutPreset.m.ItemId))!.toJSON<IEquipmentClient>()
345 inventory.Melee.id(fromOid(result.LoadOutPreset.m.ItemId))!.toJSON<IEquipmentClient>()
346 346 ];
347 347 resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.Melee[0]);
348 348 }
Modified src/models/inventoryModels/inventoryModel.ts +3 -3
@@ -112,7 +112,7 @@ import type {
112 112 IOperatorConfigDatabase,
113 113 IPolarity
114 114 } from "../../types/inventoryTypes/commonInventoryTypes.ts";
115 import { fromDbOid, toMongoDate, toOid } from "../../helpers/inventoryHelpers.ts";
115 import { toMongoDate, toOid } from "../../helpers/inventoryHelpers.ts";
116 116 import { EquipmentSelectionSchema } from "./loadoutModel.ts";
117 117 import type { ICountedStoreItem } from "warframe-public-export-plus";
118 118 import { colorSchema, shipCustomizationSchema } from "../commonModel.ts";
@@ -1926,7 +1926,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
1926 1926 HasContributedToDojo: Boolean,
1927 1927 HWIDProtectEnabled: Boolean,
1928 1928 LoadOutPresets: { type: Schema.Types.ObjectId, ref: "Loadout" },
1929 CurrentLoadOutIds: [Schema.Types.Mixed], // should be Types.ObjectId[] but might be IOid[] because of old commits
1929 CurrentLoadOutIds: { type: [Schema.Types.ObjectId] },
1930 1930 RandomUpgradesIdentified: Number,
1931 1931 BountyScore: Number,
1932 1932 ChallengeInstanceStates: { type: [challengeInstanceStateSchema], default: undefined },
@@ -2002,7 +2002,7 @@ inventorySchema.set("toJSON", {
2002 2002 inventoryResponse.Created = toMongoDate(inventoryDatabase.Created);
2003 2003 }
2004 2004 if (inventoryDatabase.CurrentLoadOutIds) {
2005 inventoryResponse.CurrentLoadOutIds = inventoryDatabase.CurrentLoadOutIds.map(x => toOid(fromDbOid(x)));
2005 inventoryResponse.CurrentLoadOutIds = inventoryDatabase.CurrentLoadOutIds.map(x => toOid(x));
2006 2006 }
2007 2007 if (inventoryDatabase.TrainingDate) {
2008 2008 inventoryResponse.TrainingDate = toMongoDate(inventoryDatabase.TrainingDate);
Modified src/services/inventoryService.ts +0 -3
@@ -62,7 +62,6 @@ import { createShip } from "./shipService.ts";
62 62 import type { TTraitsPool } from "../helpers/inventoryHelpers.ts";
63 63 import {
64 64 catbrowDetails,
65 fromDbOid,
66 65 fromMongoDate,
67 66 fromOid,
68 67 kubrowDetails,
@@ -2579,8 +2578,6 @@ export const setupKahlSyndicate = (inventory: TInventoryDatabaseDocument): void
2579 2578 };
2580 2579
2581 2580 export const cleanupInventory = async (inventory: TInventoryDatabaseDocument): Promise<void> => {
2582 inventory.CurrentLoadOutIds = inventory.CurrentLoadOutIds.map(fromDbOid);
2583
2584 2581 if (ensureOperatorSuitsRemasterData(inventory)) {
2585 2582 logger.debug(`added missing Operator suits for Operator remaster`);
2586 2583 }
Modified src/services/saveLoadoutService.ts +5 -11
@@ -12,13 +12,7 @@ import { addMods, getInventory } from "./inventoryService.ts";
12 12 import type { IOidWithLegacySupport } from "../types/commonTypes.ts";
13 13 import { Types } from "mongoose";
14 14 import { isEmptyObject } from "../helpers/general.ts";
15 import {
16 convertLegacyColorsToIColor,
17 fromDbOid,
18 fromOid,
19 toObjectId,
20 version_compare
21 } from "../helpers/inventoryHelpers.ts";
15 import { convertLegacyColorsToIColor, fromOid, toObjectId, version_compare } from "../helpers/inventoryHelpers.ts";
22 16 import { logger } from "../utils/logger.ts";
23 17 import type { TEquipmentKey } from "../types/inventoryTypes/inventoryTypes.ts";
24 18 import { equipmentKeys } from "../types/inventoryTypes/inventoryTypes.ts";
@@ -395,7 +389,7 @@ const saveLegacyLoadoutPreset = async (
395 389 throw new Error("loadout not found");
396 390 }
397 391
398 const currentLoadouts = inventory.CurrentLoadOutIds as Types.ObjectId[];
392 const currentLoadouts = inventory.CurrentLoadOutIds;
399 393
400 394 const s =
401 395 fromOid(presets[0].ItemId) != "ffffffffffffffffffffffff"
@@ -450,7 +444,7 @@ const saveLegacyLoadoutPreset = async (
450 444 currentLoadouts[0] = loadoutId;
451 445 }
452 446 } else {
453 const loadoutId = fromDbOid(currentLoadouts[0]);
447 const loadoutId = currentLoadouts[0];
454 448 const preset = loadout.NORMAL.id(loadoutId);
455 449 if (preset) {
456 450 preset.n = name ?? preset.n;
@@ -499,7 +493,7 @@ const saveLegacyLoadoutPreset = async (
499 493 currentLoadouts[1] = loadoutId;
500 494 }
501 495 } else {
502 const loadoutId = fromDbOid(currentLoadouts[1]);
496 const loadoutId = currentLoadouts[1];
503 497 const preset = loadout.SENTINEL.id(loadoutId);
504 498 if (preset) {
505 499 preset.n = name ?? preset.n;
@@ -542,7 +536,7 @@ const saveLegacyLoadoutPreset = async (
542 536 currentLoadouts[2] = loadoutId;
543 537 }
544 538 } else {
545 const loadoutId = fromDbOid(currentLoadouts[2]);
539 const loadoutId = currentLoadouts[2];
546 540 const preset = loadout.ARCHWING.id(loadoutId);
547 541 if (preset) {
548 542 preset.n = name ?? preset.n;
Modified src/types/equipmentTypes.ts +1 -1
@@ -17,7 +17,7 @@ export interface IEquipmentSelectionClient {
17 17 }
18 18
19 19 export interface IEquipmentSelectionDatabase extends Omit<IEquipmentSelectionClient, "ItemId"> {
20 ItemId?: Types.ObjectId | IOid; // should be Types.ObjectId but might be IOid because of old commits
20 ItemId?: Types.ObjectId | IOid; // should be Types.ObjectId but might be IOid
21 21 }
22 22
23 23 export enum EquipmentFeatures {
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -1
@@ -152,7 +152,7 @@ export interface IInventoryDatabase
152 152 NemesisTaxedCredits?: number;
153 153
154 154 Created: Date;
155 CurrentLoadOutIds: Types.ObjectId[] | IOid[]; // should be Types.ObjectId[] but might be IOid[] because of old commits
155 CurrentLoadOutIds: Types.ObjectId[];
156 156 TrainingDate: Date;
157 157 LoadOutPresets: Types.ObjectId; // LoadOutPresets changed from ILoadOutPresets to Types.ObjectId for population
158 158 //Mailbox?: IMailboxDatabase;