@@ -638,11 +638,22 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
638
638
bool isRandomAccount = sPlayerbotAIConfig ->IsInRandomAccountList (botAccount);
639
639
bool isMasterAccount = (masterAccountId == botAccount);
640
640
641
- if (cmd == " add" || cmd == " login" )
641
+ if (cmd == " add" || cmd == " addaccount " || cmd == " login" )
642
642
{
643
643
if (ObjectAccessor::FindPlayer (guid))
644
644
return " player already logged in" ;
645
645
646
+ // For addaccount command, verify it's an account name
647
+ if (cmd == " addaccount" )
648
+ {
649
+ uint32 accountId = sCharacterCache ->GetCharacterAccountIdByGuid (guid);
650
+ if (!accountId)
651
+ return " character not found" ;
652
+
653
+ if (!sPlayerbotAIConfig ->allowAccountBots && accountId != masterAccountId)
654
+ return " you can only add bots from your own account" ;
655
+ }
656
+
646
657
AddPlayerBot (guid, masterAccountId);
647
658
return " ok" ;
648
659
}
@@ -816,36 +827,19 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
816
827
817
828
if (!*args)
818
829
{
819
- messages.push_back (" usage: bot add character/account NAME or bot remove character/account NAME" );
820
- messages.push_back (" usage: bot addclass CLASSNAME" );
821
- messages.push_back (" usage: list/reload/tweak/self" );
830
+ messages.push_back (" usage: list/reload/tweak/self or add/addaccount/init/remove PLAYERNAME\n " );
831
+ messages.push_back (" usage: addclass CLASSNAME" );
822
832
return messages;
823
833
}
824
834
825
835
char * cmd = strtok ((char *)args, " " );
836
+ char * charname = strtok (nullptr , " " );
826
837
if (!cmd)
827
838
{
828
- messages.push_back (" usage: bot add character/account NAME or bot remove character/account NAME" );
829
- messages.push_back (" usage: bot addclass CLASSNAME" );
830
- messages.push_back (" usage: list/reload/tweak/self" );
839
+ messages.push_back (" usage: list/reload/tweak/self or add/init/remove PLAYERNAME or addclass CLASSNAME" );
831
840
return messages;
832
841
}
833
842
834
- // Handle the "bot" command prefix if it exists
835
- bool hasCommandPrefix = false ;
836
- if (!strcmp (cmd, " bot" ))
837
- {
838
- hasCommandPrefix = true ;
839
- cmd = strtok (nullptr , " " );
840
- if (!cmd)
841
- {
842
- messages.push_back (" usage: bot add character/account NAME or bot remove character/account NAME" );
843
- messages.push_back (" usage: bot addclass CLASSNAME" );
844
- messages.push_back (" usage: list/reload/tweak/self" );
845
- return messages;
846
- }
847
- }
848
-
849
843
if (!strcmp (cmd, " initself" ))
850
844
{
851
845
if (master->GetSession ()->GetSecurity () >= SEC_GAMEMASTER)
@@ -1006,10 +1000,8 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
1006
1000
return messages;
1007
1001
}
1008
1002
1009
- // Handle the addclass command to add random bots of specific class
1010
1003
if (!strcmp (cmd, " addclass" ))
1011
1004
{
1012
- char * charname = strtok (nullptr , " " );
1013
1005
if (sPlayerbotAIConfig ->addClassCommand == 0 && master->GetSession ()->GetSecurity () < SEC_GAMEMASTER)
1014
1006
{
1015
1007
messages.push_back (" You do not have permission to create bot by addclass command" );
@@ -1086,151 +1078,20 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
1086
1078
return messages;
1087
1079
}
1088
1080
1089
- // Handle new command format: "add character", "add account", "remove character", "remove account"
1090
- if (!strcmp (cmd, " add" ) || !strcmp (cmd, " remove" ))
1091
- {
1092
- bool isAdd = !strcmp (cmd, " add" );
1093
- std::string cmdStr = isAdd ? " add" : " remove" ;
1094
-
1095
- // Get the type (character or account) or wildcard
1096
- char * typeArg = strtok (nullptr , " " );
1097
- if (!typeArg)
1098
- {
1099
- messages.push_back (" usage: bot " + cmdStr + " character/account NAME or bot " + cmdStr + " *" );
1100
- return messages;
1101
- }
1102
-
1103
- // Handle wildcard removal
1104
- if (!strcmp (typeArg, " *" ) && !isAdd)
1105
- {
1106
- std::unordered_set<std::string> bots;
1107
- for (PlayerBotMap::const_iterator it = GetPlayerBotsBegin (); it != GetPlayerBotsEnd (); ++it)
1108
- {
1109
- if (Player* bot = it->second )
1110
- if (bot->IsInWorld ())
1111
- bots.insert (bot->GetName ());
1112
- }
1113
-
1114
- for (const auto & botName : bots)
1115
- {
1116
- ObjectGuid member = sCharacterCache ->GetCharacterGuidByName (botName);
1117
- if (member && master)
1118
- {
1119
- std::string result = ProcessBotCommand (cmdStr, member, master->GetGUID (),
1120
- master->GetSession ()->GetSecurity () >= SEC_GAMEMASTER,
1121
- master->GetSession ()->GetAccountId (), master->GetGuildId ());
1122
- messages.push_back (cmdStr + " : " + botName + " - " + result);
1123
- }
1124
- }
1125
- return messages;
1126
- }
1127
-
1128
- std::string typeStr = typeArg;
1129
- bool isAccount = false ;
1130
-
1131
- if (typeStr == " character" || typeStr == " char" )
1132
- {
1133
- isAccount = false ;
1134
- }
1135
- else if (typeStr == " account" || typeStr == " acc" )
1136
- {
1137
- isAccount = true ;
1138
- }
1139
- else
1140
- {
1141
- messages.push_back (" Invalid type. Use 'character' or 'account' or '*'" );
1142
- return messages;
1143
- }
1144
-
1145
- // Get the name
1146
- char * nameArg = strtok (nullptr , " " );
1147
- if (!nameArg)
1148
- {
1149
- messages.push_back (" usage: bot " + cmdStr + " " + typeStr + " NAME" );
1150
- return messages;
1151
- }
1152
-
1153
- std::string nameStr = nameArg;
1154
- std::unordered_set<std::string> bots;
1155
-
1156
- if (isAccount)
1157
- {
1158
- // Handle account level operation
1159
- uint32 accountId = GetAccountId (nameStr);
1160
- if (!accountId)
1161
- {
1162
- messages.push_back (" Account '" + nameStr + " ' not found." );
1163
- return messages;
1164
- }
1165
-
1166
- QueryResult results = CharacterDatabase.Query (" SELECT name FROM characters WHERE account = {}" , accountId);
1167
- if (results)
1168
- {
1169
- do
1170
- {
1171
- Field* fields = results->Fetch ();
1172
- std::string const charName = fields[0 ].Get <std::string>();
1173
- bots.insert (charName);
1174
- } while (results->NextRow ());
1175
- }
1176
- else
1177
- {
1178
- messages.push_back (" No characters found for account '" + nameStr + " '." );
1179
- return messages;
1180
- }
1181
- }
1182
- else
1183
- {
1184
- // Handle character level operation
1185
- bots.insert (nameStr);
1186
- }
1187
-
1188
- for (auto i = bots.begin (); i != bots.end (); ++i)
1189
- {
1190
- std::string const bot = *i;
1191
-
1192
- std::ostringstream out;
1193
- out << cmdStr << " : " << bot << " - " ;
1194
-
1195
- ObjectGuid member = sCharacterCache ->GetCharacterGuidByName (bot);
1196
- if (!member)
1197
- {
1198
- out << " character not found" ;
1199
- }
1200
- else if (master && member != master->GetGUID ())
1201
- {
1202
- out << ProcessBotCommand (cmdStr, member, master->GetGUID (),
1203
- master->GetSession ()->GetSecurity () >= SEC_GAMEMASTER,
1204
- master->GetSession ()->GetAccountId (), master->GetGuildId ());
1205
- }
1206
- else if (!master)
1207
- {
1208
- out << ProcessBotCommand (cmdStr, member, ObjectGuid::Empty, true , -1 , -1 );
1209
- }
1210
-
1211
- messages.push_back (out.str ());
1212
- }
1213
-
1214
- return messages;
1215
- }
1216
-
1217
- // Handle legacy command format for backward compatibility
1218
1081
std::string charnameStr;
1219
- char * charname = strtok (nullptr , " " );
1220
1082
1221
1083
if (!charname)
1222
1084
{
1223
1085
std::string name;
1224
1086
bool isPlayer = sCharacterCache ->GetCharacterNameByGuid (master->GetTarget (), name);
1087
+ // Player* tPlayer = ObjectAccessor::FindConnectedPlayer(master->GetTarget());
1225
1088
if (isPlayer)
1226
1089
{
1227
1090
charnameStr = name;
1228
1091
}
1229
1092
else
1230
1093
{
1231
- messages.push_back (" usage: bot add character/account NAME or bot remove character/account NAME" );
1232
- messages.push_back (" usage: bot addclass CLASSNAME" );
1233
- messages.push_back (" usage: list/reload/tweak/self" );
1094
+ messages.push_back (" usage: list/reload/tweak/self or add/init/remove PLAYERNAME" );
1234
1095
return messages;
1235
1096
}
1236
1097
}
@@ -1280,34 +1141,48 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
1280
1141
{
1281
1142
std::string const s = *i;
1282
1143
1283
- // If * is specified, add all bots to the set
1284
- if (s == " *" )
1144
+ if (!strcmp (cmd, " addaccount" ))
1285
1145
{
1286
- for (PlayerBotMap::const_iterator it = GetPlayerBotsBegin (); it != GetPlayerBotsEnd (); ++it)
1146
+ // When using addaccount, first try to get account ID directly
1147
+ uint32 accountId = GetAccountId (s);
1148
+ if (!accountId)
1287
1149
{
1288
- if (Player* bot = it->second )
1289
- if (bot->IsInWorld ())
1290
- bots.insert (bot->GetName ());
1150
+ // If not found, try to get account ID from character name
1151
+ ObjectGuid charGuid = sCharacterCache ->GetCharacterGuidByName (s);
1152
+ if (!charGuid)
1153
+ {
1154
+ messages.push_back (" Neither account nor character '" + s + " ' found" );
1155
+ continue ;
1156
+ }
1157
+ accountId = sCharacterCache ->GetCharacterAccountIdByGuid (charGuid);
1158
+ if (!accountId)
1159
+ {
1160
+ messages.push_back (" Could not find account for character '" + s + " '" );
1161
+ continue ;
1162
+ }
1291
1163
}
1292
- continue ;
1293
- }
1294
1164
1295
- uint32 accountId = GetAccountId (s);
1296
- if (!accountId)
1297
- {
1298
- bots.insert (s);
1299
- continue ;
1165
+ QueryResult results = CharacterDatabase.Query (" SELECT name FROM characters WHERE account = {}" , accountId);
1166
+ if (results)
1167
+ {
1168
+ do
1169
+ {
1170
+ Field* fields = results->Fetch ();
1171
+ std::string const charName = fields[0 ].Get <std::string>();
1172
+ bots.insert (charName);
1173
+ } while (results->NextRow ());
1174
+ }
1300
1175
}
1301
-
1302
- QueryResult results = CharacterDatabase.Query (" SELECT name FROM characters WHERE account = {}" , accountId);
1303
- if (results)
1176
+ else
1304
1177
{
1305
- do
1178
+ // For regular add command, only add the specific character
1179
+ ObjectGuid charGuid = sCharacterCache ->GetCharacterGuidByName (s);
1180
+ if (!charGuid)
1306
1181
{
1307
- Field* fields = results-> Fetch ( );
1308
- std::string const charName = fields[ 0 ]. Get <std::string>() ;
1309
- bots. insert (charName);
1310
- } while (results-> NextRow () );
1182
+ messages. push_back ( " Character ' " + s + " ' not found " );
1183
+ continue ;
1184
+ }
1185
+ bots. insert (s );
1311
1186
}
1312
1187
}
1313
1188
@@ -1326,8 +1201,8 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
1326
1201
else if (master && member != master->GetGUID ())
1327
1202
{
1328
1203
out << ProcessBotCommand (cmdStr, member, master->GetGUID (),
1329
- master->GetSession ()->GetSecurity () >= SEC_GAMEMASTER,
1330
- master->GetSession ()->GetAccountId (), master->GetGuildId ());
1204
+ master->GetSession ()->GetSecurity () >= SEC_GAMEMASTER,
1205
+ master->GetSession ()->GetAccountId (), master->GetGuildId ());
1331
1206
}
1332
1207
else if (!master)
1333
1208
{
0 commit comments