mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-18 19:35:42 +00:00
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
|
||||
time_t cTime = GameTime::GetGameTime().count();
|
||||
// Get the next delivery time
|
||||
CharacterDatabasePreparedStatement* stmtNextDeliveryTime =
|
||||
CharacterDatabase.GetPreparedStatement(CHAR_SEL_NEXT_MAIL_DELIVERYTIME);
|
||||
stmtNextDeliveryTime->SetData(0, GetGUID().GetCounter());
|
||||
stmtNextDeliveryTime->SetData(1, uint32(cTime));
|
||||
PreparedQueryResult resultNextDeliveryTime =
|
||||
CharacterDatabase.Query(stmtNextDeliveryTime);
|
||||
if (resultNextDeliveryTime)
|
||||
{
|
||||
Field* fields = resultNextDeliveryTime->Fetch();
|
||||
m_nextMailDelivereTime = time_t(fields[0].Get<uint32>());
|
||||
}
|
||||
|
||||
// Get unread mails count
|
||||
CharacterDatabasePreparedStatement* stmtUnreadAmount =
|
||||
CharacterDatabase.GetPreparedStatement(
|
||||
CHAR_SEL_CHARACTER_MAILCOUNT_UNREAD_SYNCH);
|
||||
stmtUnreadAmount->SetData(0, GetGUID().GetCounter());
|
||||
stmtUnreadAmount->SetData(1, uint32(cTime));
|
||||
PreparedQueryResult resultUnreadAmount =
|
||||
CharacterDatabase.Query(stmtUnreadAmount);
|
||||
if (resultUnreadAmount)
|
||||
m_nextMailDelivereTime = 0;
|
||||
unReadMails = 0;
|
||||
|
||||
for (Mail const* mail : GetMails())
|
||||
{
|
||||
Field* fields = resultUnreadAmount->Fetch();
|
||||
unReadMails = uint8(fields[0].Get<uint64>());
|
||||
if (mail->deliver_time > cTime)
|
||||
{
|
||||
if (!m_nextMailDelivereTime || m_nextMailDelivereTime > mail->deliver_time)
|
||||
m_nextMailDelivereTime = mail->deliver_time;
|
||||
}
|
||||
|
||||
// must be not checked yet
|
||||
if (mail->checked & MAIL_CHECK_MASK_READ)
|
||||
continue;
|
||||
|
||||
// and already delivered or expired
|
||||
if (cTime < mail->deliver_time || cTime > mail->expire_time)
|
||||
continue;
|
||||
|
||||
unReadMails++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user