diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index a4faaea3..118a38ed 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -638,11 +638,22 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje bool isRandomAccount = sPlayerbotAIConfig->IsInRandomAccountList(botAccount); bool isMasterAccount = (masterAccountId == botAccount); - if (cmd == "add" || cmd == "login") + if (cmd == "add" || cmd == "addaccount" || cmd == "login") { if (ObjectAccessor::FindPlayer(guid)) return "player already logged in"; + // For addaccount command, verify it's an account name + if (cmd == "addaccount") + { + uint32 accountId = sCharacterCache->GetCharacterAccountIdByGuid(guid); + if (!accountId) + return "character not found"; + + if (!sPlayerbotAIConfig->allowAccountBots && accountId != masterAccountId) + return "you can only add bots from your own account"; + } + AddPlayerBot(guid, masterAccountId); return "ok"; } @@ -816,7 +827,7 @@ std::vector PlayerbotHolder::HandlePlayerbotCommand(char const* arg if (!*args) { - messages.push_back("usage: list/reload/tweak/self or add/init/remove PLAYERNAME\n"); + messages.push_back("usage: list/reload/tweak/self or add/addaccount/init/remove PLAYERNAME\n"); messages.push_back("usage: addclass CLASSNAME"); return messages; } @@ -1130,22 +1141,48 @@ std::vector PlayerbotHolder::HandlePlayerbotCommand(char const* arg { std::string const s = *i; - uint32 accountId = GetAccountId(s); - if (!accountId) + if (!strcmp(cmd, "addaccount")) { - bots.insert(s); - continue; - } - - QueryResult results = CharacterDatabase.Query("SELECT name FROM characters WHERE account = {}", accountId); - if (results) - { - do + // When using addaccount, first try to get account ID directly + uint32 accountId = GetAccountId(s); + if (!accountId) { - Field* fields = results->Fetch(); - std::string const charName = fields[0].Get(); - bots.insert(charName); - } while (results->NextRow()); + // If not found, try to get account ID from character name + ObjectGuid charGuid = sCharacterCache->GetCharacterGuidByName(s); + if (!charGuid) + { + messages.push_back("Neither account nor character '" + s + "' found"); + continue; + } + accountId = sCharacterCache->GetCharacterAccountIdByGuid(charGuid); + if (!accountId) + { + messages.push_back("Could not find account for character '" + s + "'"); + continue; + } + } + + QueryResult results = CharacterDatabase.Query("SELECT name FROM characters WHERE account = {}", accountId); + if (results) + { + do + { + Field* fields = results->Fetch(); + std::string const charName = fields[0].Get(); + bots.insert(charName); + } while (results->NextRow()); + } + } + else + { + // For regular add command, only add the specific character + ObjectGuid charGuid = sCharacterCache->GetCharacterGuidByName(s); + if (!charGuid) + { + messages.push_back("Character '" + s + "' not found"); + continue; + } + bots.insert(s); } }