From deb4f10ea8972b7287d1121b2979dbc3b3045e44 Mon Sep 17 00:00:00 2001 From: neckkola <65987027+neckkola@users.noreply.github.com> Date: Mon, 7 Feb 2022 21:35:53 -0400 Subject: [PATCH] Fixed IsRaidMemberBot to remove memory leak Fixed altcombat crash though RaidMainAssist (428) needs fixing --- zone/bot_raid.cpp | 4 ++++ zone/raids.cpp | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/zone/bot_raid.cpp b/zone/bot_raid.cpp index 0e0450a1e..38edc4ac8 100644 --- a/zone/bot_raid.cpp +++ b/zone/bot_raid.cpp @@ -428,6 +428,10 @@ void Bot::AI_Process_Raid() auto assist_mob = raid->GetRaidMainAssistOneByName(this->GetName()); bool find_target = true; + if (!assist_mob) { + bot_owner->Message(Chat::Yellow, "Assist Mob is nullptr"); + } + if (assist_mob) { if (assist_mob->GetTarget()) { diff --git a/zone/raids.cpp b/zone/raids.cpp index fbc1f5b68..daca6d2aa 100644 --- a/zone/raids.cpp +++ b/zone/raids.cpp @@ -1546,12 +1546,30 @@ void Raid::SendAllRaidLeadershipAA() bool Raid::IsRaidMemberBot(Client* client) { - if (client->CastToBot()->GetBotID() == 0) { - return false; + std::string query = StringFormat("SELECT mob_type FROM vw_bot_character_mobs WHERE name = '%s' LIMIT 1", + client->GetCleanName()); + auto results = database.QueryDatabase(query); + + if (!results.Success()) + return true; //return true to avoid sending a packet to a non-existant client as a failsafe + + if (results.RowCount() == 0) { + LogError( + "Error getting B/C info for character name [{}] for IsRaidMemberBot. Error [{}]", + client->GetCleanName(), + results.ErrorMessage().c_str() + ); + return true;//return true to avoid sending a packet to a non-existant client as a failsafe } - else - { - return true; + + auto row = results.begin(); + const char* c = "C"; + const char* b = "B"; + if (strcmp(row[0], c) == 0) { + return false; // client is a client + } + else if (strcmp(row[0], b) == 0) { + return true; // client is actually a bot } } void Raid::LockRaid(bool lockFlag) @@ -2036,9 +2054,10 @@ Mob* Raid::GetRaidMainAssistOneByName(const char* name) Raid* raid = entity_list.GetRaidByBotName(name); std::vector raid_members = raid->GetMembers(); - for (RaidMember& iter : raid_members) + for (RaidMember iter : raid_members) { if (iter.IsRaidMainAssistOne) return iter.member->CastToMob(); } + return nullptr; }