mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
[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
This commit is contained in:
@@ -408,18 +408,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
|
||||
uint32 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
|
||||
@@ -468,6 +482,7 @@ void AuctionHouseMgr::PendingAuctionProcess(Player* player)
|
||||
}
|
||||
|
||||
AH->DeleteFromDB(trans);
|
||||
|
||||
AH->SaveToDB(trans);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,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();
|
||||
|
||||
@@ -309,10 +309,16 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
|
||||
|
||||
TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) 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().GetCounter(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUID().GetCounter(), item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId());
|
||||
|
||||
// Add to pending auctions, or fail with insufficient funds error
|
||||
if (!sAuctionMgr->PendingAuctionAdd(_player, AH, item))
|
||||
{
|
||||
SendAuctionCommandResult(AH->Id, 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();
|
||||
@@ -360,10 +366,16 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData)
|
||||
|
||||
TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s (guid %d) is selling item %s entry %u (guid %d) 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().GetCounter(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUID().GetCounter(), newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId());
|
||||
|
||||
// Add to pending auctions, or fail with insufficient funds error
|
||||
if (!sAuctionMgr->PendingAuctionAdd(_player, AH, newItem))
|
||||
{
|
||||
SendAuctionCommandResult(AH->Id, AUCTION_SELL_ITEM, ERR_AUCTION_NOT_ENOUGHT_MONEY);
|
||||
return;
|
||||
}
|
||||
|
||||
sAuctionMgr->AddAItem(newItem);
|
||||
auctionHouse->AddAuction(AH);
|
||||
sAuctionMgr->PendingAuctionAdd(_player, AH);
|
||||
|
||||
for (uint32 j = 0; j < itemsCount; ++j)
|
||||
{
|
||||
Item* item2 = items[j];
|
||||
|
||||
Reference in New Issue
Block a user