From 9fe739debbbec14003b52442288bab43c82ac0e0 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 10 Feb 2024 15:44:21 +0000 Subject: [PATCH] EXPERIMENTAL - pass output object into handleItemEvent and into move function --- project/src/callbacks/InventoryCallbacks.ts | 11 +++++++++-- project/src/controllers/InventoryController.ts | 17 +++++++++-------- project/src/di/Router.ts | 8 +++++++- project/src/routers/ItemEventRouter.ts | 10 +++++++--- .../item_events/InventoryItemEventRouter.ts | 3 ++- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/project/src/callbacks/InventoryCallbacks.ts b/project/src/callbacks/InventoryCallbacks.ts index d1a048ee..40ca6c20 100644 --- a/project/src/callbacks/InventoryCallbacks.ts +++ b/project/src/callbacks/InventoryCallbacks.ts @@ -35,9 +35,16 @@ export class InventoryCallbacks {} /** Handle client/game/profile/items/moving Move event */ - public moveItem(pmcData: IPmcData, body: IInventoryMoveRequestData, sessionID: string): IItemEventRouterResponse + public moveItem( + pmcData: IPmcData, + body: IInventoryMoveRequestData, + sessionID: string, + output: IItemEventRouterResponse, + ): IItemEventRouterResponse { - return this.inventoryController.moveItem(pmcData, body, sessionID); + this.inventoryController.moveItem(pmcData, body, sessionID, output); + + return output; } /** Handle Remove event */ diff --git a/project/src/controllers/InventoryController.ts b/project/src/controllers/InventoryController.ts index 8c6471a7..2809f4ad 100644 --- a/project/src/controllers/InventoryController.ts +++ b/project/src/controllers/InventoryController.ts @@ -86,13 +86,12 @@ export class InventoryController pmcData: IPmcData, moveRequest: IInventoryMoveRequestData, sessionID: string, - ): IItemEventRouterResponse + output: IItemEventRouterResponse, + ): void { - const output = this.eventOutputHolder.getOutput(sessionID); - if (output.warnings.length > 0) { - return output; + return; } // Changes made to result apply to character inventory @@ -102,7 +101,8 @@ export class InventoryController // Dont move items from trader to profile, this can happen when editing a traders preset weapons if (moveRequest.fromOwner?.type === "Trader" && !ownerInventoryItems.isMail) { - return this.getTraderExploitErrorResponse(output); + this.getTraderExploitErrorResponse(output); + return; } // Check for item in inventory before allowing internal transfer @@ -111,13 +111,15 @@ export class InventoryController if (!originalItemLocation) { // Internal item move but item never existed, possible dupe glitch - return this.getTraderExploitErrorResponse(output); + this.getTraderExploitErrorResponse(output); + return; } const moveResult = this.inventoryHelper.moveItemInternal(pmcData, ownerInventoryItems.from, moveRequest); if (!moveResult.success) { - return this.httpResponseUtil.appendErrorToOutput(output, moveResult.errorMessage); + this.httpResponseUtil.appendErrorToOutput(output, moveResult.errorMessage); + return; } // Item is moving into or out of place of fame dogtag slot @@ -130,7 +132,6 @@ export class InventoryController { this.inventoryHelper.moveItemToProfile(ownerInventoryItems.from, ownerInventoryItems.to, moveRequest); } - return output; } /** diff --git a/project/src/di/Router.ts b/project/src/di/Router.ts index 9eefe56f..18e5b8c6 100644 --- a/project/src/di/Router.ts +++ b/project/src/di/Router.ts @@ -75,7 +75,13 @@ export class DynamicRouter extends Router // So instead I added the definition export class ItemEventRouterDefinition extends Router { - public handleItemEvent(url: string, pmcData: IPmcData, body: any, sessionID: string): IItemEventRouterResponse + public handleItemEvent( + url: string, + pmcData: IPmcData, + body: any, + sessionID: string, + output: IItemEventRouterResponse, + ): void { throw new Error("This method needs to be overrode by the router classes"); } diff --git a/project/src/routers/ItemEventRouter.ts b/project/src/routers/ItemEventRouter.ts index a1bf45fb..e5f1b9a3 100644 --- a/project/src/routers/ItemEventRouter.ts +++ b/project/src/routers/ItemEventRouter.ts @@ -29,7 +29,7 @@ export class ItemEventRouter { this.eventOutputHolder.resetOutput(sessionID); - let result = this.eventOutputHolder.getOutput(sessionID); + const output = this.eventOutputHolder.getOutput(sessionID); for (const body of info.data) { @@ -39,7 +39,11 @@ export class ItemEventRouter if (eventRouter) { this.logger.debug(`event: ${body.Action}`); - result = eventRouter.handleItemEvent(body.Action, pmcData, body, sessionID); + eventRouter.handleItemEvent(body.Action, pmcData, body, sessionID, output); + if (output.warnings.length > 0) + { + break; + } } else { @@ -50,6 +54,6 @@ export class ItemEventRouter this.eventOutputHolder.updateOutputProperties(sessionID); - return result; + return output; } } diff --git a/project/src/routers/item_events/InventoryItemEventRouter.ts b/project/src/routers/item_events/InventoryItemEventRouter.ts index a43da2af..cff66a91 100644 --- a/project/src/routers/item_events/InventoryItemEventRouter.ts +++ b/project/src/routers/item_events/InventoryItemEventRouter.ts @@ -51,12 +51,13 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition pmcData: IPmcData, body: any, sessionID: string, + output: IItemEventRouterResponse, ): IItemEventRouterResponse { switch (url) { case ItemEventActions.MOVE: - return this.inventoryCallbacks.moveItem(pmcData, body, sessionID); + return this.inventoryCallbacks.moveItem(pmcData, body, sessionID, output); case ItemEventActions.REMOVE: return this.inventoryCallbacks.removeItem(pmcData, body, sessionID); case ItemEventActions.SPLIT: