From 77bc22f27edbe56a6e237c9acab02555e9ecd1dc Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Fri, 8 Mar 2024 08:59:14 +0000 Subject: [PATCH 1/2] 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, } From 56c0007caf430c559f4fc25c9282828fdb9a5cec Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Fri, 8 Mar 2024 09:00:06 +0000 Subject: [PATCH 2/2] Fix scav case timer not taking crafting skill into account (!252) The assembly calculation for scav case timer first applies the player's crafting skill reduction, then multiplies by the resulting time by the Fence modifier: ``` return base.ReductionCoefficient * this.fenceTraderInfo_0.FenceLoyalty.ScavCaseTimeModifier; ``` This change makes the server calculation match this expected value Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/252 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/controllers/HideoutController.ts | 8 +++++--- project/src/helpers/HideoutHelper.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/project/src/controllers/HideoutController.ts b/project/src/controllers/HideoutController.ts index 59053902..889fdee6 100644 --- a/project/src/controllers/HideoutController.ts +++ b/project/src/controllers/HideoutController.ts @@ -675,9 +675,11 @@ export class HideoutController } // @Important: Here we need to be very exact: - // - normal recipe: Production time value is stored in attribute "productionType" with small "p" - // - scav case recipe: Production time value is stored in attribute "ProductionType" with capital "P" - const modifiedScavCaseTime = this.getScavCaseTime(pmcData, recipe.ProductionTime); + // - normal recipe: Production time value is stored in attribute "productionTime" with small "p" + // - scav case recipe: Production time value is stored in attribute "ProductionTime" with capital "P" + const adjustedCraftTime = recipe.ProductionTime + - this.hideoutHelper.getCraftingSkillProductionTimeReduction(pmcData, recipe.ProductionTime); + const modifiedScavCaseTime = this.getScavCaseTime(pmcData, adjustedCraftTime); pmcData.Hideout.Production[body.recipeId] = this.hideoutHelper.initProduction( body.recipeId, diff --git a/project/src/helpers/HideoutHelper.ts b/project/src/helpers/HideoutHelper.ts index 45250717..1698789e 100644 --- a/project/src/helpers/HideoutHelper.ts +++ b/project/src/helpers/HideoutHelper.ts @@ -999,7 +999,7 @@ export class HideoutHelper * @param productionTime Time to complete hideout craft in seconds * @returns Adjusted craft time in seconds */ - protected getCraftingSkillProductionTimeReduction(pmcData: IPmcData, productionTime: number): number + public getCraftingSkillProductionTimeReduction(pmcData: IPmcData, productionTime: number): number { const craftingSkill = pmcData.Skills.Common.find((skill) => skill.Id === SkillTypes.CRAFTING); if (!craftingSkill)