aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/database/Database/Implementation/CharacterDatabase.cpp3
-rw-r--r--src/server/database/Database/Implementation/CharacterDatabase.h3
-rw-r--r--src/server/game/AuctionHouse/AuctionHouseMgr.cpp46
-rw-r--r--src/server/game/AuctionHouse/AuctionHouseMgr.h2
-rw-r--r--src/server/game/Handlers/AuctionHouseHandler.cpp10
5 files changed, 53 insertions, 11 deletions
diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp
index 398973a7e85..33b691efaf7 100644
--- a/src/server/database/Database/Implementation/CharacterDatabase.cpp
+++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp
@@ -127,6 +127,9 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_SEL_AUCTIONS, "SELECT id, houseid, itemguid, itemEntry, count, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit FROM auctionhouse ah INNER JOIN item_instance ii ON ii.guid = ah.itemguid", CONNECTION_SYNCH);
PrepareStatement(CHAR_INS_AUCTION, "INSERT INTO auctionhouse (id, houseid, itemguid, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_AUCTION, "DELETE FROM auctionhouse WHERE id = ?", CONNECTION_ASYNC);
+ PrepareStatement(CHAR_SEL_AUCTION_BIDDERS, "SELECT id, bidderguid FROM auctionbidders", CONNECTION_SYNCH);
+ PrepareStatement(CHAR_INS_AUCTION_BIDDERS, "INSERT IGNORE INTO auctionbidders (id, bidderguid) VALUES (?, ?)", CONNECTION_ASYNC);
+ PrepareStatement(CHAR_DEL_AUCTION_BIDDERS, "DELETE FROM auctionbidders WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_UPD_AUCTION_BID, "UPDATE auctionhouse SET buyguid = ?, lastbid = ? WHERE id = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_INS_MAIL, "INSERT INTO mail(id, messageType, stationery, mailTemplateId, sender, receiver, subject, body, has_items, expire_time, deliver_time, money, cod, checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_MAIL_BY_ID, "DELETE FROM mail WHERE id = ?", CONNECTION_ASYNC);
diff --git a/src/server/database/Database/Implementation/CharacterDatabase.h b/src/server/database/Database/Implementation/CharacterDatabase.h
index 8f59059abc0..8803ab3c6b3 100644
--- a/src/server/database/Database/Implementation/CharacterDatabase.h
+++ b/src/server/database/Database/Implementation/CharacterDatabase.h
@@ -113,6 +113,9 @@ enum CharacterDatabaseStatements : uint32
CHAR_DEL_AUCTION,
CHAR_UPD_AUCTION_BID,
CHAR_SEL_AUCTIONS,
+ CHAR_SEL_AUCTION_BIDDERS,
+ CHAR_INS_AUCTION_BIDDERS,
+ CHAR_DEL_AUCTION_BIDDERS,
CHAR_INS_MAIL,
CHAR_DEL_MAIL_BY_ID,
CHAR_INS_MAIL_ITEM,
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
index 1dabff8a76e..d4faa188493 100644
--- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
+++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
@@ -355,21 +355,37 @@ void AuctionHouseMgr::LoadAuctions()
uint32 oldMSTime = getMSTime();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTIONS);
- PreparedQueryResult result = CharacterDatabase.Query(stmt);
+ PreparedQueryResult resultAuctions = CharacterDatabase.Query(stmt);
- if (!result)
+ if (!resultAuctions)
{
TC_LOG_INFO("server.loading", ">> Loaded 0 auctions. DB table `auctionhouse` is empty.");
return;
}
- uint32 count = 0;
+ // parse bidder list
+ std::unordered_map<uint32, std::unordered_set<ObjectGuid>> biddersByAuction;
+ PreparedStatement* stmt2 = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTION_BIDDERS);
+ uint32 countBidders = 0;
+ if (PreparedQueryResult resultBidders = CharacterDatabase.Query(stmt2))
+ {
+ do
+ {
+ Field* fields = resultBidders->Fetch();
+ biddersByAuction[fields[0].GetUInt32()].insert(ObjectGuid::Create<HighGuid::Player>(fields[1].GetUInt32()));
+ ++countBidders;
+ }
+ while (resultBidders->NextRow());
+ }
+
+ // parse auctions from db
+ uint32 countAuctions = 0;
SQLTransaction trans = CharacterDatabase.BeginTransaction();
do
{
- Field* fields = result->Fetch();
+ Field* fields = resultAuctions->Fetch();
AuctionEntry* aItem = new AuctionEntry();
if (!aItem->LoadFromDB(fields))
@@ -379,14 +395,17 @@ void AuctionHouseMgr::LoadAuctions()
continue;
}
+ auto it = biddersByAuction.find(aItem->Id);
+ if (it != biddersByAuction.end())
+ aItem->bidders = std::move(it->second);
+
GetAuctionsMapByHouseId(aItem->houseId)->AddAuction(aItem);
- ++count;
- } while (result->NextRow());
+ ++countAuctions;
+ } while (resultAuctions->NextRow());
CharacterDatabase.CommitTransaction(trans);
- TC_LOG_INFO("server.loading", ">> Loaded %u auctions in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
-
+ TC_LOG_INFO("server.loading", ">> Loaded %u auctions with %u bidders in %u ms", countAuctions, countBidders, GetMSTimeDiffToNow(oldMSTime));
}
void AuctionHouseMgr::AddAItem(Item* it)
@@ -656,7 +675,7 @@ void AuctionHouseObject::BuildListBidderItems(WorldPacket& data, Player* player,
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
{
AuctionEntry* Aentry = itr->second;
- if (Aentry && Aentry->bidder == player->GetGUID().GetCounter())
+ if (Aentry && Aentry->bidders.find(player->GetGUID()) != Aentry->bidders.end())
{
if (itr->second->BuildAuctionInfo(data))
++count;
@@ -863,7 +882,13 @@ uint32 AuctionEntry::GetAuctionOutBid() const
void AuctionEntry::DeleteFromDB(SQLTransaction& trans) const
{
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_AUCTION);
+ PreparedStatement* stmt;
+
+ stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_AUCTION);
+ stmt->setUInt32(0, Id);
+ trans->Append(stmt);
+
+ stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_AUCTION_BIDDERS);
stmt->setUInt32(0, Id);
trans->Append(stmt);
}
@@ -913,6 +938,7 @@ bool AuctionEntry::LoadFromDB(Field* fields)
TC_LOG_ERROR("misc", "Auction %u has not a existing item : %u", Id, itemGUIDLow);
return false;
}
+
return true;
}
std::string AuctionEntry::BuildAuctionMailSubject(MailAuctionAnswers response) const
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h
index 2fad4264d15..3c2080b1ad5 100644
--- a/src/server/game/AuctionHouse/AuctionHouseMgr.h
+++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h
@@ -88,6 +88,7 @@ struct TC_GAME_API AuctionEntry
ObjectGuid::LowType bidder;
uint32 deposit; //deposit can be calculated only when creating auction
uint32 etime;
+ std::unordered_set<ObjectGuid> bidders;
AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc
// helpers
@@ -164,7 +165,6 @@ class TC_GAME_API AuctionHouseMgr
AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
AuctionHouseObject* GetAuctionsMapByHouseId(uint8 auctionHouseId);
- AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
Item* GetAItem(ObjectGuid::LowType id)
{
diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp
index a0d6ae3bdd2..89db6ee6e69 100644
--- a/src/server/game/Handlers/AuctionHouseHandler.cpp
+++ b/src/server/game/Handlers/AuctionHouseHandler.cpp
@@ -515,6 +515,16 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData)
stmt->setUInt32(2, auction->Id);
trans->Append(stmt);
+ if (auction->bidders.find(player->GetGUID()) == auction->bidders.end())
+ {
+ // save new bidder in list, and save record to db
+ auction->bidders.insert(player->GetGUID());
+ stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_AUCTION_BIDDERS);
+ stmt->setUInt32(0, auction->Id);
+ stmt->setUInt32(1, auction->bidder);
+ trans->Append(stmt);
+ }
+
SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, ERR_AUCTION_OK, 0);
}
else