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.
static float g_RealPlayerWeight = 1.0f;
// Array for character social list friends
std::vector<int> SocialFriendsList;
// -----------------------------------------------------------------------------
// Loads the configuration from the config file.
// -----------------------------------------------------------------------------
@@ -106,6 +109,37 @@ static void LoadBotLevelBracketsConfig()
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.
// If the bot is out of range, it returns -1
static int GetLevelRangeIndex(uint8 level, uint8 teamID)
@@ -422,18 +456,22 @@ static bool IsBotSafeForLevelReset(Player* bot)
}
// Lets ignore bots that have human friends
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());
uint32 friendCount = 0;
friendCount = result->Fetch()->Get<uint32>();
if (friendCount >= 1)
{
for(auto i = 0; i < SocialFriendsList.size(); i++)
{
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.loading", "[BotLevelBrackets] Bot {} (Level {}) is on a Real Player's friends list", bot->GetName(), bot->GetLevel());
LOG_INFO("server.loading", "[BotLevelBrackets] Check bot {} against SocialFriendsList Array Character GUID {}", bot->GetName(), SocialFriendsList[i]);
}
if (SocialFriendsList[i] == bot->GetGUID().GetRawValue())
{
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.loading", "[BotLevelBrackets] Bot {} (Level {}) is on a Real Player's friends list", bot->GetName(), bot->GetLevel());
}
return false;
}
return false;
}
}
@@ -557,6 +595,7 @@ public:
void OnStartup() override
{
LoadBotLevelBracketsConfig();
LoadSocialFriendList();
if (!g_BotLevelBracketsEnabled)
{
LOG_INFO("server.loading", "[BotLevelBrackets] Module disabled via configuration.");
@@ -582,7 +621,7 @@ public:
{
if (!g_BotLevelBracketsEnabled)
return;
m_timer += diff;
m_flaggedTimer += diff;
@@ -592,7 +631,7 @@ public:
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.loading", "[BotLevelBrackets] Pending Level Resets Triggering.");
}
}
ProcessPendingLevelResets();
m_flaggedTimer = 0;
}
@@ -602,6 +641,9 @@ public:
return;
m_timer = 0;
// Refresh Social Friends List Array
LoadSocialFriendList();
// Dynamic distribution: recalc desired percentages based on non-bot players.
if (g_UseDynamicDistribution)
{