Merge pull request #36 from zeb139/cleanup-dangling-expired-auctions

Added config to remove dangling expired/emptied auctions
This commit is contained in:
Nathan Handley
2025-10-08 07:32:59 -05:00
committed by GitHub
4 changed files with 71 additions and 7 deletions

View File

@@ -39,6 +39,13 @@
# Enable/Disable the part of AHBot that puts items up for auction # Enable/Disable the part of AHBot that puts items up for auction
# Default: false (disabled) # Default: false (disabled)
# #
# AuctionHouseBot.ReturnExpiredAuctionItemsToBot
# If enabled (true), returns expired auction items to the AH Bot(s) via
# mail. Note: if enabled, this can cause your bot's mailbox to fill up
# if you don't manage it manually. This can also cause the size of your
# acore_characters.item_instance database table to grow over time.
# Default: false (disabled)
#
# AuctionHouseBot.GUIDs # AuctionHouseBot.GUIDs
# These are the character GUIDS (from characters->characters table) that # These are the character GUIDS (from characters->characters table) that
# will be used to create auctions and otherwise interact with auctions. # will be used to create auctions and otherwise interact with auctions.
@@ -68,6 +75,7 @@ AuctionHouseBot.DEBUG_FILTERS = false
AuctionHouseBot.MinutesBetweenBuyCycle = 1 AuctionHouseBot.MinutesBetweenBuyCycle = 1
AuctionHouseBot.MinutesBetweenSellCycle = 1 AuctionHouseBot.MinutesBetweenSellCycle = 1
AuctionHouseBot.EnableSeller = false AuctionHouseBot.EnableSeller = false
AuctionHouseBot.ReturnExpiredAuctionItemsToBot = false
AuctionHouseBot.GUIDs = 0 AuctionHouseBot.GUIDs = 0
AuctionHouseBot.ItemsPerCycle = 150 AuctionHouseBot.ItemsPerCycle = 150
AuctionHouseBot.ListingExpireTimeInSecondsMin = 900 AuctionHouseBot.ListingExpireTimeInSecondsMin = 900

View File

@@ -41,6 +41,7 @@ AuctionHouseBot::AuctionHouseBot() :
debug_Out_Filters(false), debug_Out_Filters(false),
SellingBotEnabled(false), SellingBotEnabled(false),
BuyingBotEnabled(false), BuyingBotEnabled(false),
ReturnExpiredAuctionItemsToBot(false),
CyclesBetweenBuyActionMin(1), CyclesBetweenBuyActionMin(1),
CyclesBetweenBuyAction(1), CyclesBetweenBuyAction(1),
CyclesBetweenBuyActionMax(1), CyclesBetweenBuyActionMax(1),
@@ -1266,11 +1267,14 @@ void AuctionHouseBot::AddNewAuctionBuyerBotBid(std::vector<Player*> AHBPlayers,
void AuctionHouseBot::Update() void AuctionHouseBot::Update()
{ {
if ((SellingBotEnabled == false) && (BuyingBotEnabled == false))
return;
if (AHCharacters.empty() == true) if (AHCharacters.empty() == true)
return; return;
CleanupExpiredAuctionItems();
if ((SellingBotEnabled == false) && (BuyingBotEnabled == false))
return;
LastBuyCycleCount++; LastBuyCycleCount++;
LastSellCycleCount++; LastSellCycleCount++;
@@ -1369,6 +1373,7 @@ void AuctionHouseBot::InitializeConfiguration()
// Buyer & Seller core properties // Buyer & Seller core properties
SetCyclesBetweenBuyOrSell(); SetCyclesBetweenBuyOrSell();
ReturnExpiredAuctionItemsToBot = sConfigMgr->GetOption<bool>("AuctionHouseBot.ReturnExpiredAuctionItemsToBot", false);
ItemsPerCycle = sConfigMgr->GetOption<uint32>("AuctionHouseBot.ItemsPerCycle", 75); ItemsPerCycle = sConfigMgr->GetOption<uint32>("AuctionHouseBot.ItemsPerCycle", 75);
MaxBuyoutPriceInCopper = sConfigMgr->GetOption<uint32>("AuctionHouseBot.MaxBuyoutPriceInCopper", 1000000000); MaxBuyoutPriceInCopper = sConfigMgr->GetOption<uint32>("AuctionHouseBot.MaxBuyoutPriceInCopper", 1000000000);
BuyoutVariationReducePercent = sConfigMgr->GetOption<float>("AuctionHouseBot.BuyoutVariationReducePercent", 0.15f); BuyoutVariationReducePercent = sConfigMgr->GetOption<float>("AuctionHouseBot.BuyoutVariationReducePercent", 0.15f);
@@ -1647,7 +1652,13 @@ void AuctionHouseBot::EmptyAuctionHouses()
if (ai.characterGUID != 0) if (ai.characterGUID != 0)
sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans); sAuctionMgr->SendAuctionCancelledToBidderMail(auction, trans);
// Remove item from AH // Return item to AHBot if configured, else delete it
if (ReturnExpiredAuctionItemsToBot)
sAuctionMgr->SendAuctionExpiredMail(auction, trans, true, true);
else
Item::DeleteFromDB(trans, auction->item_guid.GetCounter());
// Remove auction from AH
auction->DeleteFromDB(trans); auction->DeleteFromDB(trans);
sAuctionMgr->RemoveAItem(auction->item_guid); sAuctionMgr->RemoveAItem(auction->item_guid);
auctionHouse->RemoveAuction(auction); auctionHouse->RemoveAuction(auction);
@@ -1943,3 +1954,33 @@ void AuctionHouseBot::PopulateVendorItemsPrices()
} while (result->NextRow()); } while (result->NextRow());
} }
} }
void AuctionHouseBot::CleanupExpiredAuctionItems()
{
if (AHCharactersGUIDsForQuery.empty() ||
ReturnExpiredAuctionItemsToBot)
return;
// Delete item_instances that are not in the Auction Houses
std::string queryItemInstancesString = R"SQL(
SELECT guid
FROM item_instance
LEFT JOIN auctionhouse ON auctionhouse.itemguid = item_instance.guid
WHERE item_instance.owner_guid IN ({})
AND auctionhouse.id IS NULL
)SQL";
QueryResult queryItemInstancesResult = CharacterDatabase.Query(queryItemInstancesString, AHCharactersGUIDsForQuery);
if (!queryItemInstancesResult)
return;
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
do
{
uint32 guid = queryItemInstancesResult->Fetch()[0].Get<uint32>();
Item::DeleteFromDB(trans, guid);
} while (queryItemInstancesResult->NextRow());
CharacterDatabase.CommitTransaction(trans);
}

View File

@@ -128,6 +128,7 @@ private:
bool SellingBotEnabled; bool SellingBotEnabled;
bool BuyingBotEnabled; bool BuyingBotEnabled;
bool ReturnExpiredAuctionItemsToBot;
uint32 CyclesBetweenBuyActionMin; uint32 CyclesBetweenBuyActionMin;
uint32 CyclesBetweenBuyAction; uint32 CyclesBetweenBuyAction;
uint32 CyclesBetweenBuyActionMax; uint32 CyclesBetweenBuyActionMax;
@@ -322,6 +323,7 @@ public:
void AddNewAuctions(std::vector<Player*> AHBPlayers, FactionSpecificAuctionHouseConfig* config); void AddNewAuctions(std::vector<Player*> AHBPlayers, FactionSpecificAuctionHouseConfig* config);
void AddNewAuctionBuyerBotBid(std::vector<Player*> AHBPlayers, FactionSpecificAuctionHouseConfig* config); void AddNewAuctionBuyerBotBid(std::vector<Player*> AHBPlayers, FactionSpecificAuctionHouseConfig* config);
void PopulateVendorItemsPrices(); void PopulateVendorItemsPrices();
void CleanupExpiredAuctionItems();
template <typename ValueType> template <typename ValueType>
void AddItemValuePairsToItemIDMap(std::unordered_map<uint32, ValueType>& workingValueToItemIDMap, std::string valueToItemIDMap); void AddItemValuePairsToItemIDMap(std::unordered_map<uint32, ValueType>& workingValueToItemIDMap, std::string valueToItemIDMap);

View File

@@ -62,7 +62,7 @@ public:
} }
} }
void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& /*sendMail*/) override void OnBeforeAuctionHouseMgrSendAuctionExpiredMail(AuctionHouseMgr* /*auctionHouseMgr*/, AuctionEntry* /*auction*/, Player* owner, uint32& /*owner_accId*/, bool& sendNotification, bool& sendMail) override
{ {
if (owner) if (owner)
{ {
@@ -78,6 +78,11 @@ public:
if (isAHBot == true) if (isAHBot == true)
{ {
sendNotification = false; sendNotification = false;
if (sConfigMgr->GetOption<bool>("AuctionHouseBot.ReturnExpiredAuctionItemsToBot", false))
sendMail = true;
else
sendMail = false;
} }
} }
} }
@@ -112,9 +117,17 @@ public:
} }
if (isAHBot == true) if (isAHBot == true)
{ {
if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items if (sConfigMgr->GetOption<bool>("AuctionHouseBot.ReturnExpiredAuctionItemsToBot", false))
deleteMailItemsFromDB = true; {
sendMail = false; deleteMailItemsFromDB = false;
sendMail = true;
}
else
{
if (sender.GetMailMessageType() == MAIL_AUCTION) // auction mail with items
deleteMailItemsFromDB = true;
sendMail = false;
}
} }
} }
}; };