diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index 0dddea750..822e1ee21 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -97,6 +97,8 @@ bool LoginQueryHolder::Initialize() res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA, "SELECT type, time, data FROM character_account_data WHERE guid='%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSKILLS, "SELECT skill, value, max FROM character_skills WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGLYPHS, "SELECT spec, slot, glyph FROM character_glyphs WHERE guid='%u'", GUID_LOPART(m_guid)); + res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILS, "SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC", GUID_LOPART(m_guid)); + res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADMAILEDITEMS, "SELECT data, mail_id, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE receiver = '%u'", GUID_LOPART(m_guid)); return res; } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index db270c0b1..4f6084618 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -15091,7 +15091,8 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder ) // apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods() // Mail - _LoadMail(); + _LoadMails(holder->GetResult(PLAYER_LOGIN_QUERY_LOADMAILS)); + _LoadMailedItems(holder->GetResult(PLAYER_LOGIN_QUERY_LOADMAILEDITEMS)); UpdateNextMailTimeAndUnreads(); m_specsCount = fields[59].GetUInt8(); @@ -15641,19 +15642,24 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff) } // load mailed item which should receive current player -void Player::_LoadMailedItems(Mail *mail) +void Player::_LoadMailedItems(QueryResult *result) { // data needs to be at first place for Item::LoadFromDB - QueryResult* result = CharacterDatabase.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID); + // 0 1 2 3 + // "SELECT data, mail_id, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE receiver = '%u'", GUID_LOPART(m_guid) if(!result) return; do { Field *fields = result->Fetch(); - uint32 item_guid_low = fields[1].GetUInt32(); - uint32 item_template = fields[2].GetUInt32(); + uint32 mail_id = fields[1].GetUInt32(); + uint32 item_guid_low = fields[2].GetUInt32(); + uint32 item_template = fields[3].GetUInt32(); + Mail* mail = GetMail(mail_id); + if(!mail) + continue; mail->AddItem(item_guid_low, item_template); ItemPrototype const *proto = ObjectMgr::GetItemPrototype(item_template); @@ -15683,47 +15689,44 @@ void Player::_LoadMailedItems(Mail *mail) delete result; } -void Player::_LoadMail() +void Player::_LoadMails(QueryResult *result) { m_mail.clear(); - //mails are in right order 0 1 2 3 4 5 6 7 8 9 10 11 12 13 - QueryResult *result = CharacterDatabase.PQuery("SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow()); - if(result) + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 + //"SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow() + if(!result) + return; + + do { - do + Field *fields = result->Fetch(); + Mail *m = new Mail; + m->messageID = fields[0].GetUInt32(); + m->messageType = fields[1].GetUInt8(); + m->sender = fields[2].GetUInt32(); + m->receiver = fields[3].GetUInt32(); + m->subject = fields[4].GetCppString(); + m->itemTextId = fields[5].GetUInt32(); + bool has_items = fields[6].GetBool(); + m->expire_time = (time_t)fields[7].GetUInt64(); + m->deliver_time = (time_t)fields[8].GetUInt64(); + m->money = fields[9].GetUInt32(); + m->COD = fields[10].GetUInt32(); + m->checked = fields[11].GetUInt32(); + m->stationery = fields[12].GetUInt8(); + m->mailTemplateId = fields[13].GetInt16(); + + if(m->mailTemplateId && !sMailTemplateStore.LookupEntry(m->mailTemplateId)) { - Field *fields = result->Fetch(); - Mail *m = new Mail; - m->messageID = fields[0].GetUInt32(); - m->messageType = fields[1].GetUInt8(); - m->sender = fields[2].GetUInt32(); - m->receiver = fields[3].GetUInt32(); - m->subject = fields[4].GetCppString(); - m->itemTextId = fields[5].GetUInt32(); - bool has_items = fields[6].GetBool(); - m->expire_time = (time_t)fields[7].GetUInt64(); - m->deliver_time = (time_t)fields[8].GetUInt64(); - m->money = fields[9].GetUInt32(); - m->COD = fields[10].GetUInt32(); - m->checked = fields[11].GetUInt32(); - m->stationery = fields[12].GetUInt8(); - m->mailTemplateId = fields[13].GetInt16(); + sLog.outError( "Player::_LoadMail - Mail (%u) have not existed MailTemplateId (%u), remove at load", m->messageID, m->mailTemplateId); + m->mailTemplateId = 0; + } - if(m->mailTemplateId && !sMailTemplateStore.LookupEntry(m->mailTemplateId)) - { - sLog.outError( "Player::_LoadMail - Mail (%u) have not existed MailTemplateId (%u), remove at load", m->messageID, m->mailTemplateId); - m->mailTemplateId = 0; - } + m->state = MAIL_STATE_UNCHANGED; - m->state = MAIL_STATE_UNCHANGED; - - if (has_items) - _LoadMailedItems(m); - - m_mail.push_back(m); - } while( result->NextRow() ); - delete result; - } + m_mail.push_back(m); + } while( result->NextRow() ); + delete result; } void Player::LoadPet() diff --git a/src/game/Player.h b/src/game/Player.h index 8c92a8e8e..3062b8dbd 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -889,7 +889,9 @@ enum PlayerLoginQueryIndex PLAYER_LOGIN_QUERY_LOADACCOUNTDATA = 20, PLAYER_LOGIN_QUERY_LOADSKILLS = 21, PLAYER_LOGIN_QUERY_LOADGLYPHS = 22, - MAX_PLAYER_LOGIN_QUERY = 23 + PLAYER_LOGIN_QUERY_LOADMAILS = 23, + PLAYER_LOGIN_QUERY_LOADMAILEDITEMS = 24, + MAX_PLAYER_LOGIN_QUERY = 25 }; enum PlayerDelayedOperations @@ -2311,8 +2313,8 @@ class MANGOS_DLL_SPEC Player : public Unit void _LoadAuras(QueryResult *result, uint32 timediff); void _LoadBoundInstances(QueryResult *result); void _LoadInventory(QueryResult *result, uint32 timediff); - void _LoadMail(); - void _LoadMailedItems(Mail *mail); + void _LoadMails(QueryResult *result); + void _LoadMailedItems(QueryResult *result); void _LoadQuestStatus(QueryResult *result); void _LoadDailyQuestStatus(QueryResult *result); void _LoadGroup(QueryResult *result); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 056c465b5..0f1f0c65c 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9626" + #define REVISION_NR "9627" #endif // __REVISION_NR_H__