diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AuctionHouse/AuctionHouseMgr.cpp | 17 | ||||
-rw-r--r-- | src/server/game/AuctionHouse/AuctionHouseMgr.h | 2 | ||||
-rw-r--r-- | src/server/game/Handlers/AuctionHouseHandler.cpp | 19 |
3 files changed, 33 insertions, 5 deletions
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 4118ea902f5..253570dcba1 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -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); } diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index 6c5d39586b5..b0f93ee86ef 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -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(); diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index 6c29619d38b..6cc5c0b3012 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -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) { |