fix(Core/Mail): calculate unReadMails and m_nextMailDelivereTime usin… (#18996)
* fix(Core/Mail): calculate unReadMails and m_nextMailDelivereTime using mail cache - these values were grepped directly from DB before -> this change was introduced with azerothcore/azerothcore-wotlk#3420 - the whole mailing system relies on the mails beeing cached in the core -> these get stored in DB regularly or on specific events - so apparently the DB is not always in sync with the current mail cache state of the core -> so grepping data directly from DB is not a good idea at this point * Update PlayerUpdates.cpp
This commit is contained in:
@@ -435,31 +435,27 @@ void Player::UpdateNextMailTimeAndUnreads()
|
|||||||
{
|
{
|
||||||
// Update the next delivery time and unread mails
|
// Update the next delivery time and unread mails
|
||||||
time_t cTime = GameTime::GetGameTime().count();
|
time_t cTime = GameTime::GetGameTime().count();
|
||||||
// Get the next delivery time
|
|
||||||
CharacterDatabasePreparedStatement* stmtNextDeliveryTime =
|
m_nextMailDelivereTime = 0;
|
||||||
CharacterDatabase.GetPreparedStatement(CHAR_SEL_NEXT_MAIL_DELIVERYTIME);
|
unReadMails = 0;
|
||||||
stmtNextDeliveryTime->SetData(0, GetGUID().GetCounter());
|
|
||||||
stmtNextDeliveryTime->SetData(1, uint32(cTime));
|
for (Mail const* mail : GetMails())
|
||||||
PreparedQueryResult resultNextDeliveryTime =
|
|
||||||
CharacterDatabase.Query(stmtNextDeliveryTime);
|
|
||||||
if (resultNextDeliveryTime)
|
|
||||||
{
|
{
|
||||||
Field* fields = resultNextDeliveryTime->Fetch();
|
if (mail->deliver_time > cTime)
|
||||||
m_nextMailDelivereTime = time_t(fields[0].Get<uint32>());
|
{
|
||||||
|
if (!m_nextMailDelivereTime || m_nextMailDelivereTime > mail->deliver_time)
|
||||||
|
m_nextMailDelivereTime = mail->deliver_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get unread mails count
|
// must be not checked yet
|
||||||
CharacterDatabasePreparedStatement* stmtUnreadAmount =
|
if (mail->checked & MAIL_CHECK_MASK_READ)
|
||||||
CharacterDatabase.GetPreparedStatement(
|
continue;
|
||||||
CHAR_SEL_CHARACTER_MAILCOUNT_UNREAD_SYNCH);
|
|
||||||
stmtUnreadAmount->SetData(0, GetGUID().GetCounter());
|
// and already delivered or expired
|
||||||
stmtUnreadAmount->SetData(1, uint32(cTime));
|
if (cTime < mail->deliver_time || cTime > mail->expire_time)
|
||||||
PreparedQueryResult resultUnreadAmount =
|
continue;
|
||||||
CharacterDatabase.Query(stmtUnreadAmount);
|
|
||||||
if (resultUnreadAmount)
|
unReadMails++;
|
||||||
{
|
|
||||||
Field* fields = resultUnreadAmount->Fetch();
|
|
||||||
unReadMails = uint8(fields[0].Get<uint64>());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user