From 17c3956bac2e772c4416ec70d4e654600b152409 Mon Sep 17 00:00:00 2001 From: NathanHandley Date: Sun, 9 Mar 2025 12:15:35 -0500 Subject: [PATCH] Started multi-account support (no compile) --- conf/mod_ahbot.conf.dist | 30 ++++++++---- src/AuctionHouseBot.cpp | 101 ++++++++++++++++++++++++++++++++++----- src/AuctionHouseBot.h | 23 +++++++-- 3 files changed, 126 insertions(+), 28 deletions(-) diff --git a/conf/mod_ahbot.conf.dist b/conf/mod_ahbot.conf.dist index 5d9fce2..1aa5fea 100644 --- a/conf/mod_ahbot.conf.dist +++ b/conf/mod_ahbot.conf.dist @@ -2,7 +2,6 @@ ############################################################################### # AUCTION HOUSE BOT SETTINGS -# # AuctionHouseBot.DEBUG # Enable/Disable Debugging output # Default 0 (disabled) @@ -19,21 +18,32 @@ # Enable/Disable the part of AHBot that buys items from players # Default 0 (disabled) # -# Auction House Bot character data -# AuctionHouseBot.Account is the account number -# (in realmd->account table) of the player you want to run -# as the auction bot. -# AuctionHouseBot.GUID is the GUID (in characters->characters table) -# of the player you want to run as the auction bot. -# Default: 0 (Auction House Bot disabled) +# AuctionHouseBot.GUIDs +# These are the character GUIDS (from characters->characters table) that +# will be used to create auctions and otherwise interact with auctions. +# It can be a single value or multiple values that are separated by a +# comma. Note: a GUID of "0" will be ignored! +# Examples: +# AuctionHouseBot.GUIDs = 3 <- Only character with GUID 3 +# AuctionHouseBot.GUIDs = 3,4 <- Both characters with GUID 3 and 4 +# +# AuctionHouseBot.BotsPerCycle +# If using more than one GUID, this is how many of them will come on +# to do auction behaviors each cycle. Too many might impact performance +# since the bot sessions are created and destroyed. +# Default 1 (single random bot from GUID list) +# +# AuctionHouseBot.ItemsPerCycle +# How many items to post on the auction house every house update +# Default 75 ############################################################################### AuctionHouseBot.DEBUG = 0 AuctionHouseBot.DEBUG_FILTERS = 0 AuctionHouseBot.EnableSeller = 1 AuctionHouseBot.EnableBuyer = 1 -AuctionHouseBot.Account = 14 -AuctionHouseBot.GUID = 3 +AuctionHouseBot.GUIDs = 42,43,44,45,46 +AuctionHouseBot.BotsPerCycle = 1 AuctionHouseBot.ItemsPerCycle = 75 ############################################################################### diff --git a/src/AuctionHouseBot.cpp b/src/AuctionHouseBot.cpp index 7f0e6e5..f6ba8d2 100644 --- a/src/AuctionHouseBot.cpp +++ b/src/AuctionHouseBot.cpp @@ -728,11 +728,35 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con } } +void AuctionHouseBot::LoadBotSessions(std::vector& outPlayerSessions) +{ + // Determine number to load + uint32 numOfBotsToLoad = BotsPerCycle; + if (AHCharacters.size() < BotsPerCycle) + numOfBotsToLoad = AHCharacters.size(); + + // Build a shufflebag for char indices to pick from + std::deque charGUIDBag; + for (AuctionHouseBotCharacter ahBot : AHCharacters) + charGUIDBag.push_back(ahBot.CharacterGUID); + + // Pluck out the guids and load them one at a time + for (uint32 i = 0; i < numOfBotsToLoad; i++) + { + + + + + } +} + void AuctionHouseBot::Update() { time_t _newrun = time(NULL); if ((!AHBSeller) && (!AHBBuyer)) return; + if (AHCharacters.size() == 0) + return; std::string accountName = "AuctionHouseBot" + std::to_string(AHBplayerAccount); @@ -789,9 +813,11 @@ void AuctionHouseBot::InitializeConfiguration() AHBSeller = sConfigMgr->GetOption("AuctionHouseBot.EnableSeller", false); AHBBuyer = sConfigMgr->GetOption("AuctionHouseBot.EnableBuyer", false); - AHBplayerAccount = sConfigMgr->GetOption("AuctionHouseBot.Account", 0); - AHBplayerGUID = sConfigMgr->GetOption("AuctionHouseBot.GUID", 0); - ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle", 200); + AddCharacters(sConfigMgr->GetOption("AuctionHouseBot.GUIDs", 0)); + if (AHCharacters.size() == 0) + AddCharacters(sConfigMgr->GetOption("AuctionHouseBot.GUID", 0)); // Backwards compat + ItemsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.ItemsPerCycle", 75); + BotsPerCycle = sConfigMgr->GetOption("AuctionHouseBot.BotsPerCycle", 1); // Stack Ratios RandomStackRatioConsumable = GetRandomStackValue("AuctionHouseBot.RandomStackRatio.Consumable", 20); @@ -876,16 +902,6 @@ void AuctionHouseBot::InitializeConfiguration() AddDisabledItems(sConfigMgr->GetOption("AuctionHouseBot.DisabledItemIDs", "")); AddDisabledItems(sConfigMgr->GetOption("AuctionHouseBot.DisabledCraftedItemIDs", "")); - if ((AHBplayerAccount != 0) || (AHBplayerGUID != 0)) - { - QueryResult result = CharacterDatabase.Query("SELECT 1 FROM characters WHERE account = {} AND guid = {}", AHBplayerAccount, AHBplayerGUID); - if (!result) - { - LOG_ERROR("module", "AuctionHouseBot: The account/GUID-information set for your AHBot is incorrect (account: {} guid: {})", AHBplayerAccount, AHBplayerGUID); - return; - } - } - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) { AllianceConfig.SetMinItems(sConfigMgr->GetOption("AuctionHouseBot.Alliance.MinItems", 15000)); @@ -928,6 +944,65 @@ void AuctionHouseBot::AddToDisabledItems(std::set& workingDisabledItemID } } +void AuctionHouseBot::AddCharacters(std::string characterGUIDString) +{ + std::string delimitedValue; + std::stringstream characterGUIDStream; + std::set characterGUIDs; + + // Grab from the string + characterGUIDStream.str(characterGUIDString); + while (std::getline(characterGUIDStream, delimitedValue, ',')) // Process each charecter GUID in the string, delimited by the comma "," + { + std::string valueOne; + std::stringstream characterGUIDStream(delimitedValue); + characterGUIDStream >> valueOne; + auto characterGUID = atoi(valueOne.c_str()); + if (characterGUID == 0) + continue; + if (characterGUIDs.find(characterGUID) != characterGUIDs.end()) + { + if (debug_Out) + LOG_ERROR("module", "AuctionHouseBot: Duplicate character with GUID of {} found, skipping", characterGUID); + } + else + characterGUIDs.insert(characterGUID); + } + + // Lookup accounts and add them + if (characterGUIDs.empty() == true) + { + LOG_ERROR("module", "AuctionHouseBot: No character GUIDs were supplied. Be sure to set AuctionHouseBot.GUIDs"); + return; + } + AHCharactersGUIDsForQuery = ""; + bool first = true; + for (uint32 curGUID : characterGUIDs) + { + if (first == false) + { + AHCharactersGUIDsForQuery += ", "; + } + AHCharactersGUIDsForQuery += std::to_string(curGUID); + first = false; + } + QueryResult queryResult = CharacterDatabase.Query("SELECT `guid`, `account` FROM `characters` WHERE guid IN ({})", AHCharactersGUIDsForQuery); + if (!queryResult || queryResult->GetRowCount() == 0) + { + LOG_ERROR("module", "AuctionHouseBot: No character GUIDs found when looking up values from AuctionHouseBot.GUIDs from the character database 'characters.guid'."); + return; + } + do + { + // Pull the data out + Field* fields = queryResult->Fetch(); + uint32 guid = fields[0].Get(); + uint32 account = fields[1].Get(); + AuctionHouseBotCharacter curChar = AuctionHouseBotCharacter(account, guid); + AHCharacters.push_back(curChar); + } while (queryResult->NextRow()); +} + void AuctionHouseBot::AddDisabledItems(std::string disabledItemIdString) { std::string delimitedValue; diff --git a/src/AuctionHouseBot.h b/src/AuctionHouseBot.h index 115aa5a..ca83908 100644 --- a/src/AuctionHouseBot.h +++ b/src/AuctionHouseBot.h @@ -120,20 +120,30 @@ public: { } }; + +class AuctionHouseBotCharacter +{ +public: + AuctionHouseBotCharacter(uint32 accountID, uint32 characterGUID) : + AccountID(accountID), + CharacterGUID(characterGUID) { } + uint32 AccountID; + ObjectGuid::LowType CharacterGUID; +}; + class AuctionHouseBot { private: - bool debug_Out; bool debug_Out_Filters; bool AHBSeller; bool AHBBuyer; - uint32 AHBplayerAccount; - ObjectGuid::LowType AHBplayerGUID; + std::vector AHCharacters; + std::string AHCharactersGUIDsForQuery; uint32 ItemsPerCycle; - + uint32 BotsPerCycle; bool DisabledItemTextFilter; std::set DisabledItems; uint32 RandomStackRatioConsumable; @@ -239,10 +249,13 @@ public: void Initialize(); void InitializeConfiguration(); uint32 GetRandomStackValue(std::string configKeyString, uint32 defaultValue); + + void AddCharacters(std::string characterGUIDString); void AddToDisabledItems(std::set& workingDisabledItemIDs, uint32 disabledItemID); void AddDisabledItems(std::string disabledItemIdString); void AddPriceMinimumOverrides(std::string priceMinimimOverridesString); - ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; + //ObjectGuid::LowType GetAHBplayerGUID() { return AHBplayerGUID; }; + void LoadBotSessions(std::vector& outPlayerSessions); }; #define auctionbot AuctionHouseBot::instance()