From cbcd431f091d647bc86e9ac345d11f99b7cdb347 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 3 Aug 2023 12:25:09 +0100 Subject: [PATCH] Fixed new profiles failing to start game during christmas/new years event Add new function in dialog helper for getting dialogs frm profile - creates empty object if none found Set gift collection time to 48 hours if none supplied --- project/assets/configs/gifts.json | 3 +- project/src/controllers/DialogueController.ts | 28 +++++++++++-------- project/src/helpers/DialogueHelper.ts | 16 +++++++++++ project/src/services/GiftService.ts | 5 ++++ project/src/services/MailSendService.ts | 4 ++- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/project/assets/configs/gifts.json b/project/assets/configs/gifts.json index 9f4e9b93..a6474e6c 100644 --- a/project/assets/configs/gifts.json +++ b/project/assets/configs/gifts.json @@ -215,7 +215,8 @@ "sender": "System", "messageText": "Merry christmas!", "timestampToSend": 42069, - "associatedEvent": "Christmas" + "associatedEvent": "Christmas", + "collectionTimeHours": 48, }, "1CLICKDRESSUP": { "items": [{ diff --git a/project/src/controllers/DialogueController.ts b/project/src/controllers/DialogueController.ts index 81e463ce..3ad59657 100644 --- a/project/src/controllers/DialogueController.ts +++ b/project/src/controllers/DialogueController.ts @@ -72,7 +72,7 @@ export class DialogueController public generateDialogueList(sessionID: string): DialogueInfo[] { const data: DialogueInfo[] = []; - for (const dialogueId in this.saveServer.getProfile(sessionID).dialogues) + for (const dialogueId in this.dialogueHelper.getDialogsForProfile(sessionID).dialogues) { data.push(this.getDialogueInfo(dialogueId, sessionID)); } @@ -88,7 +88,7 @@ export class DialogueController */ public getDialogueInfo(dialogueID: string, sessionID: string): DialogueInfo { - const dialogue = this.saveServer.getProfile(sessionID).dialogues[dialogueID]; + const dialogue = this.dialogueHelper.getDialogsForProfile(sessionID).dialogues[dialogueID]; const result: DialogueInfo = { _id: dialogueID, @@ -277,8 +277,7 @@ export class DialogueController /** Handle client/mail/dialog/pin && Handle client/mail/dialog/unpin */ public setDialoguePin(dialogueId: string, shouldPin: boolean, sessionId: string): void { - const profile = this.saveServer.getProfile(sessionId); - const dialog = profile.dialogues[dialogueId]; + const dialog = this.dialogueHelper.getDialogsForProfile(sessionId)[dialogueId]; if (!dialog) { this.logger.error(`No dialog in profile: ${sessionId} found with id: ${dialogueId}`); @@ -297,8 +296,7 @@ export class DialogueController */ public setRead(dialogueIds: string[], sessionId: string): void { - const profile = this.saveServer.getProfile(sessionId); - const dialogs = profile.dialogues; + const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId); if (!dialogs) { this.logger.error(`No dialog object in profile: ${sessionId}`); @@ -322,8 +320,8 @@ export class DialogueController */ public getAllAttachments(dialogueId: string, sessionId: string): IGetAllAttachmentsResponse { - const profile = this.saveServer.getProfile(sessionId); - const dialog = profile.dialogues[dialogueId]; + const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId); + const dialog = dialogs[dialogueId]; if (!dialog) { this.logger.error(`No dialog in profile: ${sessionId} found with id: ${dialogueId}`); @@ -434,7 +432,8 @@ export class DialogueController protected getActiveMessagesFromDialog(sessionId: string, dialogueId: string): Message[] { const timeNow = this.timeUtil.getTimestamp(); - return this.saveServer.getProfile(sessionId).dialogues[dialogueId].messages.filter(x => timeNow < (x.dt + x.maxStorageTime)); + const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId); + return dialogs[dialogueId].messages.filter(x => timeNow < (x.dt + x.maxStorageTime)); } /** @@ -453,7 +452,7 @@ export class DialogueController */ protected removeExpiredItemsFromMessages(sessionId: string): void { - for (const dialogueId in this.saveServer.getProfile(sessionId).dialogues) + for (const dialogueId in this.dialogueHelper.getDialogsForProfile(sessionId)) { this.removeExpiredItemsFromMessage(sessionId, dialogueId); } @@ -466,7 +465,14 @@ export class DialogueController */ protected removeExpiredItemsFromMessage(sessionId: string, dialogueId: string): void { - for (const message of this.saveServer.getProfile(sessionId).dialogues[dialogueId].messages) + const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId); + const dialog = dialogs[dialogueId]; + if (!dialog.messages) + { + return; + } + + for (const message of dialog.messages) { if (this.messageHasExpired(message)) { diff --git a/project/src/helpers/DialogueHelper.ts b/project/src/helpers/DialogueHelper.ts index a32332fa..d15bb149 100644 --- a/project/src/helpers/DialogueHelper.ts +++ b/project/src/helpers/DialogueHelper.ts @@ -223,4 +223,20 @@ export class DialogueHelper return []; } + + /** + * Get the dialogs dictionary for a profile, create if doesnt exist + * @param sessionId Session/player id + * @returns Dialog dictionary + */ + public getDialogsForProfile(sessionId: string): Record + { + const profile = this.saveServer.getProfile(sessionId); + if (!profile.dialogues) + { + profile.dialogues = {}; + } + + return profile.dialogues; + } } \ No newline at end of file diff --git a/project/src/services/GiftService.ts b/project/src/services/GiftService.ts index 67d5a045..4d07d87e 100644 --- a/project/src/services/GiftService.ts +++ b/project/src/services/GiftService.ts @@ -61,6 +61,11 @@ export class GiftService return GiftSentResult.FAILED_GIFT_ALREADY_RECEIVED; } + if (giftData.items?.length > 0 && !giftData.collectionTimeHours) + { + this.logger.warning(`Gift ${giftId} has items but no collection time limit, defaulting to 48 hours`); + } + // Handle system messsages if (giftData.sender === GiftSenderType.SYSTEM) { diff --git a/project/src/services/MailSendService.ts b/project/src/services/MailSendService.ts index b97bb0e3..6926215e 100644 --- a/project/src/services/MailSendService.ts +++ b/project/src/services/MailSendService.ts @@ -1,4 +1,5 @@ import { inject, injectable } from "tsyringe"; +import { DialogueHelper } from "../helpers/DialogueHelper"; import { ItemHelper } from "../helpers/ItemHelper"; import { NotificationSendHelper } from "../helpers/NotificationSendHelper"; import { NotifierHelper } from "../helpers/NotifierHelper"; @@ -26,6 +27,7 @@ export class MailSendService @inject("SaveServer") protected saveServer: SaveServer, @inject("DatabaseServer") protected databaseServer: DatabaseServer, @inject("NotifierHelper") protected notifierHelper: NotifierHelper, + @inject("DialogueHelper") protected dialogueHelper: DialogueHelper, @inject("NotificationSendHelper") protected notificationSendHelper: NotificationSendHelper, @inject("LocalisationService") protected localisationService: LocalisationService, @inject("ItemHelper") protected itemHelper: ItemHelper @@ -361,7 +363,7 @@ export class MailSendService */ protected getDialog(messageDetails: ISendMessageDetails): Dialogue { - const dialogsInProfile = this.saveServer.getProfile(messageDetails.recipientId).dialogues; + const dialogsInProfile = this.dialogueHelper.getDialogsForProfile(messageDetails.recipientId); const senderId = this.getMessageSenderIdByType(messageDetails); // Does dialog exist