Started multi-account support (no compile)

This commit is contained in:
NathanHandley
2025-03-09 12:15:35 -05:00
parent fced1798f6
commit 17c3956bac
3 changed files with 126 additions and 28 deletions

View File

@@ -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
###############################################################################

View File

@@ -728,11 +728,35 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
}
}
void AuctionHouseBot::LoadBotSessions(std::vector<Player>& 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<uint32> 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<bool>("AuctionHouseBot.EnableSeller", false);
AHBBuyer = sConfigMgr->GetOption<bool>("AuctionHouseBot.EnableBuyer", false);
AHBplayerAccount = sConfigMgr->GetOption<uint32>("AuctionHouseBot.Account", 0);
AHBplayerGUID = sConfigMgr->GetOption<uint32>("AuctionHouseBot.GUID", 0);
ItemsPerCycle = sConfigMgr->GetOption<uint32>("AuctionHouseBot.ItemsPerCycle", 200);
AddCharacters(sConfigMgr->GetOption<std::string>("AuctionHouseBot.GUIDs", 0));
if (AHCharacters.size() == 0)
AddCharacters(sConfigMgr->GetOption<std::string>("AuctionHouseBot.GUID", 0)); // Backwards compat
ItemsPerCycle = sConfigMgr->GetOption<uint32>("AuctionHouseBot.ItemsPerCycle", 75);
BotsPerCycle = sConfigMgr->GetOption<uint32>("AuctionHouseBot.BotsPerCycle", 1);
// Stack Ratios
RandomStackRatioConsumable = GetRandomStackValue("AuctionHouseBot.RandomStackRatio.Consumable", 20);
@@ -876,16 +902,6 @@ void AuctionHouseBot::InitializeConfiguration()
AddDisabledItems(sConfigMgr->GetOption<std::string>("AuctionHouseBot.DisabledItemIDs", ""));
AddDisabledItems(sConfigMgr->GetOption<std::string>("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<uint32>("AuctionHouseBot.Alliance.MinItems", 15000));
@@ -928,6 +944,65 @@ void AuctionHouseBot::AddToDisabledItems(std::set<uint32>& workingDisabledItemID
}
}
void AuctionHouseBot::AddCharacters(std::string characterGUIDString)
{
std::string delimitedValue;
std::stringstream characterGUIDStream;
std::set<uint32> 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>();
uint32 account = fields[1].Get<uint32>();
AuctionHouseBotCharacter curChar = AuctionHouseBotCharacter(account, guid);
AHCharacters.push_back(curChar);
} while (queryResult->NextRow());
}
void AuctionHouseBot::AddDisabledItems(std::string disabledItemIdString)
{
std::string delimitedValue;

View File

@@ -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<AuctionHouseBotCharacter> AHCharacters;
std::string AHCharactersGUIDsForQuery;
uint32 ItemsPerCycle;
uint32 BotsPerCycle;
bool DisabledItemTextFilter;
std::set<uint32> 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<uint32>& 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<Player>& outPlayerSessions);
};
#define auctionbot AuctionHouseBot::instance()