Updated Ignore Friend Listed Bot code to access database less

Changed to load all friend guid's from character_socials into an array and check bots against that
This commit is contained in:
jimm0thy
2025-03-03 21:06:21 -05:00
parent dcea8b2828
commit eda05a45b4

View File

@@ -60,6 +60,9 @@ static bool g_IgnoreFriendListed = true;
// Real player weight to boost bracket contributions. // Real player weight to boost bracket contributions.
static float g_RealPlayerWeight = 1.0f; static float g_RealPlayerWeight = 1.0f;
// Array for character social list friends
std::vector<int> SocialFriendsList;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Loads the configuration from the config file. // Loads the configuration from the config file.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -106,6 +109,37 @@ static void LoadBotLevelBracketsConfig()
ClampAndBalanceBrackets(); ClampAndBalanceBrackets();
} }
// -----------------------------------------------------------------------------
// Loads the friend guid(s) from character_social into array
// -----------------------------------------------------------------------------
static void LoadSocialFriendList()
{
SocialFriendsList.clear();
QueryResult result = CharacterDatabase.Query("SELECT friend FROM character_social WHERE flags = 1");
if (!result)
return;
if (result->GetRowCount() == 0)
return;
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.loading", "[BotLevelBrackets] Fetching Social Friend List GUIDs into array");
}
do
{
uint32 socialFriendGUID = result->Fetch()->Get<uint32>();
SocialFriendsList.push_back(socialFriendGUID);
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.load", "[BotLevelBrackets] Adding GUID {} to Social Friend List", socialFriendGUID);
}
} while (result->NextRow());
}
// Returns the index of the level range bracket that the given level belongs to. // Returns the index of the level range bracket that the given level belongs to.
// If the bot is out of range, it returns -1 // If the bot is out of range, it returns -1
static int GetLevelRangeIndex(uint8 level, uint8 teamID) static int GetLevelRangeIndex(uint8 level, uint8 teamID)
@@ -423,11 +457,14 @@ static bool IsBotSafeForLevelReset(Player* bot)
// Lets ignore bots that have human friends // Lets ignore bots that have human friends
if (g_IgnoreFriendListed) if (g_IgnoreFriendListed)
{ {
QueryResult result = CharacterDatabase.Query("SELECT COUNT(friend) FROM character_social WHERE friend IN (SELECT guid FROM characters WHERE name ='{}') and flags = 1", bot->GetName()); for(auto i = 0; i < SocialFriendsList.size(); i++)
uint32 friendCount = 0; {
friendCount = result->Fetch()->Get<uint32>(); if (g_BotDistFullDebugMode)
{
LOG_INFO("server.loading", "[BotLevelBrackets] Check bot {} against SocialFriendsList Array Character GUID {}", bot->GetName(), SocialFriendsList[i]);
}
if (friendCount >= 1) if (SocialFriendsList[i] == bot->GetGUID().GetRawValue())
{ {
if (g_BotDistFullDebugMode) if (g_BotDistFullDebugMode)
{ {
@@ -436,6 +473,7 @@ static bool IsBotSafeForLevelReset(Player* bot)
return false; return false;
} }
} }
}
return true; return true;
} }
@@ -557,6 +595,7 @@ public:
void OnStartup() override void OnStartup() override
{ {
LoadBotLevelBracketsConfig(); LoadBotLevelBracketsConfig();
LoadSocialFriendList();
if (!g_BotLevelBracketsEnabled) if (!g_BotLevelBracketsEnabled)
{ {
LOG_INFO("server.loading", "[BotLevelBrackets] Module disabled via configuration."); LOG_INFO("server.loading", "[BotLevelBrackets] Module disabled via configuration.");
@@ -602,6 +641,9 @@ public:
return; return;
m_timer = 0; m_timer = 0;
// Refresh Social Friends List Array
LoadSocialFriendList();
// Dynamic distribution: recalc desired percentages based on non-bot players. // Dynamic distribution: recalc desired percentages based on non-bot players.
if (g_UseDynamicDistribution) if (g_UseDynamicDistribution)
{ {