Skip to content

Commit

Permalink
-Alwaysbot fix: The alwaysbot configs are now proper toggles where ei…
Browse files Browse the repository at this point in the history
…ther will toggle the selfbot behavior. The always command overrides all config settings.
  • Loading branch information
mostlikely4r committed Nov 6, 2024
1 parent 1792257 commit 0c439b1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 26 deletions.
28 changes: 18 additions & 10 deletions playerbot/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ bool PlayerbotAIConfig::Initialize()
LoadList<std::list<uint32> >(config.GetStringDefault("AiPlayerbot.RandomBotQuestIds", "7848,3802,5505,6502,7761,9378"), randomBotQuestIds);
LoadList<std::list<uint32> >(config.GetStringDefault("AiPlayerbot.ImmuneSpellIds", ""), immuneSpellIds);

botAutologin = config.GetIntDefault("AiPlayerbot.BotAutologin", false);
botAutologin = BotAutoLogin(config.GetIntDefault("AiPlayerbot.BotAutologin", 0));
randomBotAutologin = config.GetBoolDefault("AiPlayerbot.RandomBotAutologin", true);
minRandomBots = config.GetIntDefault("AiPlayerbot.MinRandomBots", 50);
maxRandomBots = config.GetIntDefault("AiPlayerbot.MaxRandomBots", 200);
Expand Down Expand Up @@ -602,7 +602,7 @@ bool PlayerbotAIConfig::Initialize()
}

sLog.outString("Loading free bots.");
selfBotLevel = config.GetIntDefault("AiPlayerbot.SelfBotLevel", 1);
selfBotLevel = BotSelfBotLevel(config.GetIntDefault("AiPlayerbot.SelfBotLevel", uint32(BotSelfBotLevel::GM_ONLY)));
LoadListString<std::list<std::string>>(config.GetStringDefault("AiPlayerbot.ToggleAlwaysOnlineAccounts", ""), toggleAlwaysOnlineAccounts);
LoadListString<std::list<std::string>>(config.GetStringDefault("AiPlayerbot.ToggleAlwaysOnlineChars", ""), toggleAlwaysOnlineChars);

Expand Down Expand Up @@ -753,7 +753,7 @@ void PlayerbotAIConfig::SetValue(std::string name, std::string value)

void PlayerbotAIConfig::loadFreeAltBotAccounts()
{
bool allCharsOnline = (selfBotLevel > 3);
bool allCharsOnline = (selfBotLevel == BotSelfBotLevel::ALWAYS_ACTIVE);

freeAltBots.clear();

Expand All @@ -762,37 +762,45 @@ void PlayerbotAIConfig::loadFreeAltBotAccounts()
{
do
{
bool accountAlwaysOnline = allCharsOnline;
bool accountToggle = false;

Field* fields = results->Fetch();
std::string accountName = fields[0].GetString();
uint32 accountId = fields[1].GetUInt32();

if (std::find(toggleAlwaysOnlineAccounts.begin(), toggleAlwaysOnlineAccounts.end(), accountName) != toggleAlwaysOnlineAccounts.end())
accountAlwaysOnline = !accountAlwaysOnline;
accountToggle = true;

auto result = CharacterDatabase.PQuery("SELECT name, guid FROM characters WHERE account = '%u'", accountId);
if (!result)
continue;

do
{
bool charAlwaysOnline = allCharsOnline;
bool charToggle = false;

Field* fields = result->Fetch();
std::string charName = fields[0].GetString();
uint32 guid = fields[1].GetUInt32();

uint32 always = sRandomPlayerbotMgr.GetValue(guid, "always");
BotAlwaysOnline always = BotAlwaysOnline(sRandomPlayerbotMgr.GetValue(guid, "always"));

if (always == 2)
if (always == BotAlwaysOnline::DISABLED_BY_COMMAND)
continue;

if (std::find(toggleAlwaysOnlineChars.begin(), toggleAlwaysOnlineChars.end(), charName) != toggleAlwaysOnlineChars.end())
charAlwaysOnline = !charAlwaysOnline;
charToggle = true;

if(charAlwaysOnline || accountAlwaysOnline || always)
bool thisCharAlwaysOnline = allCharsOnline;

if (accountToggle || charToggle)
thisCharAlwaysOnline = !thisCharAlwaysOnline;

if ((thisCharAlwaysOnline && always != BotAlwaysOnline::DISABLED_BY_COMMAND) || always == BotAlwaysOnline::ACTIVE)
{
sLog.outString("Enabling always online for %s", charName.c_str());
freeAltBots.push_back(std::make_pair(accountId, guid));
}

} while (result->NextRow());

Expand Down
27 changes: 25 additions & 2 deletions playerbot/PlayerbotAIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ enum class BotCheatMask : uint32
maxMask = 1 << 11
};

enum class BotAutoLogin : uint32
{
DISABLED = 0,
LOGIN_ALL_WITH_MASTER = 1,
LOGIN_ONLY_ALWAYS_ACTIVE = 2
};

enum class BotSelfBotLevel : uint32
{
DISABLED = 0,
GM_ONLY = 1,
ACTIVE_BY_COMMAND = 2,
ACTIVE_BY_LOGIN = 3,
ALWAYS_ACTIVE = 4
};

enum class BotAlwaysOnline : uint32
{
DISABLED = 0,
ACTIVE = 1,
DISABLED_BY_COMMAND = 2
};

#define MAX_GEAR_PROGRESSION_LEVEL 6

class ConfigAccess
Expand Down Expand Up @@ -71,7 +94,7 @@ class PlayerbotAIConfig

uint32 openGoSpell;
bool randomBotAutologin;
uint32 botAutologin;
BotAutoLogin botAutologin;
std::string randomBotMapsAsString;
std::vector<uint32> randomBotMaps;
std::list<uint32> randomBotQuestItems;
Expand Down Expand Up @@ -245,7 +268,7 @@ class PlayerbotAIConfig
bool talentsInPublicNote;
bool nonGmFreeSummon;

uint32 selfBotLevel;
BotSelfBotLevel selfBotLevel;
uint32 iterationsPerTick;

std::string autoPickReward;
Expand Down
49 changes: 36 additions & 13 deletions playerbot/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,17 +775,17 @@ std::list<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* args,

if (!strcmp(cmd, "always"))
{
if (sPlayerbotAIConfig.selfBotLevel == 0)
if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::DISABLED)
{
messages.push_back("Self-bot is disabled");
return messages;
}
else if (sPlayerbotAIConfig.selfBotLevel == 1 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::GM_ONLY && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
{
messages.push_back("You do not have permission to enable player ai");
return messages;
}
else if (sPlayerbotAIConfig.selfBotLevel == 2 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::ACTIVE_BY_COMMAND && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
{
messages.push_back("Player ai is only available while online");
return messages;
Expand Down Expand Up @@ -821,17 +821,36 @@ std::list<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* args,
alwaysName = charname;
}

uint32 always = sRandomPlayerbotMgr.GetValue(guid.GetCounter(), "always");
BotAlwaysOnline always = BotAlwaysOnline(sRandomPlayerbotMgr.GetValue(guid.GetCounter(), "always"));

if (!always || always == 2)
if (always == BotAlwaysOnline::DISABLED || always == BotAlwaysOnline::DISABLED_BY_COMMAND)
{
sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", 1);
sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", (uint32)BotAlwaysOnline::ACTIVE);
messages.push_back("Enable offline player ai for " + alwaysName);
sPlayerbotAIConfig.freeAltBots.push_back(std::make_pair(accountId, guid.GetCounter()));

if (!charname)
{
if (!master->GetPlayerbotAI())
OnBotLogin(master);
}
else
{
Player* bot = sRandomPlayerbotMgr.GetPlayerBot(guid);

if (bot)
{
ProcessBotCommand("add", guid,
master->GetObjectGuid(),
master->GetSession()->GetSecurity() >= SEC_GAMEMASTER,
master->GetSession()->GetAccountId(),
master->GetGuildId());
}
}
}
else
{
sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", 2);
sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", (uint32)BotAlwaysOnline::DISABLED_BY_COMMAND);
messages.push_back("Disable offline player ai for " + alwaysName);

if (guid != master->GetObjectGuid())
Expand Down Expand Up @@ -862,14 +881,14 @@ std::list<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* args,
if (sRandomPlayerbotMgr.GetValue(master->GetObjectGuid().GetCounter(), "selfbot"))
{
messages.push_back("Disable player ai (on login)");
sRandomPlayerbotMgr.SetValue(master->GetObjectGuid().GetCounter(), "selfbot", 0);
sRandomPlayerbotMgr.SetValue(master->GetObjectGuid().GetCounter(), "selfbot", (uint32)BotAlwaysOnline::DISABLED);
}
else
messages.push_back("Disable player ai");
}
else if (sPlayerbotAIConfig.selfBotLevel == 0)
else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::DISABLED)
messages.push_back("Self-bot is disabled");
else if (sPlayerbotAIConfig.selfBotLevel == 1 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::GM_ONLY && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
messages.push_back("You do not have permission to enable player ai");
else
{
Expand Down Expand Up @@ -1287,14 +1306,18 @@ void PlayerbotMgr::OnPlayerLogin(Player* player)
sPlayerbotTextMgr.AddLocalePriority(player->GetSession()->GetSessionDbLocaleIndex());
sLog.outBasic("Player %s logged in, localeDbc %i, localeDb %i", player->GetName(), (uint32)(player->GetSession()->GetSessionDbcLocale()), player->GetSession()->GetSessionDbLocaleIndex());

if(sPlayerbotAIConfig.selfBotLevel > 2 || sPlayerbotAIConfig.IsFreeAltBot(player) || sRandomPlayerbotMgr.GetValue(master->GetObjectGuid().GetCounter(), "selfbot"))
if (sPlayerbotAIConfig.IsFreeAltBot(player))
{
sLog.outString("Enabling selfbot on login for %s", player->GetName());
HandlePlayerbotCommand("self", player);
}

if (player->GetSession() != player->GetPlayerMenu()->GetGossipMenu().GetMenuSession())
{
player->GetPlayerMenu()->GetGossipMenu() = GossipMenu(player->GetSession());
}

if (!sPlayerbotAIConfig.botAutologin)
if (sPlayerbotAIConfig.botAutologin == BotAutoLogin::DISABLED)
return;

uint32 accountId = player->GetSession()->GetAccountId();
Expand All @@ -1309,7 +1332,7 @@ void PlayerbotMgr::OnPlayerLogin(Player* player)
{
Field* fields = results->Fetch();
if (first) first = false; else out << ",";
if(sPlayerbotAIConfig.botAutologin == 2 && !sPlayerbotAIConfig.IsFreeAltBot(fields[0].GetUInt32())) continue;
if(sPlayerbotAIConfig.botAutologin == BotAutoLogin::LOGIN_ONLY_ALWAYS_ACTIVE && !sPlayerbotAIConfig.IsFreeAltBot(fields[0].GetUInt32())) continue;
out << fields[1].GetString();
} while (results->NextRow());

Expand Down
2 changes: 1 addition & 1 deletion playerbot/RandomPlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void RandomPlayerbotMgr::ScaleBotActivity()
void RandomPlayerbotMgr::LoginFreeBots()
{

if (!sPlayerbotAIConfig.freeAltBots.empty() && sPlayerbotAIConfig.botAutologin != 2)
if (!sPlayerbotAIConfig.freeAltBots.empty() && sPlayerbotAIConfig.botAutologin != BotAutoLogin::LOGIN_ONLY_ALWAYS_ACTIVE)
{
for (auto bot : sPlayerbotAIConfig.freeAltBots)
{
Expand Down

0 comments on commit 0c439b1

Please sign in to comment.