From 77bc22f27edbe56a6e237c9acab02555e9ecd1dc Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Fri, 8 Mar 2024 08:59:14 +0000 Subject: [PATCH] Fix being returned to the main menu when inventory full (!251) - Add a new method of sending errors back but not flagging the response as failed in ItemEventCallback - Don't treat `NOTENOUGHSPACE` errors as critical errors - Return proper `NOTENOUGHSPACE` error code for stash space issues for trader/flea/craft - Add missing error codes to `BackendErrorCodes` Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/251 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/callbacks/ItemEventCallbacks.ts | 25 +++++++++++++++++-- project/src/controllers/HideoutController.ts | 7 +++++- project/src/helpers/InventoryHelper.ts | 13 ++++++++-- project/src/models/enums/BackendErrorCodes.ts | 2 ++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/project/src/callbacks/ItemEventCallbacks.ts b/project/src/callbacks/ItemEventCallbacks.ts index ad396ff9..cd12742a 100644 --- a/project/src/callbacks/ItemEventCallbacks.ts +++ b/project/src/callbacks/ItemEventCallbacks.ts @@ -24,17 +24,38 @@ export class ItemEventCallbacks ): IGetBodyResponseData { const eventResponse = this.itemEventRouter.handleEvents(info, sessionID); - const result = (eventResponse.warnings.length > 0) + const result = (this.isCriticalError(eventResponse.warnings)) ? this.httpResponse.getBody( eventResponse, this.getErrorCode(eventResponse.warnings), eventResponse.warnings[0].errmsg, - ) // TODO: map 228 to its enum value + ) : this.httpResponse.getBody(eventResponse); return result; } + /** + * Return true if the passed in list of warnings contains critical issues + * @param warnings The list of warnings to check for critical errors + * @returns + */ + private isCriticalError(warnings: Warning[]): boolean + { + // List of non-critical error codes, we return true if any error NOT included is passed in + const nonCriticalErrorCodes: BackendErrorCodes[] = [BackendErrorCodes.NOTENOUGHSPACE]; + + for (const warning of warnings) + { + if (!nonCriticalErrorCodes.includes(+warning.code)) + { + return true; + } + } + + return false; + } + protected getErrorCode(warnings: Warning[]): number { if (warnings[0]?.code) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 1c15bbfb..59053902 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -35,6 +35,7 @@ import { IRecordShootingRangePoints } from "@spt-aki/models/eft/hideout/IRecordS import { IAddItemDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemDirectRequest"; import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; +import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { HideoutAreas } from "@spt-aki/models/enums/HideoutAreas"; import { SkillTypes } from "@spt-aki/models/enums/SkillTypes"; @@ -949,7 +950,11 @@ export class HideoutController const totalResultItems = toolsToSendToPlayer.concat(itemAndChildrenToSendToPlayer); if (!this.inventoryHelper.canPlaceItemsInInventory(sessionID, totalResultItems)) { - this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + BackendErrorCodes.NOTENOUGHSPACE, + ); return; } diff --git a/project/src/helpers/InventoryHelper.ts b/project/src/helpers/InventoryHelper.ts index 1cdd0fbe..64da9edc 100644 --- a/project/src/helpers/InventoryHelper.ts +++ b/project/src/helpers/InventoryHelper.ts @@ -20,6 +20,7 @@ import { IInventoryRemoveRequestData } from "@spt-aki/models/eft/inventory/IInve import { IInventorySplitRequestData } from "@spt-aki/models/eft/inventory/IInventorySplitRequestData"; import { IInventoryTransferRequestData } from "@spt-aki/models/eft/inventory/IInventoryTransferRequestData"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; +import { BackendErrorCodes } from "@spt-aki/models/enums/BackendErrorCodes"; import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { BonusType } from "@spt-aki/models/enums/BonusType"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; @@ -88,7 +89,11 @@ export class InventoryHelper if (!this.canPlaceItemsInInventory(sessionId, request.itemsWithModsToAdd)) { // No space, exit - this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + BackendErrorCodes.NOTENOUGHSPACE, + ); return; } @@ -470,7 +475,11 @@ export class InventoryHelper } else { - this.httpResponse.appendErrorToOutput(output, this.localisationService.getText("inventory-no_stash_space")); + this.httpResponse.appendErrorToOutput( + output, + this.localisationService.getText("inventory-no_stash_space"), + BackendErrorCodes.NOTENOUGHSPACE, + ); return; } diff --git a/project/src/models/enums/BackendErrorCodes.ts b/project/src/models/enums/BackendErrorCodes.ts index 81f00650..3a9eff12 100644 --- a/project/src/models/enums/BackendErrorCodes.ts +++ b/project/src/models/enums/BackendErrorCodes.ts @@ -63,6 +63,7 @@ export enum BackendErrorCodes BANNEDERRORCODE = 1513, INSUFFICIENTNUMBERINSTOCK = 1516, TOOMANYITEMSTOSELL = 1517, + INCORRECTCLIENTPRICE = 1519, EXAMINATIONFAILED = 22001, ITEMALREADYEXAMINED = 22002, UNKNOWNNGINXERROR = 9000, @@ -83,4 +84,5 @@ export enum BackendErrorCodes PLAYERALREADYLOOKINGFORGAME = 503001, PLAYERINRAID = 503002, LIMITFORPRESETSREACHED = 504001, + PLAYERPROFILENOTFOUND = 505001, }