diff options
author | Shauren <shauren.trinity@gmail.com> | 2020-09-27 00:51:52 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2020-09-27 00:51:52 +0200 |
commit | d0d0f51f325e4ae42c9bef7606fed4f4c00c98d6 (patch) | |
tree | 81695bac1c498d8806965e0dd11bbac1e87e1d98 | |
parent | dc56f0a1d90af192a2df8612197b675fe25cac5b (diff) |
Core/Auction House: Eliminate blocking db queries for account permissions when expiring auctions that have offline bidders
8 files changed, 34 insertions, 8 deletions
diff --git a/sql/base/characters_database.sql b/sql/base/characters_database.sql index 0a03202302e..eb084c1256c 100644 --- a/sql/base/characters_database.sql +++ b/sql/base/characters_database.sql @@ -246,6 +246,7 @@ CREATE TABLE `auctionhouse` ( `lastbid` int(10) unsigned NOT NULL DEFAULT '0', `startbid` int(10) unsigned NOT NULL DEFAULT '0', `deposit` int(10) unsigned NOT NULL DEFAULT '0', + `Flags` tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `item_guid` (`itemguid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -2651,7 +2652,8 @@ INSERT INTO `updates` VALUES ('2020_08_15_00_characters.sql','70979D488ACD23DEB8E45D31C3ADC690A1B81F79','ARCHIVED','2020-08-15 09:34:44',0), ('2020_08_22_00_characters.sql','78251072C9281D98BC4EAC523DA0858C9F8425D9','ARCHIVED','2020-08-22 16:27:27',0), ('2020_09_02_00_characters.sql','627F320D58A42F401AB10ABA927F2B37C1981576','ARCHIVED','2020-09-02 17:41:04',0), -('2020_09_15_00_characters.sql','1B650E8C815E29AE261238B010BC9EB35BD49A25','ARCHIVED','2020-09-15 19:35:18',0); +('2020_09_15_00_characters.sql','1B650E8C815E29AE261238B010BC9EB35BD49A25','ARCHIVED','2020-09-15 19:35:18',0), +('2020_09_27_00_characters.sql','441A0E8717165067D13B206F6925EEEA774262F3','RELEASED','2020-09-27 00:27:19',0); /*!40000 ALTER TABLE `updates` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/updates/characters/3.3.5/2020_09_27_00_characters.sql b/sql/updates/characters/3.3.5/2020_09_27_00_characters.sql new file mode 100644 index 00000000000..6487a5e6ac5 --- /dev/null +++ b/sql/updates/characters/3.3.5/2020_09_27_00_characters.sql @@ -0,0 +1 @@ +ALTER TABLE `auctionhouse` ADD `Flags` tinyint(3) unsigned NOT NULL DEFAULT '0' AFTER `deposit`; diff --git a/src/server/database/Database/Implementation/CharacterDatabase.cpp b/src/server/database/Database/Implementation/CharacterDatabase.cpp index 78643ee7af7..d181866634c 100644 --- a/src/server/database/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/database/Database/Implementation/CharacterDatabase.cpp @@ -121,14 +121,14 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_SEL_CHARACTER_ACTIONS_SPEC, "SELECT button, action, type FROM character_action WHERE guid = ? AND spec = ? ORDER BY button", CONNECTION_ASYNC); PrepareStatement(CHAR_SEL_MAILITEMS, "SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, item_guid, itemEntry, ii.owner_guid, m.id FROM mail_items mi INNER JOIN mail m ON mi.mail_id = m.id LEFT JOIN item_instance ii ON mi.item_guid = ii.guid WHERE m.receiver = ?", CONNECTION_ASYNC); - PrepareStatement(CHAR_SEL_AUCTION_ITEMS, "SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, itemguid, itemEntry FROM auctionhouse ah JOIN item_instance ii ON ah.itemguid = ii.guid", CONNECTION_SYNCH); - 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_SEL_AUCTION_ITEMS, "SELECT creatorGuid, giftCreatorGuid, count, duration, charges, ii.flags, enchantments, randomPropertyId, durability, playedTime, text, itemguid, itemEntry FROM auctionhouse ah JOIN item_instance ii ON ah.itemguid = ii.guid", CONNECTION_SYNCH); + PrepareStatement(CHAR_SEL_AUCTIONS, "SELECT id, houseid, itemguid, itemEntry, count, itemowner, buyoutprice, time, buyguid, lastbid, startbid, deposit, ah.Flags 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, Flags) 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_UPD_AUCTION_BID, "UPDATE auctionhouse SET buyguid = ?, lastbid = ?, Flags = ? 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); PrepareStatement(CHAR_INS_MAIL_ITEM, "INSERT INTO mail_items(mail_id, item_guid, receiver) VALUES (?, ?, ?)", CONNECTION_ASYNC); diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index fd4b3eb5dee..60d9d057429 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -131,18 +131,16 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, CharacterDatabas Player* bidder = ObjectAccessor::FindConnectedPlayer(bidderGuid); // data for gm.log std::string bidderName; - bool logGmTrade = false; + bool logGmTrade = (auction->Flags & AUCTION_ENTRY_FLAG_GM_LOG_BUYER) != AUCTION_ENTRY_FLAG_NONE; if (bidder) { bidderAccId = bidder->GetSession()->GetAccountId(); bidderName = bidder->GetName(); - logGmTrade = bidder->GetSession()->HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE); } else { bidderAccId = sCharacterCache->GetCharacterAccountIdByGuid(bidderGuid); - logGmTrade = AccountMgr::HasPermission(bidderAccId, rbac::RBAC_PERM_LOG_GM_TRADE, realm.Id.Realm); if (logGmTrade && !sCharacterCache->GetCharacterNameByGuid(bidderGuid, bidderName)) bidderName = sObjectMgr->GetTrinityStringForDBCLocale(LANG_UNKNOWN); @@ -910,6 +908,7 @@ void AuctionEntry::SaveToDB(CharacterDatabaseTransaction trans) const stmt->setUInt32(7, bid); stmt->setUInt32(8, startbid); stmt->setUInt32(9, deposit); + stmt->setUInt8(10, Flags); trans->Append(stmt); } @@ -927,6 +926,7 @@ bool AuctionEntry::LoadFromDB(Field* fields) bid = fields[9].GetUInt32(); startbid = fields[10].GetUInt32(); deposit = fields[11].GetUInt32(); + Flags = AuctionEntryFlag(fields[12].GetUInt8()); auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntryFromHouse(houseId); if (!auctionHouseEntry) diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index 7e4e09c932a..80dba9a5ed3 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -72,6 +72,12 @@ enum AuctionHouses AUCTIONHOUSE_NEUTRAL = 7 }; +enum AuctionEntryFlag : uint8 +{ + AUCTION_ENTRY_FLAG_NONE = 0x0, + AUCTION_ENTRY_FLAG_GM_LOG_BUYER = 0x1 // write transaction to gm log file for buyer (optimization flag - avoids querying database for offline player permissions) +}; + struct TC_GAME_API AuctionEntry { uint32 Id; @@ -89,6 +95,7 @@ struct TC_GAME_API AuctionEntry uint32 etime; std::unordered_set<ObjectGuid> bidders; AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc + AuctionEntryFlag Flags; // helpers uint8 GetHouseId() const { return houseId; } diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp index 380d719e2be..ce92481cb38 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBotBuyer.cpp @@ -431,12 +431,14 @@ void AuctionBotBuyer::PlaceBidToEntry(AuctionEntry* auction, uint32 bidPrice) // Set bot as bidder and set new bid amount auction->bidder = sAuctionBotConfig->GetRandCharExclude(auction->owner); auction->bid = bidPrice; + auction->Flags = AuctionEntryFlag(auction->Flags & ~AUCTION_ENTRY_FLAG_GM_LOG_BUYER); // Update auction to DB CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_BID); stmt->setUInt32(0, auction->bidder); stmt->setUInt32(1, auction->bid); stmt->setUInt32(2, auction->Id); + stmt->setUInt8(3, auction->Flags); trans->Append(stmt); // Run SQLs diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp index e9fc8fc98c4..2705c4067f5 100644 --- a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp +++ b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp @@ -928,6 +928,7 @@ void AuctionBotSeller::AddNewAuctions(SellerConfiguration& config) auctionEntry->deposit = sAuctionMgr->GetAuctionDeposit(ahEntry, etime, item, stackCount); auctionEntry->auctionHouseEntry = ahEntry; auctionEntry->expire_time = GameTime::GetGameTime() + urand(config.GetMinTime(), config.GetMaxTime()) * HOUR; + auctionEntry->Flags = AUCTION_ENTRY_FLAG_NONE; item->SaveToDB(trans); sAuctionMgr->AddAItem(item); diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index bcd9091acfe..1ac1da51427 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -311,6 +311,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AH->deposit = deposit; AH->etime = etime; AH->auctionHouseEntry = auctionHouseEntry; + AH->Flags = AUCTION_ENTRY_FLAG_NONE; TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s %s is selling item %s entry %u %s 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().ToString().c_str(), item->GetTemplate()->Name1.c_str(), item->GetEntry(), item->GetGUID().ToString().c_str(), item->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); @@ -368,6 +369,7 @@ void WorldSession::HandleAuctionSellItem(WorldPacket& recvData) AH->deposit = deposit; AH->etime = etime; AH->auctionHouseEntry = auctionHouseEntry; + AH->Flags = AUCTION_ENTRY_FLAG_NONE; TC_LOG_INFO("network", "CMSG_AUCTION_SELL_ITEM: Player %s %s is selling item %s entry %u %s 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().ToString().c_str(), newItem->GetTemplate()->Name1.c_str(), newItem->GetEntry(), newItem->GetGUID().ToString().c_str(), newItem->GetCount(), bid, buyout, auctionTime, AH->GetHouseId()); @@ -507,12 +509,18 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) auction->bidder = player->GetGUID().GetCounter(); auction->bid = price; + if (HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE)) + auction->Flags = AuctionEntryFlag(auction->Flags | AUCTION_ENTRY_FLAG_GM_LOG_BUYER); + else + auction->Flags = AuctionEntryFlag(auction->Flags & ~AUCTION_ENTRY_FLAG_GM_LOG_BUYER); + GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, price); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_AUCTION_BID); stmt->setUInt32(0, auction->bidder); stmt->setUInt32(1, auction->bid); stmt->setUInt32(2, auction->Id); + stmt->setUInt8(3, auction->Flags); trans->Append(stmt); if (auction->bidders.find(player->GetGUID()) == auction->bidders.end()) @@ -540,6 +548,11 @@ void WorldSession::HandleAuctionPlaceBid(WorldPacket& recvData) } auction->bidder = player->GetGUID().GetCounter(); auction->bid = auction->buyout; + if (HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE)) + auction->Flags = AuctionEntryFlag(auction->Flags | AUCTION_ENTRY_FLAG_GM_LOG_BUYER); + else + auction->Flags = AuctionEntryFlag(auction->Flags & ~AUCTION_ENTRY_FLAG_GM_LOG_BUYER); + GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout); //- Mails must be under transaction control too to prevent data loss |