[9627] Make mail load async.

Signed-off-by: hunuza <hunuza@gmail.com>
This commit is contained in:
hunuza 2010-03-27 11:15:22 +01:00
parent 9311a36d2a
commit 841db412e9
4 changed files with 51 additions and 44 deletions

View file

@ -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_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_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_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; return res;
} }

View file

@ -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() // apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
// Mail // Mail
_LoadMail(); _LoadMails(holder->GetResult(PLAYER_LOGIN_QUERY_LOADMAILS));
_LoadMailedItems(holder->GetResult(PLAYER_LOGIN_QUERY_LOADMAILEDITEMS));
UpdateNextMailTimeAndUnreads(); UpdateNextMailTimeAndUnreads();
m_specsCount = fields[59].GetUInt8(); m_specsCount = fields[59].GetUInt8();
@ -15641,19 +15642,24 @@ void Player::_LoadInventory(QueryResult *result, uint32 timediff)
} }
// load mailed item which should receive current player // 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 // 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) if(!result)
return; return;
do do
{ {
Field *fields = result->Fetch(); Field *fields = result->Fetch();
uint32 item_guid_low = fields[1].GetUInt32(); uint32 mail_id = fields[1].GetUInt32();
uint32 item_template = fields[2].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); mail->AddItem(item_guid_low, item_template);
ItemPrototype const *proto = ObjectMgr::GetItemPrototype(item_template); ItemPrototype const *proto = ObjectMgr::GetItemPrototype(item_template);
@ -15683,47 +15689,44 @@ void Player::_LoadMailedItems(Mail *mail)
delete result; delete result;
} }
void Player::_LoadMail() void Player::_LoadMails(QueryResult *result)
{ {
m_mail.clear(); m_mail.clear();
//mails are in right order 0 1 2 3 4 5 6 7 8 9 10 11 12 13 // 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()); //"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) 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(); sLog.outError( "Player::_LoadMail - Mail (%u) have not existed MailTemplateId (%u), remove at load", m->messageID, m->mailTemplateId);
Mail *m = new Mail; m->mailTemplateId = 0;
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)) m->state = MAIL_STATE_UNCHANGED;
{
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_mail.push_back(m);
} while( result->NextRow() );
if (has_items) delete result;
_LoadMailedItems(m);
m_mail.push_back(m);
} while( result->NextRow() );
delete result;
}
} }
void Player::LoadPet() void Player::LoadPet()

View file

@ -889,7 +889,9 @@ enum PlayerLoginQueryIndex
PLAYER_LOGIN_QUERY_LOADACCOUNTDATA = 20, PLAYER_LOGIN_QUERY_LOADACCOUNTDATA = 20,
PLAYER_LOGIN_QUERY_LOADSKILLS = 21, PLAYER_LOGIN_QUERY_LOADSKILLS = 21,
PLAYER_LOGIN_QUERY_LOADGLYPHS = 22, 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 enum PlayerDelayedOperations
@ -2311,8 +2313,8 @@ class MANGOS_DLL_SPEC Player : public Unit
void _LoadAuras(QueryResult *result, uint32 timediff); void _LoadAuras(QueryResult *result, uint32 timediff);
void _LoadBoundInstances(QueryResult *result); void _LoadBoundInstances(QueryResult *result);
void _LoadInventory(QueryResult *result, uint32 timediff); void _LoadInventory(QueryResult *result, uint32 timediff);
void _LoadMail(); void _LoadMails(QueryResult *result);
void _LoadMailedItems(Mail *mail); void _LoadMailedItems(QueryResult *result);
void _LoadQuestStatus(QueryResult *result); void _LoadQuestStatus(QueryResult *result);
void _LoadDailyQuestStatus(QueryResult *result); void _LoadDailyQuestStatus(QueryResult *result);
void _LoadGroup(QueryResult *result); void _LoadGroup(QueryResult *result);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9626" #define REVISION_NR "9627"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__