Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions zone/bot_raid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

#include "bot.h"
#include "bot_command.h"
#include "client.h"
#include "object.h"
#include "raids.h"
#include "doors.h"
Expand Down Expand Up @@ -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) {
Aeadoin marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
}
}
}
}

2 changes: 1 addition & 1 deletion zone/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,7 @@ class Client : public Mob
void SetBotSpawnLimit(int new_spawn_limit, uint8 class_id = NO_CLASS);

void CampAllBots(uint8 class_id = NO_CLASS);
void SpawnRaidBotsOnConnect(Raid* raid);

private:
bool bot_owner_options[_booCount];
Expand All @@ -2042,7 +2043,6 @@ class Client : public Mob
bool CanTradeFVNoDropItem();
void SendMobPositions();
void PlayerTradeEventLog(Trade *t, Trade *t2);

};

#endif
24 changes: 2 additions & 22 deletions zone/client_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,28 +607,8 @@ void Client::CompleteConnect()
if (raid) {
SetRaidGrouped(true);
raid->LearnMembers();
std::list<BotsAvailableList> bots_list;
database.botdb.LoadBotsList(this->CharacterID(), bots_list);
std::vector<RaidMember> r_members = raid->GetMembers();
for (const RaidMember& iter : r_members) {
if (iter.member_name) {
for (const BotsAvailableList& b_iter : bots_list)
{
if (strcmp(iter.member_name, b_iter.Name) == 0)
{
char buffer[71] = "^spawn ";
strcat(buffer, iter.member_name);
bot_command_real_dispatch(this, buffer);
Bot* b = entity_list.GetBotByBotName(iter.member_name);
if (b)
{
b->SetRaidGrouped(true);
b->p_raid_instance = raid;
//b->SetFollowID(this->GetID());
}
}
}
}
if (RuleB(Bots, Enabled)) {
SpawnRaidBotsOnConnect(raid);
}
raid->VerifyRaid();
raid->GetRaidDetails();
Expand Down