From cda89084d37347427e5e83513368c17fdc93ba74 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 2 Aug 2023 08:29:23 +0100 Subject: [PATCH] Show error when trader id can't be found in Traders enum Exit early when sending messages from trader if no trader supplied --- project/src/helpers/TraderHelper.ts | 9 ++++++++- project/src/services/MailSendService.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/project/src/helpers/TraderHelper.ts b/project/src/helpers/TraderHelper.ts index 2d810377..2c0ee312 100644 --- a/project/src/helpers/TraderHelper.ts +++ b/project/src/helpers/TraderHelper.ts @@ -396,6 +396,13 @@ export class TraderHelper { const keys = Object.keys(Traders).filter(x => Traders[x] === traderId); - return keys.length > 0 ? keys[0] as Traders : null; + if (keys.length === 0) + { + this.logger.error(`Unable to find trader: ${traderId} in Traders enum`); + + return null; + } + + return keys[0] as Traders; } } \ No newline at end of file diff --git a/project/src/services/MailSendService.ts b/project/src/services/MailSendService.ts index 0010fbdc..b97bb0e3 100644 --- a/project/src/services/MailSendService.ts +++ b/project/src/services/MailSendService.ts @@ -43,6 +43,13 @@ export class MailSendService */ public sendDirectNpcMessageToPlayer(playerId: string, sender: Traders, messageType: MessageType, message: string, items: Item[] = [], maxStorageTimeSeconds = null): void { + if (!sender) + { + this.logger.error(`Unable to send message type: ${messageType} to player: ${playerId}, provided trader enum was null`); + + return; + } + const details: ISendMessageDetails = { recipientId: playerId, sender: messageType, @@ -72,6 +79,13 @@ export class MailSendService */ public sendLocalisedNpcMessageToPlayer(playerId: string, sender: Traders, messageType: MessageType, messageLocaleId: string, items: Item[] = [], maxStorageTimeSeconds = null): void { + if (!sender) + { + this.logger.error(`Unable to send message type: ${messageType} to player: ${playerId}, provided trader enum was null`); + + return; + } + const details: ISendMessageDetails = { recipientId: playerId, sender: messageType,