feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -21,7 +21,7 @@
#define MAX_INBOX_CLIENT_CAPACITY 50
bool WorldSession::CanOpenMailBox(uint64 guid)
bool WorldSession::CanOpenMailBox(ObjectGuid guid)
{
if (guid == _player->GetGUID())
{
@@ -31,12 +31,12 @@ bool WorldSession::CanOpenMailBox(uint64 guid)
return false;
}
}
else if (IS_GAMEOBJECT_GUID(guid))
else if (guid.IsGameObject())
{
if (!_player->GetGameObjectIfCanInteractWith(guid, GAMEOBJECT_TYPE_MAILBOX))
return false;
}
else if (IS_CRE_OR_VEH_OR_PET_GUID(guid))
else if (guid.IsAnyTypeCreature())
{
if (!_player->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_MAILBOX))
return false;
@@ -49,7 +49,8 @@ bool WorldSession::CanOpenMailBox(uint64 guid)
void WorldSession::HandleSendMail(WorldPacket& recvData)
{
uint64 mailbox, unk3;
ObjectGuid mailbox;
uint64 unk3;
std::string receiver, subject, body;
uint32 unk1, unk2, money, COD;
uint8 unk4;
@@ -80,7 +81,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
return;
}
uint64 itemGUIDs[MAX_MAIL_ITEMS];
ObjectGuid itemGUIDs[MAX_MAIL_ITEMS];
for (uint8 i = 0; i < items_count; ++i)
{
@@ -108,21 +109,23 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
return;
}
uint64 rc = 0;
ObjectGuid rc;
if (normalizePlayerName(receiver))
rc = sObjectMgr->GetPlayerGUIDByName(receiver);
if (!rc)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "Player %u is sending mail to %s (GUID: not existed!) with subject %s and body %s includes %u items, %u copper and %u COD copper with unk1 = %u, unk2 = %u", player->GetGUIDLow(), receiver.c_str(), subject.c_str(), body.c_str(), items_count, money, COD, unk1, unk2);
LOG_DEBUG("server", "Player %s is sending mail to %s (GUID: not existed!) with subject %s and body %s includes %u items, %u copper and %u COD copper with unk1 = %u, unk2 = %u",
player->GetGUID().ToString().c_str(), receiver.c_str(), subject.c_str(), body.c_str(), items_count, money, COD, unk1, unk2);
#endif
player->SendMailResult(0, MAIL_SEND, MAIL_ERR_RECIPIENT_NOT_FOUND);
return;
}
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "Player %u is sending mail to %s (GUID: %u) with subject %s and body %s includes %u items, %u copper and %u COD copper with unk1 = %u, unk2 = %u", player->GetGUIDLow(), receiver.c_str(), GUID_LOPART(rc), subject.c_str(), body.c_str(), items_count, money, COD, unk1, unk2);
LOG_DEBUG("server", "Player %s is sending mail to %s (%s) with subject %s and body %s includes %u items, %u copper and %u COD copper with unk1 = %u, unk2 = %u",
player->GetGUID().ToString().c_str(), receiver.c_str(), rc.ToString().c_str(), subject.c_str(), body.c_str(), items_count, money, COD, unk1, unk2);
#endif
if (player->GetGUID() == rc)
@@ -155,7 +158,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
return;
}
Player* receive = ObjectAccessor::FindPlayerInOrOutOfWorld(rc);
Player* receive = ObjectAccessor::FindConnectedPlayer(rc);
uint32 rc_teamId = TEAM_NEUTRAL;
uint16 mails_count = 0; //do not allow to send to one player more than 100 mails
@@ -168,7 +171,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
else
{
// xinef: get data from global storage
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(rc)))
if (GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(rc.GetCounter()))
{
rc_teamId = Player::TeamIdForRace(playerData->race);
mails_count = playerData->mailCount;
@@ -197,7 +200,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
}
}*/
uint32 rc_account = receive ? receive->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(rc);
uint32 rc_account = receive ? receive->GetSession()->GetAccountId() : sObjectMgr->GetPlayerAccountIdByGUID(rc.GetCounter());
if (/*!accountBound*/ GetAccountId() != rc_account && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_MAIL) && player->GetTeamId() != rc_teamId && AccountMgr::IsPlayerAccount(GetSecurity()))
{
@@ -298,7 +301,8 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
if( money >= 10 * GOLD )
{
CleanStringForMysqlQuery(subject);
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<MAIL> %s\", NOW())", GetAccountId(), player->GetGUIDLow(), player->GetName().c_str(), player->GetSession()->GetRemoteAddress().c_str(), rc_account, receiver.c_str(), money, subject.c_str());
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<MAIL> %s\", NOW())",
GetAccountId(), player->GetGUID().GetCounter(), player->GetName().c_str(), player->GetSession()->GetRemoteAddress().c_str(), rc_account, receiver.c_str(), money, subject.c_str());
}
}
@@ -313,7 +317,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
draft
.AddMoney(money)
.AddCOD(COD)
.SendMailTo(trans, MailReceiver(receive, GUID_LOPART(rc)), MailSender(player), body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY, deliver_delay);
.SendMailTo(trans, MailReceiver(receive, rc.GetCounter()), MailSender(player), body.empty() ? MAIL_CHECK_MASK_COPIED : MAIL_CHECK_MASK_HAS_BODY, deliver_delay);
player->SaveInventoryAndGoldToDB(trans);
CharacterDatabase.CommitTransaction(trans);
@@ -322,7 +326,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
//called when mail is read
void WorldSession::HandleMailMarkAsRead(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
uint32 mailId;
recvData >> mailbox;
recvData >> mailId;
@@ -345,7 +349,7 @@ void WorldSession::HandleMailMarkAsRead(WorldPacket& recvData)
//called when client deletes mail
void WorldSession::HandleMailDelete(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
uint32 mailId;
recvData >> mailbox;
recvData >> mailId;
@@ -368,14 +372,14 @@ void WorldSession::HandleMailDelete(WorldPacket& recvData)
m->state = MAIL_STATE_DELETED;
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(player->GetGUIDLow(), -1);
sWorld->UpdateGlobalPlayerMails(player->GetGUID().GetCounter(), -1);
}
player->SendMailResult(mailId, MAIL_DELETED, MAIL_OK);
}
void WorldSession::HandleMailReturnToSender(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
uint32 mailId;
recvData >> mailbox;
recvData >> mailId;
@@ -432,18 +436,18 @@ void WorldSession::HandleMailReturnToSender(WorldPacket& recvData)
player->SendMailResult(mailId, MAIL_RETURNED_TO_SENDER, MAIL_OK);
// xinef: update global data
sWorld->UpdateGlobalPlayerMails(player->GetGUIDLow(), -1);
sWorld->UpdateGlobalPlayerMails(player->GetGUID().GetCounter(), -1);
}
//called when player takes item attached in mail
void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
uint32 mailId;
uint32 itemId;
uint32 itemLowGuid;
recvData >> mailbox;
recvData >> mailId;
recvData >> itemId; // item guid low
recvData >> itemLowGuid; // item guid low
if (!CanOpenMailBox(mailbox))
return;
@@ -460,7 +464,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
// verify that the mail has the item to avoid cheaters taking COD items without paying
bool foundItem = false;
for (std::vector<MailItemInfo>::const_iterator itr = m->items.begin(); itr != m->items.end(); ++itr)
if (itr->item_guid == itemId)
if (itr->item_guid == itemLowGuid)
{
foundItem = true;
break;
@@ -478,25 +482,24 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
return;
}
Item* it = player->GetMItem(itemId);
Item* it = player->GetMItem(itemLowGuid);
ItemPosCountVec dest;
uint8 msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, it, false);
if (msg == EQUIP_ERR_OK)
{
SQLTransaction trans = CharacterDatabase.BeginTransaction();
m->RemoveItem(itemId);
m->removedItems.push_back(itemId);
m->RemoveItem(itemLowGuid);
m->removedItems.push_back(itemLowGuid);
if (m->COD > 0) // if there is COD, take COD money from player and send them to sender by mail
{
uint64 sender_guid = MAKE_NEW_GUID(m->sender, 0, HIGHGUID_PLAYER);
uint32 sender_accId = 0;
Player* sender = ObjectAccessor::FindPlayerInOrOutOfWorld(sender_guid);
Player* sender = ObjectAccessor::FindPlayerByLowGUID(m->sender);
if (sender)
sender_accId = sender->GetSession()->GetAccountId();
else
sender_accId = sObjectMgr->GetPlayerAccountIdByGUID(sender_guid);
sender_accId = sObjectMgr->GetPlayerAccountIdByGUID(m->sender);
// check player existence
if (sender || sender_accId)
@@ -508,11 +511,12 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
if( m->COD >= 10 * GOLD )
{
std::string senderName;
if (!sObjectMgr->GetPlayerNameByGUID(sender_guid, senderName))
if (!sObjectMgr->GetPlayerNameByGUID(m->sender, senderName))
senderName = sObjectMgr->GetAcoreStringForDBCLocale(LANG_UNKNOWN);
std::string subj = m->subject;
CleanStringForMysqlQuery(subj);
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<COD> %s\", NOW())", GetAccountId(), player->GetGUIDLow(), player->GetName().c_str(), player->GetSession()->GetRemoteAddress().c_str(), sender_accId, senderName.c_str(), m->COD, subj.c_str());
CharacterDatabase.PExecute("INSERT INTO log_money VALUES(%u, %u, \"%s\", \"%s\", %u, \"%s\", %u, \"<COD> %s\", NOW())",
GetAccountId(), player->GetGUID().GetCounter(), player->GetName().c_str(), player->GetSession()->GetRemoteAddress().c_str(), sender_accId, senderName.c_str(), m->COD, subj.c_str());
}
}
@@ -522,7 +526,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
m->COD = 0;
m->state = MAIL_STATE_CHANGED;
player->m_mailsUpdated = true;
player->RemoveMItem(it->GetGUIDLow());
player->RemoveMItem(it->GetGUID().GetCounter());
uint32 count = it->GetCount(); // save counts before store and possible merge with deleting
it->SetState(ITEM_UNCHANGED); // need to set this state, otherwise item cannot be removed later, if neccessary
@@ -532,7 +536,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
player->_SaveMail(trans);
CharacterDatabase.CommitTransaction(trans);
player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemId, count);
player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_OK, 0, itemLowGuid, count);
}
else
player->SendMailResult(mailId, MAIL_ITEM_TAKEN, MAIL_ERR_EQUIP_ERROR, msg);
@@ -540,7 +544,7 @@ void WorldSession::HandleMailTakeItem(WorldPacket& recvData)
void WorldSession::HandleMailTakeMoney(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
uint32 mailId;
recvData >> mailbox;
recvData >> mailId;
@@ -579,7 +583,7 @@ void WorldSession::HandleMailTakeMoney(WorldPacket& recvData)
//called when player lists his received mails
void WorldSession::HandleGetMailList(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
recvData >> mailbox;
if (!CanOpenMailBox(mailbox))
@@ -623,7 +627,7 @@ void WorldSession::HandleGetMailList(WorldPacket& recvData)
switch ((*itr)->messageType)
{
case MAIL_NORMAL: // sender guid
data << uint64(MAKE_NEW_GUID((*itr)->sender, 0, HIGHGUID_PLAYER));
data << ObjectGuid::Create<HighGuid::Player>((*itr)->sender);
break;
case MAIL_CREATURE:
case MAIL_GAMEOBJECT:
@@ -663,7 +667,7 @@ void WorldSession::HandleGetMailList(WorldPacket& recvData)
// item index (0-6?)
data << uint8(i);
// item guid low?
data << uint32((item ? item->GetGUIDLow() : 0));
data << uint32((item ? item->GetGUID().GetCounter() : 0));
// entry
data << uint32((item ? item->GetEntry() : 0));
for (uint8 j = 0; j < MAX_INSPECTED_ENCHANTMENT_SLOT; ++j)
@@ -702,7 +706,7 @@ void WorldSession::HandleGetMailList(WorldPacket& recvData)
//used when player copies mail body to his inventory
void WorldSession::HandleMailCreateTextItem(WorldPacket& recvData)
{
uint64 mailbox;
ObjectGuid mailbox;
uint32 mailId;
recvData >> mailbox;
@@ -721,7 +725,7 @@ void WorldSession::HandleMailCreateTextItem(WorldPacket& recvData)
}
Item* bodyItem = new Item; // This is not bag and then can be used new Item.
if (!bodyItem->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_ITEM), MAIL_BODY_ITEM_TEMPLATE, player))
if (!bodyItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), MAIL_BODY_ITEM_TEMPLATE, player))
{
delete bodyItem;
return;
@@ -798,7 +802,7 @@ void WorldSession::HandleQueryNextMailTime(WorldPacket& /*recvData*/)
if (sentSenders.count(m->sender))
continue;
data << uint64(m->messageType == MAIL_NORMAL ? m->sender : 0); // player guid
data << (m->messageType == MAIL_NORMAL ? ObjectGuid::Create<HighGuid::Player>(m->sender) : ObjectGuid::Empty); // player guid
data << uint32(m->messageType != MAIL_NORMAL ? m->sender : 0); // non-player entries
data << uint32(m->messageType);
data << uint32(m->stationery);