[Bug Fix] Check Rule "Bots Enabled" to prevent bot database calls on connect (#3154)

* [Bug Fix] Check for Rule "Bots Enabled" to prevent bot database calls if not enabled.

* formatting

* check if LoadBotsList failed, or is bots_list empty
This commit is contained in:
Aeadoin
2023-03-28 22:44:47 -04:00
committed by GitHub
parent e9c63c7d94
commit 7854130a93
3 changed files with 31 additions and 23 deletions
+28
View File
@@ -17,6 +17,8 @@
*/
#include "bot.h"
#include "bot_command.h"
#include "client.h"
#include "object.h"
#include "raids.h"
#include "doors.h"
@@ -296,4 +298,30 @@ void Bot::ProcessBotGroupAdd(Group* group, Raid* raid, Client* client, bool new_
raid->GroupUpdate(raid_free_group_id);
}
void Client::SpawnRaidBotsOnConnect(Raid* raid) {
std::list<BotsAvailableList> bots_list;
if (!database.botdb.LoadBotsList(CharacterID(), bots_list) || bots_list.empty()) {
return;
}
std::vector<RaidMember> r_members = raid->GetMembers();
for (const auto& m: r_members) {
if (strlen(m.member_name) != 0) {
for (const auto& b: bots_list) {
if (strcmp(m.member_name, b.Name) == 0) {
std::string buffer = "^spawn ";
buffer.append(m.member_name);
bot_command_real_dispatch(this, buffer.c_str());
auto bot = entity_list.GetBotByBotName(m.member_name);
if (bot) {
bot->SetRaidGrouped(true);
bot->p_raid_instance = raid;
}
}
}
}
}
}