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
This commit is contained in:
Dev 2023-08-03 12:25:09 +01:00
parent 0c37a76ff6
commit cbcd431f09
5 changed files with 43 additions and 13 deletions

View File

@ -215,7 +215,8 @@
"sender": "System",
"messageText": "Merry christmas!",
"timestampToSend": 42069,
"associatedEvent": "Christmas"
"associatedEvent": "Christmas",
"collectionTimeHours": 48,
},
"1CLICKDRESSUP": {
"items": [{

View File

@ -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))
{

View File

@ -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<string, Dialogue>
{
const profile = this.saveServer.getProfile(sessionId);
if (!profile.dialogues)
{
profile.dialogues = {};
}
return profile.dialogues;
}
}

View File

@ -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)
{

View File

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