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

@@ -23,14 +23,14 @@
//void called when player click on auctioneer npc
void WorldSession::HandleAuctionHelloOpcode(WorldPacket& recvData)
{
uint64 guid; //NPC guid
ObjectGuid guid; //NPC guid
recvData >> guid;
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_AUCTIONEER);
if (!unit)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
LOG_DEBUG("network", "WORLD: HandleAuctionHelloOpcode - Unit (%s) not found or you can't interact with him.", guid.ToString().c_str());
#endif
return;
}
@@ -43,7 +43,7 @@ void WorldSession::HandleAuctionHelloOpcode(WorldPacket& recvData)
}
//this void causes that auction window is opened
void WorldSession::SendAuctionHello(uint64 guid, Creature* unit)
void WorldSession::SendAuctionHello(ObjectGuid guid, Creature* unit)
{
if (GetPlayer()->getLevel() < sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ))
{
@@ -59,7 +59,7 @@ void WorldSession::SendAuctionHello(uint64 guid, Creature* unit)
return;
WorldPacket data(MSG_AUCTION_HELLO, 12);
data << uint64(guid);
data << guid;
data << uint32(ahEntry->houseId);
data << uint8(1); // 3.3.3: 1 - AH enabled, 0 - AH disabled
SendPacket(&data);
@@ -78,12 +78,12 @@ void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uin
}
//this function sends notification, if bidder is online
void WorldSession::SendAuctionBidderNotification(uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template)
void WorldSession::SendAuctionBidderNotification(uint32 location, uint32 auctionId, ObjectGuid bidder, uint32 bidSum, uint32 diff, uint32 item_template)
{
WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8 * 4));
data << uint32(location);
data << uint32(auctionId);
data << uint64(bidder);
data << bidder;
data << uint32(bidSum);
data << uint32(diff);
data << uint32(item_template);
@@ -108,13 +108,12 @@ void WorldSession::SendAuctionOwnerNotification(AuctionEntry* auction)
//this void creates new auction and adds auction to some auctionhouse
void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
{
uint64 auctioneer;
ObjectGuid auctioneer;
uint32 itemsCount, etime, bid, buyout;
recvData >> auctioneer;
recvData >> itemsCount;
uint64 itemGUIDs[MAX_AUCTION_ITEMS]; // 160 slot = 4x 36 slot bag + backpack 16 slot
memset(itemGUIDs, 0, sizeof(itemGUIDs));
ObjectGuid itemGUIDs[MAX_AUCTION_ITEMS]; // 160 slot = 4x 36 slot bag + backpack 16 slot
uint32 count[MAX_AUCTION_ITEMS];
memset(count, 0, sizeof(count));
@@ -147,7 +146,8 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
if (bid > MAX_MONEY_AMOUNT || buyout > MAX_MONEY_AMOUNT)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionSellItem - Player %s (GUID %u) attempted to sell item with higher price than max gold amount.", _player->GetName().c_str(), _player->GetGUIDLow());
LOG_DEBUG("network", "WORLD: HandleAuctionSellItem - Player %s (%s) attempted to sell item with higher price than max gold amount.",
_player->GetName().c_str(), _player->GetGUID().ToString().c_str());
#endif
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, ERR_AUCTION_DATABASE_ERROR);
return;
@@ -157,7 +157,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
if (!creature)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", GUID_LOPART(auctioneer));
LOG_DEBUG("network", "WORLD: HandleAuctionSellItem - Unit (%s) not found or you can't interact with him.", auctioneer.ToString().c_str());
#endif
return;
}
@@ -166,7 +166,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
if (!auctionHouseEntry)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", GUID_LOPART(auctioneer));
LOG_DEBUG("network", "WORLD: HandleAuctionSellItem - Unit (%s) has wrong faction.", auctioneer.ToString().c_str());
#endif
return;
}
@@ -204,7 +204,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
if (itemEntry == 0)
itemEntry = item->GetTemplate()->ItemId;
if (sAuctionMgr->GetAItem(item->GetGUIDLow()) || !item->CanBeTraded() || item->IsNotEmptyBag() ||
if (sAuctionMgr->GetAItem(item->GetGUID()) || !item->CanBeTraded() || item->IsNotEmptyBag() ||
item->GetTemplate()->Flags & ITEM_FLAG_CONJURED || item->GetUInt32Value(ITEM_FIELD_DURATION) ||
item->GetCount() < count[i] || itemEntry != item->GetTemplate()->ItemId)
{
@@ -266,19 +266,36 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
AH->Id = sObjectMgr->GenerateAuctionID();
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
AH->auctioneer = 23442;
AH->houseId = AUCTIONHOUSE_NEUTRAL;
else
AH->auctioneer = GUID_LOPART(auctioneer);
{
CreatureData const* auctioneerData = sObjectMgr->GetCreatureData(creature->GetSpawnId());
if (!auctioneerData)
{
LOG_ERROR("server", "Data for auctioneer not found (%s)", auctioneer.ToString().c_str());
return;
}
CreatureTemplate const* auctioneerInfo = sObjectMgr->GetCreatureTemplate(auctioneerData->id);
if (!auctioneerInfo)
{
LOG_ERROR("server", "Non existing auctioneer (%s)", auctioneer.ToString().c_str());
return;
}
const AuctionHouseEntry* AHEntry = sAuctionMgr->GetAuctionHouseEntry(auctioneerInfo->faction);
AH->houseId = AHEntry->houseId;
}
// Required stack size of auction matches to current item stack size, just move item to auctionhouse
if (itemsCount == 1 && item->GetCount() == count[i])
{
AH->item_guidlow = item->GetGUIDLow();
AH->item_guid = item->GetGUID();
AH->item_template = item->GetEntry();
AH->itemCount = item->GetCount();
AH->owner = _player->GetGUIDLow();
AH->owner = _player->GetGUID();
AH->startbid = bid;
AH->bidder = 0;
AH->bidder = ObjectGuid::Empty;
AH->bid = 0;
AH->buyout = buyout;
AH->expire_time = time(nullptr) + auctionTime;
@@ -286,7 +303,8 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
AH->auctionHouseEntry = auctionHouseEntry;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", _player->GetName().c_str(), _player->GetGUIDLow(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUIDLow(), AH->auctioneer, item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId());
LOG_DEBUG("server", "CMSG_AUCTION_SELL_ITEM: Player %s (%s) is selling item %s entry %u (%s) with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u",
_player->GetName().c_str(), _player->GetGUID().ToString().c_str(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUID().ToString().c_str(), item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId());
#endif
sAuctionMgr->AddAItem(item);
auctionHouse->AddAuction(AH);
@@ -315,12 +333,12 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
return;
}
AH->item_guidlow = newItem->GetGUIDLow();
AH->item_guid = newItem->GetGUID();
AH->item_template = newItem->GetEntry();
AH->itemCount = newItem->GetCount();
AH->owner = _player->GetGUIDLow();
AH->owner = _player->GetGUID();
AH->startbid = bid;
AH->bidder = 0;
AH->bidder = ObjectGuid::Empty;
AH->bid = 0;
AH->buyout = buyout;
AH->expire_time = time(nullptr) + auctionTime;
@@ -328,7 +346,8 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
AH->auctionHouseEntry = auctionHouseEntry;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("server", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) to auctioneer %u with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", _player->GetName().c_str(), _player->GetGUIDLow(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUIDLow(), AH->auctioneer, newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId());
LOG_DEBUG("server", "CMSG_AUCTION_SELL_ITEM: Player %s (%s) is selling item %s entry %u (%s) with count %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u",
_player->GetName().c_str(), _player->GetGUID().ToString().c_str(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUID().ToString().c_str(), newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId());
#endif
sAuctionMgr->AddAItem(newItem);
auctionHouse->AddAuction(AH);
@@ -382,7 +401,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
LOG_DEBUG("network", "WORLD: Received CMSG_AUCTION_PLACE_BID");
#endif
uint64 auctioneer;
ObjectGuid auctioneer;
uint32 auctionId;
uint32 price;
recvData >> auctioneer;
@@ -395,7 +414,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
if (!creature)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
LOG_DEBUG("network", "WORLD: HandleAuctionPlaceBid - Unit (%s) not found or you can't interact with him.", auctioneer.ToString().c_str());
#endif
return;
}
@@ -409,7 +428,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
AuctionEntry* auction = auctionHouse->GetAuction(auctionId);
Player* player = GetPlayer();
if (!auction || auction->owner == player->GetGUIDLow())
if (!auction || auction->owner == player->GetGUID())
{
//you cannot bid your own auction:
SendAuctionCommandResult(0, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN);
@@ -417,8 +436,8 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
}
// impossible have online own another character (use this for speedup check in case online owner)
Player* auction_owner = ObjectAccessor::FindPlayerInOrOutOfWorld(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
if (!auction_owner && sObjectMgr->GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == GetAccountId())
Player* auction_owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
if (!auction_owner && sObjectMgr->GetPlayerAccountIdByGUID(auction->owner.GetCounter()) == GetAccountId())
{
//you cannot bid your another character auction:
SendAuctionCommandResult(0, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN);
@@ -448,9 +467,9 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
if (price < auction->buyout || auction->buyout == 0)
{
if (auction->bidder > 0)
if (auction->bidder)
{
if (auction->bidder == player->GetGUIDLow())
if (auction->bidder == player->GetGUID())
player->ModifyMoney(-int32(price - auction->bid));
else
{
@@ -462,12 +481,12 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
else
player->ModifyMoney(-int32(price));
auction->bidder = player->GetGUIDLow();
auction->bidder = player->GetGUID();
auction->bid = price;
GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_BID);
stmt->setUInt32(0, auction->bidder);
stmt->setUInt32(0, auction->bidder.GetCounter());
stmt->setUInt32(1, auction->bid);
stmt->setUInt32(2, auction->Id);
trans->Append(stmt);
@@ -477,7 +496,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
else
{
//buyout:
if (player->GetGUIDLow() == auction->bidder)
if (player->GetGUID() == auction->bidder)
player->ModifyMoney(-int32(auction->buyout - auction->bid));
else
{
@@ -485,7 +504,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
if (auction->bidder) //buyout for bidded auction ..
sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, GetPlayer(), trans);
}
auction->bidder = player->GetGUIDLow();
auction->bidder = player->GetGUID();
auction->bid = auction->buyout;
GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);
@@ -498,7 +517,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
auction->DeleteFromDB(trans);
sAuctionMgr->RemoveAItem(auction->item_guidlow);
sAuctionMgr->RemoveAItem(auction->item_guid);
auctionHouse->RemoveAuction(auction);
}
player->SaveInventoryAndGoldToDB(trans);
@@ -512,7 +531,7 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
LOG_DEBUG("network", "WORLD: Received CMSG_AUCTION_REMOVE_ITEM");
#endif
uint64 auctioneer;
ObjectGuid auctioneer;
uint32 auctionId;
recvData >> auctioneer;
recvData >> auctionId;
@@ -521,7 +540,7 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
if (!creature)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
LOG_DEBUG("network", "WORLD: HandleAuctionRemoveItem - Unit (%s) not found or you can't interact with him.", auctioneer.ToString().c_str());
#endif
return;
}
@@ -536,12 +555,12 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
Player* player = GetPlayer();
SQLTransaction trans = CharacterDatabase.BeginTransaction();
if (auction && auction->owner == player->GetGUIDLow())
if (auction && auction->owner == player->GetGUID())
{
Item* pItem = sAuctionMgr->GetAItem(auction->item_guidlow);
Item* pItem = sAuctionMgr->GetAItem(auction->item_guid);
if (pItem)
{
if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
if (auction->bidder) // If we have a bidder, we have to send him the money he paid
{
uint32 auctionCut = auction->GetAuctionCut();
if (!player->HasEnoughMoney(auctionCut)) //player doesn't have enough money, maybe message needed
@@ -552,13 +571,13 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
}
// item will deleted or added to received mail list
MailDraft(auction->BuildAuctionMailSubject(AUCTION_CANCELED), AuctionEntry::BuildAuctionMailBody(0, 0, auction->buyout, auction->deposit, 0))
MailDraft(auction->BuildAuctionMailSubject(AUCTION_CANCELED), AuctionEntry::BuildAuctionMailBody(ObjectGuid::Empty, 0, auction->buyout, auction->deposit, 0))
.AddItem(pItem)
.SendMailTo(trans, player, auction, MAIL_CHECK_MASK_COPIED);
}
else
{
LOG_ERROR("server", "Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow);
LOG_ERROR("server", "Auction id: %u has non-existed item (item: %s)!!!", auction->Id, auction->item_guid.ToString().c_str());
SendAuctionCommandResult(0, AUCTION_CANCEL, ERR_AUCTION_DATABASE_ERROR);
return;
}
@@ -567,7 +586,7 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
{
SendAuctionCommandResult(0, AUCTION_CANCEL, ERR_AUCTION_DATABASE_ERROR);
//this code isn't possible ... maybe there should be assert
LOG_ERROR("server", "CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is nullptr", player->GetGUIDLow(), auctionId);
LOG_ERROR("server", "CHEATER : %s, he tried to cancel auction (id: %u) of another player, or auction is nullptr", player->GetGUID().ToString().c_str(), auctionId);
return;
}
@@ -580,7 +599,7 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
auction->DeleteFromDB(trans);
CharacterDatabase.CommitTransaction(trans);
sAuctionMgr->RemoveAItem(auction->item_guidlow);
sAuctionMgr->RemoveAItem(auction->item_guid);
auctionHouse->RemoveAuction(auction);
}
@@ -591,7 +610,7 @@ void WorldSession::HandleAuctionListBidderItems(WorldPacket& recvData)
LOG_DEBUG("network", "WORLD: Received CMSG_AUCTION_LIST_BIDDER_ITEMS");
#endif
uint64 guid; //NPC guid
ObjectGuid guid; //NPC guid
uint32 listfrom; //page of auctions
uint32 outbiddedCount; //count of outbidded auctions
@@ -608,7 +627,7 @@ void WorldSession::HandleAuctionListBidderItems(WorldPacket& recvData)
if (!creature)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
LOG_DEBUG("network", "WORLD: HandleAuctionListBidderItems - Unit (%s) not found or you can't interact with him.", guid.ToString().c_str());
#endif
recvData.rfinish();
return;
@@ -649,7 +668,7 @@ void WorldSession::HandleAuctionListBidderItems(WorldPacket& recvData)
void WorldSession::HandleAuctionListOwnerItems(WorldPacket& recvData)
{
// prevent crash caused by malformed packet
uint64 guid;
ObjectGuid guid;
uint32 listfrom;
recvData >> guid;
@@ -668,7 +687,7 @@ void WorldSession::HandleAuctionListOwnerItems(WorldPacket& recvData)
_player->m_Events.AddEvent(new AuctionListOwnerItemsDelayEvent(guid, _player->GetGUID(), true), _player->m_Events.CalculateTime(delay - diff));
}
void WorldSession::HandleAuctionListOwnerItemsEvent(uint64 creatureGuid)
void WorldSession::HandleAuctionListOwnerItemsEvent(ObjectGuid creatureGuid)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: Received CMSG_AUCTION_LIST_OWNER_ITEMS");
@@ -680,7 +699,7 @@ void WorldSession::HandleAuctionListOwnerItemsEvent(uint64 creatureGuid)
if (!creature)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("network", "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(creatureGuid)));
LOG_DEBUG("network", "WORLD: HandleAuctionListOwnerItems - Unit (%s) not found or you can't interact with him.", creatureGuid.ToString().c_str());
#endif
return;
}
@@ -714,7 +733,7 @@ void WorldSession::HandleAuctionListItems(WorldPacket& recvData)
std::string searchedname;
uint8 levelmin, levelmax, usable;
uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality;
uint64 guid;
ObjectGuid guid;
recvData >> guid;
recvData >> listfrom; // start, used for page control listing by 50 elements