[Core/AH] Correctly check player can pay deposit

- Deposit amount wasn't correctly checked in the case of multiple items,
   player with insufficient funds could auctin more items than they should

(cherrypicked from 6bd9aa2787)
This commit is contained in:
r00ty-tc
2017-02-19 00:47:59 +00:00
committed by Shauren
parent 00454fdd45
commit 83e2777249
3 changed files with 33 additions and 5 deletions

View File

@@ -402,18 +402,32 @@ bool AuctionHouseMgr::RemoveAItem(ObjectGuid::LowType id, bool deleteItem)
return true;
}
void AuctionHouseMgr::PendingAuctionAdd(Player* player, AuctionEntry* aEntry)
bool AuctionHouseMgr::PendingAuctionAdd(Player* player, AuctionEntry* aEntry, Item* item)
{
PlayerAuctions* thisAH;
auto itr = pendingAuctionMap.find(player->GetGUID());
if (itr != pendingAuctionMap.end())
{
thisAH = itr->second.first;
// Get deposit so far
uint64 totalDeposit = 0;
for (AuctionEntry const* thisAuction : *thisAH)
totalDeposit += GetAuctionDeposit(thisAuction->auctionHouseEntry, thisAuction->etime, item, thisAuction->itemCount);
// Add this deposit
totalDeposit += GetAuctionDeposit(aEntry->auctionHouseEntry, aEntry->etime, item, aEntry->itemCount);
if (!player->HasEnoughMoney(totalDeposit))
return false;
}
else
{
thisAH = new PlayerAuctions;
pendingAuctionMap[player->GetGUID()] = AuctionPair(thisAH, 0);
}
thisAH->push_back(aEntry);
return true;
}
uint32 AuctionHouseMgr::PendingAuctionCount(const Player* player) const
@@ -462,6 +476,7 @@ void AuctionHouseMgr::PendingAuctionProcess(Player* player)
}
AH->DeleteFromDB(trans);
AH->SaveToDB(trans);
}

View File

@@ -229,7 +229,7 @@ class TC_GAME_API AuctionHouseMgr
void AddAItem(Item* it);
bool RemoveAItem(ObjectGuid::LowType id, bool deleteItem = false);
void PendingAuctionAdd(Player* player, AuctionEntry* aEntry);
bool PendingAuctionAdd(Player* player, AuctionEntry* aEntry, Item* item);
uint32 PendingAuctionCount(const Player* player) const;
void PendingAuctionProcess(Player* player);
void UpdatePendingAuctions();

View File

@@ -268,10 +268,16 @@ void WorldSession::HandleAuctionSellItem(WorldPackets::AuctionHouse::AuctionSell
TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: %s %s is selling item %s %s to auctioneer " UI64FMTD " with count %u with initial bid " UI64FMTD " with buyout " UI64FMTD " and with time %u (in sec) in auctionhouse %u",
_player->GetGUID().ToString().c_str(), _player->GetName().c_str(), item->GetGUID().ToString().c_str(), item->GetTemplate()->GetDefaultLocaleName(), AH->auctioneer, item->GetCount(), packet.MinBid, packet.BuyoutPrice, auctionTime, AH->GetHouseId());
// Add to pending auctions, or fail with insufficient funds error
if (!sAuctionMgr->PendingAuctionAdd(_player, AH, item))
{
SendAuctionCommandResult(AH, AUCTION_SELL_ITEM, ERR_AUCTION_NOT_ENOUGHT_MONEY);
return;
}
sAuctionMgr->AddAItem(item);
auctionHouse->AddAuction(AH);
sAuctionMgr->PendingAuctionAdd(_player, AH);
_player->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
@@ -319,9 +325,16 @@ void WorldSession::HandleAuctionSellItem(WorldPackets::AuctionHouse::AuctionSell
TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: %s %s is selling %s %s to auctioneer " UI64FMTD " with count %u with initial bid " UI64FMTD " with buyout " UI64FMTD " and with time %u (in sec) in auctionhouse %u",
_player->GetGUID().ToString().c_str(), _player->GetName().c_str(), newItem->GetGUID().ToString().c_str(), newItem->GetTemplate()->GetDefaultLocaleName(), AH->auctioneer, newItem->GetCount(), packet.MinBid, packet.BuyoutPrice, auctionTime, AH->GetHouseId());
// Add to pending auctions, or fail with insufficient funds error
if (!sAuctionMgr->PendingAuctionAdd(_player, AH, newItem))
{
SendAuctionCommandResult(AH, AUCTION_SELL_ITEM, ERR_AUCTION_NOT_ENOUGHT_MONEY);
return;
}
sAuctionMgr->AddAItem(newItem);
auctionHouse->AddAuction(AH);
sAuctionMgr->PendingAuctionAdd(_player, AH);
for (std::size_t i = 0; i < packet.Items.size(); ++i)
{