Show error when trader id can't be found in Traders enum

Exit early when sending messages from trader if no trader supplied
This commit is contained in:
Dev 2023-08-02 08:29:23 +01:00
parent 177a01439b
commit cda89084d3
2 changed files with 22 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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,