bool ChatHandler::HandlePlayerbotCommand(char* args) { if (sWorld.getConfig(CONFIG_BOOL_PLAYERBOT_DISABLE)) { PSendSysMessage("|cffff0000Playerbot system is currently disabled!"); SetSentErrorMessage(true); return false; } if (!m_session) { PSendSysMessage("|cffff0000You may only add bots from an active session"); SetSentErrorMessage(true); return false; } if (!*args) { PSendSysMessage("|cffff0000usage: add PLAYERNAME or remove PLAYERNAME"); SetSentErrorMessage(true); return false; } char *cmd = strtok ((char *) args, " "); char *charname = strtok (NULL, " "); if (!cmd || !charname) { PSendSysMessage("|cffff0000usage: add PLAYERNAME or remove PLAYERNAME"); SetSentErrorMessage(true); return false; } std::string cmdStr = cmd; std::string charnameStr = charname; if (!normalizePlayerName(charnameStr)) return false; ObjectGuid guid = sAccountMgr.GetPlayerGuidByName(charnameStr.c_str()); if (guid == ObjectGuid() || (guid == m_session->GetPlayer()->GetObjectGuid())) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); return false; } uint32 accountId = sAccountMgr.GetPlayerAccountIdByGUID(guid); if (accountId != m_session->GetAccountId()) { if (!sWorld.getConfig(CONFIG_BOOL_PLAYERBOT_SHAREDBOTS)) { PSendSysMessage("|cffff0000You may only add bots from the same account."); SetSentErrorMessage(true); return false; } QueryResult *resultsocial = CharacterDatabase.PQuery("SELECT COUNT(*) FROM character_social s, characters c WHERE s.guid=c.guid AND c.online = 0 AND flags & 1 AND s.note " _LIKE_ " " _CONCAT3_ ("'%%'","'shared'","'%%'")" AND s.friend = '%u' AND s.guid = '%llu'", m_session->GetPlayer()->GetGUIDLow(), guid.GetRawValue()); if (resultsocial) { Field *fields = resultsocial->Fetch(); if (fields[0].GetUInt32() == 0 && (cmdStr == "add" || cmdStr == "login")) { PSendSysMessage("|cffff0000You may only add bots from the same account or a friend's character that contains 'shared' in the notes on their friend list while not online."); SetSentErrorMessage(true); delete resultsocial; return false; } } delete resultsocial; } // create the playerbot manager if it doesn't already exist PlayerbotMgr* mgr = m_session->GetPlayer()->GetPlayerbotMgr(); if (!mgr) { mgr = new PlayerbotMgr(m_session->GetPlayer()); m_session->GetPlayer()->SetPlayerbotMgr(mgr); } if (!(m_session->GetSecurity() > SEC_PLAYER)) { int maxnum = sWorld.getConfig(CONFIG_UINT32_PLAYERBOT_MAXBOTS); int charcount = m_session->GetPlayer()->GetPlayerbotMgr()->GetBotCount(); if (charcount >= maxnum && (cmdStr == "add" || cmdStr == "login")) { PSendSysMessage("|cffff0000You cannot summon anymore bots.(Current Max: |cffffffff%u)",maxnum); SetSentErrorMessage(true); return false; } } QueryResult *resultlvl = CharacterDatabase.PQuery("SELECT level, name, race FROM characters WHERE guid = '%u'", guid.GetCounter()); if (resultlvl) { Field *fields = resultlvl->Fetch(); int charlvl = fields[0].GetUInt32(); uint32 race = fields[2].GetUInt32(); Team master_team = m_session->GetPlayer()->GetTeam(); Team bot_team = HORDE; if (RACEMASK_ALLIANCE & (1 << (race-1))) bot_team = ALLIANCE; int maxlvl = sWorld.getConfig(CONFIG_UINT32_PLAYERBOT_RESTRICTLEVEL); int minlvl = sWorld.getConfig(CONFIG_UINT32_PLAYERBOT_MINBOTLEVEL); if (!(m_session->GetSecurity() > SEC_PLAYER)) { if (charlvl > maxlvl) { PSendSysMessage("|cffff0000You cannot summon |cffffffff[%s]|cffff0000, it's level is too high.(Current Max:lvl |cffffffff%u)", fields[1].GetString(), maxlvl); SetSentErrorMessage(true); delete resultlvl; return false; } if (charlvl < minlvl) { PSendSysMessage("|cffff0000You cannot summon |cffffffff[%s]|cffff0000, it's level is too low.(Current Min:lvl |cffffffff%u)", fields[1].GetString(), minlvl); SetSentErrorMessage(true); delete resultlvl; return false; } if (!sWorld.getConfig(CONFIG_BOOL_PLAYERBOT_ALLOW_SUMMON_OPPOSITE_FACTION) && bot_team != master_team) { PSendSysMessage("|cffff0000You cannot summon |cffffffff[%s]|cffff0000, it is from opposite faction.", fields[1].GetString()); SetSentErrorMessage(true); delete resultlvl; return false; } } delete resultlvl; } // end of gmconfig patch if (cmdStr == "add" || cmdStr == "login") { if (mgr->GetPlayerBot(guid) || sObjectMgr.GetPlayer(guid)) { PSendSysMessage("Bot already exists in world."); SetSentErrorMessage(true); return false; } CharacterDatabase.DirectPExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", guid.GetCounter()); mgr->AddPlayerBot(guid); PSendSysMessage("Bot added successfully."); ++mgr->m_botCount; } else if (cmdStr == "remove" || cmdStr == "logout") { if (!mgr->GetPlayerBot(guid)) { PSendSysMessage("|cffff0000Bot can not be removed because bot does not exist in world."); SetSentErrorMessage(true); return false; } CharacterDatabase.DirectPExecute("UPDATE characters SET online = 0 WHERE guid = '%u'", guid.GetCounter()); mgr->LogoutPlayerBot(guid); PSendSysMessage("Bot removed successfully."); --mgr->m_botCount; } else if (cmdStr == "co" || cmdStr == "combatorder") { Unit *target = NULL; char *orderChar = strtok(NULL, " "); if (!orderChar) { PSendSysMessage("|cffff0000Syntax error:|cffffffff .bot co <botName> <order=reset|tank|assist|heal|protect> [targetPlayer]"); SetSentErrorMessage(true); return false; } std::string orderStr = orderChar; if (orderStr == "protect" || orderStr == "assist") { char *targetChar = strtok(NULL, " "); ObjectGuid targetGuid = m_session->GetPlayer()->GetSelectionGuid(); if (!targetChar && targetGuid.IsEmpty()) { PSendSysMessage("|cffff0000Combat orders protect and assist expect a target either by selection or by giving target player in command string!"); SetSentErrorMessage(true); return false; } if (targetChar) { std::string targetStr = targetChar; ObjectGuid targ_guid = sAccountMgr.GetPlayerGuidByName(targetStr.c_str()); targetGuid.Set(targ_guid.GetRawValue()); } target = ObjectAccessor::GetUnit(*m_session->GetPlayer(), targetGuid); if (!target) { PSendSysMessage("|cffff0000Invalid target for combat order protect or assist!"); SetSentErrorMessage(true); return false; } } if (mgr->GetPlayerBot(guid) == NULL) { PSendSysMessage("|cffff0000Bot can not receive combat order because bot does not exist in world."); SetSentErrorMessage(true); return false; } mgr->GetPlayerBot(guid)->GetPlayerbotAI()->SetCombatOrderByStr(orderStr, target); } return true; }
bool ChatHandler::HandlePlayerbotCommand(const char* args) { if (! m_session) { PSendSysMessage("You may only add bots from an active session"); SetSentErrorMessage(true); return false; } if (!*args) { PSendSysMessage("usage: add PLAYERNAME or remove PLAYERNAME"); SetSentErrorMessage(true); return false; } char *cmd = strtok ((char*)args, " "); char *charname = strtok (NULL, " "); if (!cmd || !charname) { PSendSysMessage("usage: add PLAYERNAME or remove PLAYERNAME"); SetSentErrorMessage(true); return false; } std::string cmdStr = cmd; std::string charnameStr = charname; if(!normalizePlayerName(charnameStr)) return false; uint64 guid = objmgr.GetPlayerGUIDByName(charnameStr.c_str()); if (guid == 0 || (guid == m_session->GetPlayer()->GetGUID())) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); return false; } uint32 accountId = objmgr.GetPlayerAccountIdByGUID(guid); if (accountId != m_session->GetAccountId()) { PSendSysMessage("You may only add bots from the same account."); SetSentErrorMessage(true); return false; } // create the playerbot manager if it doesn't already exist PlayerbotMgr* mgr = m_session->GetPlayer()->GetPlayerbotMgr(); if (!mgr) { mgr = new PlayerbotMgr(m_session->GetPlayer()); m_session->GetPlayer()->SetPlayerbotMgr(mgr); } if (cmdStr == "add" || cmdStr == "login") { if (mgr->GetPlayerBot(guid)) { PSendSysMessage("Bot already exists in world."); SetSentErrorMessage(true); return false; } mgr->AddPlayerBot(guid); PSendSysMessage("Bot added successfully."); } else if (cmdStr == "remove" || cmdStr == "logout") { if (! mgr->GetPlayerBot(guid)) { PSendSysMessage("Bot can not be removed because bot does not exist in world."); SetSentErrorMessage(true); return false; } mgr->LogoutPlayerBot(guid); PSendSysMessage("Bot removed successfully."); } else if (cmdStr == "co" || cmdStr == "combatorder") { Unit *target = 0; char *orderChar = strtok( NULL, " " ); if( !orderChar ) { PSendSysMessage("Syntax error: .bot co <botName> <order=reset|tank|assist|heal|protect> [targetPlayer]"); SetSentErrorMessage(true); return false; } std::string orderStr = orderChar; if( orderStr == "protect" || orderStr == "assist" ) { char *targetChar = strtok( NULL, " " ); uint64 targetGUID = m_session->GetPlayer()->GetSelection(); if( !targetChar && !targetGUID ) { PSendSysMessage("Combat orders protect and assist expect a target either by selection or by giving target player in command string!"); SetSentErrorMessage(true); return false; } std::string targetStr = targetChar; if( targetChar ) { targetGUID = objmgr.GetPlayerGUIDByName( targetStr.c_str() ); } target = ObjectAccessor::GetUnit( *m_session->GetPlayer(), targetGUID ); if( !target ) { PSendSysMessage("Invalid target for combat order protect or assist!"); SetSentErrorMessage(true); return false; } } if (mgr->GetPlayerBot(guid) == NULL) { PSendSysMessage("Bot can not receive combat order because bot does not exist in world."); SetSentErrorMessage(true); return false; } mgr->GetPlayerBot( guid )->GetPlayerbotAI()->SetCombatOrderByStr( orderStr, target ); } return true; }
bool ChatHandler::HandlePlayerbotCommand(char* args) { if (sWorld.getConfig(CONFIG_BOOL_PLAYERBOT_DISABLE)) { PSendSysMessage("|cffff0000Playerbot system is currently disabled!"); SetSentErrorMessage(true); return false; } if (!m_session) { PSendSysMessage("|cffff0000You may only add bots from an active session"); SetSentErrorMessage(true); return false; } if (!*args) { PSendSysMessage("|cffff0000usage: add PLAYERNAME or remove PLAYERNAME"); SetSentErrorMessage(true); return false; } char *cmd = strtok ((char *) args, " "); char *charname = strtok (NULL, " "); if (!cmd || !charname) { PSendSysMessage("|cffff0000usage: add PLAYERNAME or remove PLAYERNAME"); SetSentErrorMessage(true); return false; } std::string cmdStr = cmd; std::string charnameStr = charname; if (!normalizePlayerName(charnameStr)) return false; ObjectGuid guid = sObjectMgr.GetPlayerGuidByName(charnameStr.c_str()); if (guid.IsEmpty() || (guid == m_session->GetPlayer()->GetObjectGuid())) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); return false; } uint32 accountId = sObjectMgr.GetPlayerAccountIdByGUID(guid); if (accountId != m_session->GetAccountId()) { PSendSysMessage("|cffff0000You may only add bots from the same account."); SetSentErrorMessage(true); return false; } // create the playerbot manager if it doesn't already exist PlayerbotMgr* mgr = m_session->GetPlayer()->GetPlayerbotMgr(); if (!mgr) { mgr = new PlayerbotMgr(m_session->GetPlayer()); m_session->GetPlayer()->SetPlayerbotMgr(mgr); } QueryResult *resultchar = CharacterDatabase.PQuery("SELECT COUNT(*) FROM characters WHERE online = '1' AND account = '%u'", accountId); if (resultchar) { Field *fields = resultchar->Fetch(); int acctcharcount = fields[0].GetUInt32(); int maxnum = sWorld.getConfig(CONFIG_UINT32_PLAYERBOT_MAXBOTS); if (!(m_session->GetSecurity() > SEC_PLAYER)) if (acctcharcount > maxnum && (cmdStr == "add" || cmdStr == "login")) { PSendSysMessage("|cffff0000You cannot summon anymore bots.(Current Max: |cffffffff%u)", maxnum); SetSentErrorMessage(true); delete resultchar; return false; } delete resultchar; } QueryResult *resultlvl = CharacterDatabase.PQuery("SELECT level,name FROM characters WHERE guid = '%u'", guid.GetCounter()); if (resultlvl) { Field *fields = resultlvl->Fetch(); int charlvl = fields[0].GetUInt32(); int maxlvl = sWorld.getConfig(CONFIG_UINT32_PLAYERBOT_RESTRICTLEVEL); if (!(m_session->GetSecurity() > SEC_PLAYER)) if (charlvl > maxlvl) { PSendSysMessage("|cffff0000You cannot summon |cffffffff[%s]|cffff0000, it's level is too high.(Current Max:lvl |cffffffff%u)", fields[1].GetString(), maxlvl); SetSentErrorMessage(true); delete resultlvl; return false; } delete resultlvl; } // end of gmconfig patch if (cmdStr == "add" || cmdStr == "login") { if (mgr->GetPlayerBot(guid)) { PSendSysMessage("Bot already exists in world."); SetSentErrorMessage(true); return false; } CharacterDatabase.DirectPExecute("UPDATE characters SET online = 1 WHERE guid = '%u'", guid.GetCounter()); mgr->AddPlayerBot(guid); PSendSysMessage("Bot added successfully."); } else if (cmdStr == "remove" || cmdStr == "logout") { if (!mgr->GetPlayerBot(guid)) { PSendSysMessage("|cffff0000Bot can not be removed because bot does not exist in world."); SetSentErrorMessage(true); return false; } CharacterDatabase.DirectPExecute("UPDATE characters SET online = 0 WHERE guid = '%u'", guid.GetCounter()); mgr->LogoutPlayerBot(guid); PSendSysMessage("Bot removed successfully."); } else if (cmdStr == "co" || cmdStr == "combatorder") { Unit *target = NULL; char *orderChar = strtok(NULL, " "); if (!orderChar) { PSendSysMessage("|cffff0000Syntax error:|cffffffff .bot co <botName> <order=reset|tank|assist|heal|protect> [targetPlayer]"); SetSentErrorMessage(true); return false; } std::string orderStr = orderChar; if (orderStr == "protect" || orderStr == "assist") { char *targetChar = strtok(NULL, " "); ObjectGuid targetGuid = m_session->GetPlayer()->GetSelectionGuid(); if (!targetChar && targetGuid.IsEmpty()) { PSendSysMessage("|cffff0000Combat orders protect and assist expect a target either by selection or by giving target player in command string!"); SetSentErrorMessage(true); return false; } if (targetChar) { std::string targetStr = targetChar; targetGuid = sObjectMgr.GetPlayerGuidByName(targetStr.c_str()); } target = ObjectAccessor::GetUnit(*m_session->GetPlayer(), targetGuid); if (!target) { PSendSysMessage("|cffff0000Invalid target for combat order protect or assist!"); SetSentErrorMessage(true); return false; } } if (mgr->GetPlayerBot(guid) == NULL) { PSendSysMessage("|cffff0000Bot can not receive combat order because bot does not exist in world."); SetSentErrorMessage(true); return false; } mgr->GetPlayerBot(guid)->GetPlayerbotAI()->SetCombatOrderByStr(orderStr, target); } return true; }