void AuctionHouseMgr::PendingAuctionProcess(Player* player) { auto iterMap = pendingAuctionMap.find(player->GetGUID()); if (iterMap == pendingAuctionMap.end()) return; PlayerAuctions* thisAH = iterMap->second.first; SQLTransaction trans = CharacterDatabase.BeginTransaction(); uint32 totalItems = 0; for (auto itrAH = thisAH->begin(); itrAH != thisAH->end(); ++itrAH) { AuctionEntry* AH = (*itrAH); totalItems += AH->itemCount; } uint32 totaldeposit = 0; auto itr = (*thisAH->begin()); if (Item* item = GetAItem(itr->itemGUIDLow)) totaldeposit = GetAuctionDeposit(itr->auctionHouseEntry, itr->etime, item, totalItems); uint32 depositremain = totaldeposit; for (auto itr = thisAH->begin(); itr != thisAH->end(); ++itr) { AuctionEntry* AH = (*itr); if (next(itr) == thisAH->end()) AH->deposit = depositremain; else { AH->deposit = totaldeposit / thisAH->size(); depositremain -= AH->deposit; } AH->DeleteFromDB(trans); AH->SaveToDB(trans); } CharacterDatabase.CommitTransaction(trans); pendingAuctionMap.erase(player->GetGUID()); delete thisAH; player->ModifyMoney(-int32(totaldeposit)); }
void AuctionHouseMgr::UpdatePendingAuctions() { for (auto itr = pendingAuctionMap.begin(); itr != pendingAuctionMap.end();) { ObjectGuid playerGUID = itr->first; if (Player* player = ObjectAccessor::FindConnectedPlayer(playerGUID)) { // Check if there were auctions since last update process if not if (PendingAuctionCount(player) == itr->second.second) { ++itr; PendingAuctionProcess(player); } else { ++itr; pendingAuctionMap[playerGUID].second = PendingAuctionCount(player); } } else { // Expire any auctions that we couldn't get a deposit for TC_LOG_WARN("auctionHouse", "Player %s was offline, unable to retrieve deposit!", playerGUID.ToString().c_str()); PlayerAuctions* thisAH = itr->second.first; ++itr; SQLTransaction trans = CharacterDatabase.BeginTransaction(); for (auto AHitr = thisAH->begin(); AHitr != thisAH->end();) { AuctionEntry* AH = (*AHitr); ++AHitr; AH->expire_time = time(NULL); AH->DeleteFromDB(trans); AH->SaveToDB(trans); } CharacterDatabase.CommitTransaction(trans); pendingAuctionMap.erase(playerGUID); delete thisAH; } } }