From f7a16e15f9cabd5d5e95c4e01deb09fcec977e53 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 10 Feb 2024 16:23:26 +0000 Subject: [PATCH] Reset client output object data at end of function, instead of at start - fixes issue where old profile change data persists in memory after player logs out and into another profile Pass output into failquest function --- project/src/callbacks/InventoryCallbacks.ts | 9 +++++++-- project/src/controllers/QuestController.ts | 14 +++++++++++--- project/src/routers/ItemEventRouter.ts | 10 +++++++--- .../item_events/InventoryItemEventRouter.ts | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/project/src/callbacks/InventoryCallbacks.ts b/project/src/callbacks/InventoryCallbacks.ts index 1d1071d9..281beab3 100644 --- a/project/src/callbacks/InventoryCallbacks.ts +++ b/project/src/callbacks/InventoryCallbacks.ts @@ -206,8 +206,13 @@ export class InventoryCallbacks * TODO - MOVE INTO QUEST CODE * Handle game/profile/items/moving - QuestFail */ - public failQuest(pmcData: IPmcData, request: IFailQuestRequestData, sessionID: string): IItemEventRouterResponse + public failQuest( + pmcData: IPmcData, + request: IFailQuestRequestData, + sessionID: string, + output: IItemEventRouterResponse, + ): IItemEventRouterResponse { - return this.questController.failQuest(pmcData, request, sessionID); + return this.questController.failQuest(pmcData, request, sessionID, output); } } diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 9b8aadbc..774dc4f9 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -842,7 +842,10 @@ export class QuestController // element `location` properties of the parent so they are sequential, while retaining order if (typeof removedItem.location === "number") { - const childItems = this.itemHelper.findAndReturnChildrenAsItems(pmcData.Inventory.items, removedItem.parentId); + const childItems = this.itemHelper.findAndReturnChildrenAsItems( + pmcData.Inventory.items, + removedItem.parentId, + ); childItems.shift(); // Remove the parent // Sort by the current `location` and update @@ -948,8 +951,13 @@ export class QuestController * @param sessionID Session id * @returns IItemEventRouterResponse */ - public failQuest(pmcData: IPmcData, request: IFailQuestRequestData, sessionID: string): IItemEventRouterResponse + public failQuest( + pmcData: IPmcData, + request: IFailQuestRequestData, + sessionID: string, + output: IItemEventRouterResponse, + ): IItemEventRouterResponse { - return this.questHelper.failQuest(pmcData, request, sessionID); + return this.questHelper.failQuest(pmcData, request, sessionID, output); } } diff --git a/project/src/routers/ItemEventRouter.ts b/project/src/routers/ItemEventRouter.ts index e5f1b9a3..d19899c1 100644 --- a/project/src/routers/ItemEventRouter.ts +++ b/project/src/routers/ItemEventRouter.ts @@ -7,12 +7,14 @@ import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEve import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { EventOutputHolder } from "@spt-aki/routers/EventOutputHolder"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; +import { JsonUtil } from "@spt-aki/utils/JsonUtil"; @injectable() export class ItemEventRouter { constructor( @inject("WinstonLogger") protected logger: ILogger, + @inject("JsonUtil") protected jsonUtil: JsonUtil, @inject("ProfileHelper") protected profileHelper: ProfileHelper, @injectAll("IERouters") protected itemEventRouters: ItemEventRouterDefinition[], @inject("LocalisationService") protected localisationService: LocalisationService, @@ -27,8 +29,6 @@ export class ItemEventRouter */ public handleEvents(info: IItemEventRouterRequest, sessionID: string): IItemEventRouterResponse { - this.eventOutputHolder.resetOutput(sessionID); - const output = this.eventOutputHolder.getOutput(sessionID); for (const body of info.data) @@ -54,6 +54,10 @@ export class ItemEventRouter this.eventOutputHolder.updateOutputProperties(sessionID); - return output; + // Clone output before resetting the output object ready for use next time + const outputClone = this.jsonUtil.clone(output); + this.eventOutputHolder.resetOutput(sessionID); + + return outputClone; } } diff --git a/project/src/routers/item_events/InventoryItemEventRouter.ts b/project/src/routers/item_events/InventoryItemEventRouter.ts index e9045bb9..c2e9a9a1 100644 --- a/project/src/routers/item_events/InventoryItemEventRouter.ts +++ b/project/src/routers/item_events/InventoryItemEventRouter.ts @@ -99,7 +99,7 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition case ItemEventActions.SET_FAVORITE_ITEMS: return this.inventoryCallbacks.setFavoriteItem(pmcData, body, sessionID); case ItemEventActions.QUEST_FAIL: - return this.inventoryCallbacks.failQuest(pmcData, body, sessionID); + return this.inventoryCallbacks.failQuest(pmcData, body, sessionID, output); default: throw new Error(`Unhandled event ${url} request: ${JSON.stringify(body)}`); }