Skip to content

Commit

Permalink
properly display names of auction owners and bidders (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongdove authored Oct 15, 2024
1 parent fb43d6a commit 50daab9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 59 deletions.
59 changes: 26 additions & 33 deletions src/server/game/AuctionHouse/AuctionHouseMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas
return;

uint32 bidderAccId = 0;
ObjectGuid bidderGuid(HighGuid::Player, auction->bidder);
Player* bidder = ObjectAccessor::FindConnectedPlayer(bidderGuid);
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);
// data for gm.log
std::string bidderName;
bool logGmTrade = false;
Expand All @@ -137,21 +136,20 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas
}
else
{
bidderAccId = sObjectMgr->GetPlayerAccountIdByGUID(bidderGuid);
bidderAccId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder);
logGmTrade = AccountMgr::GetSecurity(bidderAccId, realm.Id.Realm) >= SEC_MODERATOR;

if (logGmTrade && !sObjectMgr->GetPlayerNameByGUID(bidderGuid, bidderName))
if (logGmTrade && !sObjectMgr->GetPlayerNameByGUID(auction->bidder, bidderName))
bidderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);
}

if (logGmTrade)
{
ObjectGuid ownerGuid = ObjectGuid(HighGuid::Player, auction->owner);
std::string ownerName;
if (!sObjectMgr->GetPlayerNameByGUID(ownerGuid, ownerName))
if (!sObjectMgr->GetPlayerNameByGUID(auction->owner, ownerName))
ownerName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN);

uint32 ownerAccId = sObjectMgr->GetPlayerAccountIdByGUID(ownerGuid);
uint32 ownerAccId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);

sLog->outCommand(bidderAccId, "GM %s (Account: %u) won item in auction: %s (Entry: %u Count: %u) and pay money: %u. Original owner %s (Account: %u)",
bidderName.c_str(), bidderAccId, pItem->GetTemplate()->Name1.c_str(), pItem->GetEntry(), pItem->GetCount(), auction->bid, ownerName.c_str(), ownerAccId);
Expand All @@ -169,7 +167,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas

if (bidder)
{
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, bidderGuid, 0, 0, auction->itemEntry);
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, auction->bidder, 0, 0, auction->itemEntry);
// FIXME: for offline player need also
bidder->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS, 1);
}
Expand All @@ -182,9 +180,8 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas

void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, CharacterDatabaseTransaction& trans)
{
ObjectGuid owner_guid(HighGuid::Player, auction->owner);
Player* owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
// owner exist (online or offline)
if (owner || owner_accId && !sAuctionBotConfig->IsBotChar(auction->owner))
MailDraft(auction->BuildAuctionMailSubject(AUCTION_SALE_PENDING), AuctionEntry::BuildAuctionMailBody(auction->bidder, auction->bid, auction->buyout, auction->deposit, auction->GetAuctionCut()))
Expand All @@ -194,9 +191,8 @@ void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, Characte
//call this method to send mail to auction owner, when auction is successful, it does not clear ram
void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry* auction, CharacterDatabaseTransaction& trans)
{
ObjectGuid owner_guid(HighGuid::Player, auction->owner);
Player* owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
// owner exist
if (owner || owner_accId && !sAuctionBotConfig->IsBotChar(auction->owner))
{
Expand Down Expand Up @@ -225,16 +221,15 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry* auction, CharacterDat
if (!pItem)
return;

ObjectGuid owner_guid(HighGuid::Player, auction->owner);
Player* owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(owner_guid);
Player* owner = ObjectAccessor::FindConnectedPlayer(auction->owner);
uint32 owner_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->owner);
// owner exist
if (owner || owner_accId && !sAuctionBotConfig->IsBotChar(auction->owner))
{
if (owner)
owner->GetSession()->SendAuctionOwnerNotification(auction);

MailDraft(auction->BuildAuctionMailSubject(AUCTION_EXPIRED), AuctionEntry::BuildAuctionMailBody(0, 0, auction->buyout, auction->deposit, 0))
MailDraft(auction->BuildAuctionMailSubject(AUCTION_EXPIRED), AuctionEntry::BuildAuctionMailBody(ObjectGuid::Empty, 0, auction->buyout, auction->deposit, 0))
.AddItem(pItem)
.SendMailTo(trans, MailReceiver(owner, auction->owner), auction, MAIL_CHECK_MASK_COPIED, 0);
}
Expand All @@ -248,12 +243,11 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry* auction, CharacterDat
//this function sends mail to old bidder
void AuctionHouseMgr::SendAuctionOutbiddedMail(AuctionEntry* auction, uint64 newPrice, Player* newBidder, CharacterDatabaseTransaction& trans)
{
ObjectGuid oldBidder_guid(HighGuid::Player, auction->bidder);
Player* oldBidder = ObjectAccessor::FindPlayer(oldBidder_guid);
Player* oldBidder = ObjectAccessor::FindPlayer(auction->bidder);

uint32 oldBidder_accId = 0;
if (!oldBidder)
oldBidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(oldBidder_guid);
oldBidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder);

// old bidder exist
if (oldBidder || oldBidder_accId && !sAuctionBotConfig->IsBotChar(auction->bidder))
Expand All @@ -270,12 +264,11 @@ void AuctionHouseMgr::SendAuctionOutbiddedMail(AuctionEntry* auction, uint64 new
//this function sends mail, when auction is cancelled to old bidder
void AuctionHouseMgr::SendAuctionCancelledToBidderMail(AuctionEntry* auction, CharacterDatabaseTransaction& trans, Item* item)
{
ObjectGuid bidder_guid = ObjectGuid(HighGuid::Player, auction->bidder);
Player* bidder = ObjectAccessor::FindConnectedPlayer(bidder_guid);
Player* bidder = ObjectAccessor::FindConnectedPlayer(auction->bidder);

uint32 bidder_accId = 0;
if (!bidder)
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(bidder_guid);
bidder_accId = sObjectMgr->GetPlayerAccountIdByGUID(auction->bidder);

// if (bidder)
// bidder->GetSession()->SendAuctionRemovedNotification(auction->Id, auction->itemEntry, item->GetItemRandomPropertyId());
Expand Down Expand Up @@ -683,7 +676,7 @@ void AuctionHouseObject::BuildListOwnerItems(WorldPacket& data, Player* player,
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
{
AuctionEntry* Aentry = itr->second;
if (Aentry && Aentry->owner == player->GetGUID().GetCounter())
if (Aentry && Aentry->owner == player->GetGUID())
{
if (Aentry->BuildAuctionInfo(data))
++count;
Expand Down Expand Up @@ -847,13 +840,13 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket& data, Item* sourceItem) const
data << uint32(item->GetCount()); // item->count
data << uint32(item->GetSpellCharges()); // item->charge FFFFFFF
data << uint32(0); // Unknown
data << uint64(owner); // Auction->owner
data << owner.GetRawValue(); // Auction->owner
data << uint64(startbid); // Auction->startbid (not sure if useful)
data << uint64(bid ? GetAuctionOutBid() : 0);
// Minimal outbid
data << uint64(buyout); // Auction->buyout
data << uint32((expire_time - GameTime::GetGameTime()) * IN_MILLISECONDS); // time left
data << uint64(bidder); // auction->bidder current
data << bidder.GetRawValue(); // auction->bidder current
data << uint64(bid); // current bid
return true;
}
Expand Down Expand Up @@ -890,10 +883,10 @@ void AuctionEntry::SaveToDB(CharacterDatabaseTransaction& trans) const
stmt->setUInt32(0, Id);
stmt->setUInt32(1, houseId);
stmt->setUInt32(2, itemGUIDLow);
stmt->setUInt32(3, owner);
stmt->setUInt32(3, owner.GetCounter());
stmt->setUInt32(4, buyout);
stmt->setUInt32(5, uint32(expire_time));
stmt->setUInt32(6, bidder);
stmt->setUInt32(6, bidder.GetCounter());
stmt->setUInt32(7, bid);
stmt->setUInt32(8, startbid);
stmt->setUInt32(9, deposit);
Expand All @@ -907,10 +900,10 @@ bool AuctionEntry::LoadFromDB(Field* fields)
itemGUIDLow = fields[2].GetUInt32();
itemEntry = fields[3].GetUInt32();
itemCount = fields[4].GetUInt32();
owner = fields[5].GetUInt32();
owner = ObjectGuid::Create<HighGuid::Player>(fields[5].GetUInt32());
buyout = fields[6].GetUInt32();
expire_time = fields[7].GetUInt32();
bidder = fields[8].GetUInt32();
bidder = ObjectGuid::Create<HighGuid::Player>(fields[8].GetUInt32());
bid = fields[9].GetUInt32();
startbid = fields[10].GetUInt32();
deposit = fields[11].GetUInt32();
Expand Down Expand Up @@ -940,11 +933,11 @@ std::string AuctionEntry::BuildAuctionMailSubject(MailAuctionAnswers response) c
return strm.str();
}

std::string AuctionEntry::BuildAuctionMailBody(ObjectGuid::LowType lowGuid, uint64 bid, uint64 buyout, uint64 deposit, uint64 cut)
std::string AuctionEntry::BuildAuctionMailBody(ObjectGuid guid, uint64 bid, uint64 buyout, uint64 deposit, uint64 cut)
{
std::ostringstream strm;
strm.width(16);
strm << std::right << std::hex << ObjectGuid(HighGuid::Player, lowGuid).GetRawValue(); // HighGuid::Player always present, even for empty guids
strm << std::right << std::hex << guid.GetRawValue(); // HighGuid::Player always present, even for empty guids
strm << std::dec << ':' << bid << ':' << buyout;
strm << ':' << deposit << ':' << cut;
return strm.str();
Expand Down
6 changes: 3 additions & 3 deletions src/server/game/AuctionHouse/AuctionHouseMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ struct AuctionEntry
ObjectGuid::LowType itemGUIDLow;
uint32 itemEntry;
uint32 itemCount;
ObjectGuid::LowType owner;
ObjectGuid owner;
uint64 startbid; //maybe useless
uint64 bid;
uint64 buyout;
time_t expire_time;
ObjectGuid::LowType bidder;
ObjectGuid bidder;
uint64 deposit; //deposit can be calculated only when creating auction
uint32 etime;
std::unordered_set<ObjectGuid> bidders;
Expand All @@ -100,7 +100,7 @@ struct AuctionEntry
void SaveToDB(CharacterDatabaseTransaction& trans) const;
bool LoadFromDB(Field* fields);
std::string BuildAuctionMailSubject(MailAuctionAnswers response) const;
static std::string BuildAuctionMailBody(ObjectGuid::LowType lowGuid, uint64 bid, uint64 buyout, uint64 deposit, uint64 cut);
static std::string BuildAuctionMailBody(ObjectGuid guid, uint64 bid, uint64 buyout, uint64 deposit, uint64 cut);
};

//this class is used as auctionhouse instance
Expand Down
18 changes: 9 additions & 9 deletions src/server/game/AuctionHouseBot/AuctionHouseBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool AuctionBotConfig::Initialize()
do
{
Field* fields = result->Fetch();
_AHBotCharacters.push_back(fields[0].GetUInt32());
_AHBotCharacters.push_back(ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32()));
++count;
} while (result->NextRow());
}
Expand Down Expand Up @@ -307,35 +307,35 @@ char const* AuctionBotConfig::GetHouseTypeName(AuctionHouseType houseType)
}

// Picks a random character from the list of AHBot chars
uint32 AuctionBotConfig::GetRandChar() const
ObjectGuid AuctionBotConfig::GetRandChar() const
{
if (_AHBotCharacters.empty())
return 0;
return ObjectGuid::Empty;

return Trinity::Containers::SelectRandomContainerElement(_AHBotCharacters);
}

// Picks a random AHBot character, but excludes a specific one. This is used
// to have another character than the auction owner place bids
uint32 AuctionBotConfig::GetRandCharExclude(uint32 exclude) const
ObjectGuid AuctionBotConfig::GetRandCharExclude(ObjectGuid exclude) const
{
if (_AHBotCharacters.empty())
return 0;
return ObjectGuid::Empty;

std::vector<uint32> filteredCharacters;
std::vector<ObjectGuid> filteredCharacters;
filteredCharacters.reserve(_AHBotCharacters.size() - 1);

for (uint32 charId : _AHBotCharacters)
for (ObjectGuid charId : _AHBotCharacters)
if (charId != exclude)
filteredCharacters.push_back(charId);

if (filteredCharacters.empty())
return 0;
return ObjectGuid::Empty;

return Trinity::Containers::SelectRandomContainerElement(filteredCharacters);
}

bool AuctionBotConfig::IsBotChar(uint32 characterID) const
bool AuctionBotConfig::IsBotChar(ObjectGuid characterID) const
{
return !characterID || std::find(_AHBotCharacters.begin(), _AHBotCharacters.end(), characterID) != _AHBotCharacters.end();
}
Expand Down
8 changes: 4 additions & 4 deletions src/server/game/AuctionHouseBot/AuctionHouseBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ class AuctionBotConfig

uint32 GetItemPerCycleBoost() const { return _itemsPerCycleBoost; }
uint32 GetItemPerCycleNormal() const { return _itemsPerCycleNormal; }
uint32 GetRandChar() const;
uint32 GetRandCharExclude(uint32 exclude) const;
bool IsBotChar(uint32 characterID) const;
ObjectGuid GetRandChar() const;
ObjectGuid GetRandCharExclude(ObjectGuid exclude) const;
bool IsBotChar(ObjectGuid characterID) const;
void Reload() { GetConfigFromFile(); }

static char const* GetHouseTypeName(AuctionHouseType houseType);

private:
std::string _AHBotIncludes;
std::string _AHBotExcludes;
std::vector<uint32> _AHBotCharacters;
std::vector<ObjectGuid> _AHBotCharacters;
uint32 _itemsPerCycleBoost;
uint32 _itemsPerCycleNormal;

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ void AuctionBotSeller::AddNewAuctions(SellerConfiguration& config)
auctionEntry->startbid = bidPrice;
auctionEntry->buyout = buyoutPrice;
auctionEntry->houseId = houseid;
auctionEntry->bidder = 0;
auctionEntry->bidder = ObjectGuid::Empty;
auctionEntry->bid = 0;
auctionEntry->deposit = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount);
auctionEntry->auctionHouseEntry = ahEntry;
Expand Down
18 changes: 9 additions & 9 deletions src/server/game/Handlers/AuctionHouseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
AH->itemGUIDLow = item->GetGUID().GetCounter();
AH->itemEntry = item->GetEntry();
AH->itemCount = item->GetCount();
AH->owner = _player->GetGUID().GetCounter();
AH->owner = _player->GetGUID();
AH->startbid = bid;
AH->bidder = 0;
AH->bidder = ObjectGuid::Empty;
AH->bid = 0;
AH->buyout = buyout;
AH->expire_time = GameTime::GetGameTime() + auctionTime;
Expand Down Expand Up @@ -514,9 +514,9 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
AH->itemGUIDLow = newItem->GetGUID().GetCounter();
AH->itemEntry = newItem->GetEntry();
AH->itemCount = newItem->GetCount();
AH->owner = _player->GetGUID().GetCounter();
AH->owner = _player->GetGUID();
AH->startbid = bid;
AH->bidder = 0;
AH->bidder = ObjectGuid::Empty;
AH->bid = 0;
AH->buyout = buyout;
AH->expire_time = GameTime::GetGameTime() + auctionTime;
Expand Down Expand Up @@ -625,7 +625,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
AuctionEntry* auction = auctionHouse->GetAuction(auctionId);
Player* player = GetPlayer();

if (!auction || auction->owner == player->GetGUID().GetCounter())
if (!auction || auction->owner == player->GetGUID())
{
//you cannot bid your own auction:
SendAuctionCommandResult(NULL, AUCTION_PLACE_BID, ERR_AUCTION_BID_OWN);
Expand Down Expand Up @@ -679,7 +679,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
else
player->ModifyMoney(-int64(price));

auction->bidder = player->GetGUID().GetCounter();
auction->bidder = player->GetGUID();
auction->bid = price;
GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price);

Expand Down Expand Up @@ -712,7 +712,7 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
if (auction->bidder) //buyout for bidded auction ..
sAuctionMgr->SendAuctionOutbiddedMail(auction, auction->buyout, GetPlayer(), trans);
}
auction->bidder = player->GetGUID().GetCounter();
auction->bidder = player->GetGUID();
auction->bid = auction->buyout;
GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);

Expand Down Expand Up @@ -777,7 +777,7 @@ void WorldSession::HandleAuctionRemoveItem(WorldPacket& recvData)
Player* player = GetPlayer();

CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
if (auction && auction->owner == player->GetGUID().GetCounter())
if (auction && auction->owner == player->GetGUID())
{
Item* pItem = sAuctionMgr->GetAItem(auction->itemGUIDLow);
if (pItem)
Expand All @@ -792,7 +792,7 @@ 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);
}
Expand Down

0 comments on commit 50daab9

Please sign in to comment.