mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 09:07:19 +00:00
add ability to add or remove character with same name as account (#1070)
* add ability to add or remove character with same name as account * seperate bot add and bot addacount so that characters with same name as an account doesn't add all toons from that account but adds the character instead if so desired
This commit is contained in:
@@ -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<std::string> 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<std::string> 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<std::string>();
|
||||
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<std::string>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user