bool ChatHandler::HandlePlayerbotCommand(char* args) { if (!(m_session->GetSecurity() > SEC_PLAYER)) { if (botConfig.GetBoolDefault("PlayerbotAI.DisableBots", false)) { 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(nullptr, " "); 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 == ObjectGuid() || (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'", m_session->GetAccountId()); if (resultchar) { Field* fields = resultchar->Fetch(); int acctcharcount = fields[0].GetUInt32(); int maxnum = botConfig.GetIntDefault("PlayerbotAI.MaxNumBots", 9); 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, race FROM characters WHERE guid = '%u'", guid.GetCounter()); if (resultlvl) { Field* fields = resultlvl->Fetch(); int charlvl = fields[0].GetUInt32(); int maxlvl = botConfig.GetIntDefault("PlayerbotAI.RestrictBotLevel", 80); uint8 race = fields[2].GetUInt8(); uint32 team = 0; team = Player::TeamForRace(race); 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; } // Opposing team bot if (!sWorld.getConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_GROUP) && m_session->GetPlayer()->GetTeam() != team) { PSendSysMessage("|cffff0000You cannot summon |cffffffff[%s]|cffff0000, a member of the enemy side", fields[1].GetString()); 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->LoginPlayerBot(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."); } 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 (!(m_session->GetSecurity() > SEC_PLAYER)) if (botConfig.GetBoolDefault("PlayerbotAI.DisableBots", false)) { 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 (nullptr, " "); 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 == ObjectGuid() || (guid == m_session->GetPlayer()->GetObjectGuid())) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); return false; } // Removed this restriction to accomodate 40 man raids teams of bots in vanilla /*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'", m_session->GetAccountId()); if (resultchar) { Field *fields = resultchar->Fetch(); int acctcharcount = fields[0].GetUInt32(); int maxnum = botConfig.GetIntDefault("PlayerbotAI.MaxNumBots", 9); 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 = botConfig.GetIntDefault("PlayerbotAI.RestrictBotLevel", 60); 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()); // Modified to allow bot to originate from an account not on the masters account mgr->LoginPlayerBot(guid, mgr->GetMaster()->GetSession()->GetAccountId()); 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 = nullptr; char *orderChar = strtok(nullptr, " "); if (!orderChar) { PSendSysMessage("|cffff0000Syntax error:|cffffffff .bot co <botName> <order=reset|tank|assist|heal|protect> [targetPlayer]"); SetSentErrorMessage(true); return false; } 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 = 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(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; }
void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) { uint32 type; uint32 lang; recvData >> type; recvData >> lang; if (type >= MAX_CHAT_MSG_TYPE) { TC_LOG_ERROR("network", "CHAT: Wrong message type received: %u", type); recvData.rfinish(); return; } if (lang == LANG_UNIVERSAL && type != CHAT_MSG_AFK && type != CHAT_MSG_DND) { TC_LOG_ERROR("network", "CMSG_MESSAGECHAT: Possible hacking-attempt: %s tried to send a message in universal language", GetPlayerInfo().c_str()); SendNotification(LANG_UNKNOWN_LANGUAGE); recvData.rfinish(); return; } Player* sender = GetPlayer(); //TC_LOG_DEBUG("CHAT: packet received. type %u, lang %u", type, lang); // prevent talking at unknown language (cheating) LanguageDesc const* langDesc = GetLanguageDescByID(lang); if (!langDesc) { SendNotification(LANG_UNKNOWN_LANGUAGE); recvData.rfinish(); return; } if (langDesc->skill_id != 0 && !sender->HasSkill(langDesc->skill_id)) { // also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language) Unit::AuraEffectList const& langAuras = sender->GetAuraEffectsByType(SPELL_AURA_COMPREHEND_LANGUAGE); bool foundAura = false; for (Unit::AuraEffectList::const_iterator i = langAuras.begin(); i != langAuras.end(); ++i) { if ((*i)->GetMiscValue() == int32(lang)) { foundAura = true; break; } } if (!foundAura) { SendNotification(LANG_NOT_LEARNED_LANGUAGE); recvData.rfinish(); return; } } if (lang == LANG_ADDON) { // LANG_ADDON is only valid for the following message types switch (type) { case CHAT_MSG_PARTY: case CHAT_MSG_RAID: case CHAT_MSG_GUILD: case CHAT_MSG_BATTLEGROUND: case CHAT_MSG_WHISPER: // check if addon messages are disabled if (!sWorld->getBoolConfig(CONFIG_ADDON_CHANNEL)) { recvData.rfinish(); return; } break; default: TC_LOG_ERROR("network", "Player %s (GUID: %u) sent a chatmessage with an invalid language/message type combination", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().GetCounter()); recvData.rfinish(); return; } } // LANG_ADDON should not be changed nor be affected by flood control else { // send in universal language if player in .gmon mode (ignore spell effects) if (sender->IsGameMaster()) lang = LANG_UNIVERSAL; else { Unit::AuraEffectList const& ModLangAuras = sender->GetAuraEffectsByType(SPELL_AURA_MOD_LANGUAGE); if (!ModLangAuras.empty()) lang = ModLangAuras.front()->GetMiscValue(); else if (HasPermission(rbac::RBAC_PERM_TWO_SIDE_INTERACTION_CHAT)) lang = LANG_UNIVERSAL; else { switch (type) { case CHAT_MSG_PARTY: case CHAT_MSG_PARTY_LEADER: case CHAT_MSG_RAID: case CHAT_MSG_RAID_LEADER: case CHAT_MSG_RAID_WARNING: // allow two side chat at group channel if two side group allowed if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP)) lang = LANG_UNIVERSAL; break; case CHAT_MSG_GUILD: case CHAT_MSG_OFFICER: // allow two side chat at guild channel if two side guild allowed if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD)) lang = LANG_UNIVERSAL; break; } } } if (!sender->CanSpeak()) { std::string timeStr = secsToTimeString(m_muteTime - time(NULL)); SendNotification(GetTrinityString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str()); recvData.rfinish(); // Prevent warnings return; } if (type != CHAT_MSG_AFK && type != CHAT_MSG_DND) sender->UpdateSpeakTime(); } if (sender->HasAura(1852) && type != CHAT_MSG_WHISPER) { SendNotification(GetTrinityString(LANG_GM_SILENCE), sender->GetName().c_str()); recvData.rfinish(); return; } std::string to, channel, msg; bool ignoreChecks = false; switch (type) { case CHAT_MSG_SAY: case CHAT_MSG_EMOTE: case CHAT_MSG_YELL: case CHAT_MSG_PARTY: case CHAT_MSG_PARTY_LEADER: case CHAT_MSG_GUILD: case CHAT_MSG_OFFICER: case CHAT_MSG_RAID: case CHAT_MSG_RAID_LEADER: case CHAT_MSG_RAID_WARNING: case CHAT_MSG_BATTLEGROUND: case CHAT_MSG_BATTLEGROUND_LEADER: recvData >> msg; break; case CHAT_MSG_WHISPER: recvData >> to; recvData >> msg; break; case CHAT_MSG_CHANNEL: recvData >> channel; recvData >> msg; break; case CHAT_MSG_AFK: case CHAT_MSG_DND: recvData >> msg; ignoreChecks = true; break; } if (!ignoreChecks) { if (msg.empty()) return; if (ChatHandler(this).ParseCommands(msg.c_str())) return; if (lang != LANG_ADDON) { // Strip invisible characters for non-addon messages if (sWorld->getBoolConfig(CONFIG_CHAT_FAKE_MESSAGE_PREVENTING)) stripLineInvisibleChars(msg); if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY) && !ChatHandler(this).isValidChatMessage(msg.c_str())) { TC_LOG_ERROR("network", "Player %s (GUID: %u) sent a chatmessage with an invalid link: %s", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().GetCounter(), msg.c_str()); if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_KICK)) KickPlayer(); return; } } } switch (type) { case CHAT_MSG_SAY: case CHAT_MSG_EMOTE: case CHAT_MSG_YELL: { // Prevent cheating if (!sender->IsAlive()) return; if (sender->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ)) { SendNotification(GetTrinityString(LANG_SAY_REQ), sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ)); return; } if (type == CHAT_MSG_SAY) sender->Say(msg, Language(lang)); else if (type == CHAT_MSG_EMOTE) sender->TextEmote(msg); else if (type == CHAT_MSG_YELL) sender->Yell(msg, Language(lang)); } break; case CHAT_MSG_WHISPER: { if (!normalizePlayerName(to)) { SendPlayerNotFoundNotice(to); break; } Player* receiver = ObjectAccessor::FindConnectedPlayerByName(to); if (!receiver || (lang != LANG_ADDON && !receiver->isAcceptWhispers() && receiver->GetSession()->HasPermission(rbac::RBAC_PERM_CAN_FILTER_WHISPERS) && !receiver->IsInWhisperWhiteList(sender->GetGUID()))) { SendPlayerNotFoundNotice(to); return; } if (!sender->IsGameMaster() && sender->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ) && !receiver->IsInWhisperWhiteList(sender->GetGUID())) { SendNotification(GetTrinityString(LANG_WHISPER_REQ), sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ)); return; } if (GetPlayer()->GetTeam() != receiver->GetTeam() && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_INTERACTION_CHAT) && !receiver->IsInWhisperWhiteList(sender->GetGUID())) { SendWrongFactionNotice(); return; } if (GetPlayer()->HasAura(1852) && !receiver->IsGameMaster()) { SendNotification(GetTrinityString(LANG_GM_SILENCE), GetPlayer()->GetName().c_str()); return; } // If player is a Gamemaster and doesn't accept whisper, we auto-whitelist every player that the Gamemaster is talking to // We also do that if a player is under the required level for whispers. if (receiver->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ) || (HasPermission(rbac::RBAC_PERM_CAN_FILTER_WHISPERS) && !sender->isAcceptWhispers() && !sender->IsInWhisperWhiteList(receiver->GetGUID()))) sender->AddWhisperWhiteList(receiver->GetGUID()); // Playerbot mod: handle whispered command to bot if (receiver->GetPlayerbotAI() && lang != LANG_ADDON) { receiver->GetPlayerbotAI()->HandleCommand(type, msg, *GetPlayer()); receiver->m_speakTime = 0; receiver->m_speakCount = 0; } else { GetPlayer()->Whisper(msg, Language(lang), receiver); } // END Playerbot mod } break; case CHAT_MSG_PARTY: case CHAT_MSG_PARTY_LEADER: { // if player is in battleground, he cannot say to battleground members by /p Group* group = GetPlayer()->GetOriginalGroup(); if (!group) { group = sender->GetGroup(); if (!group || group->isBGGroup()) return; } if (type == CHAT_MSG_PARTY_LEADER && !group->IsLeader(sender->GetGUID())) return; // Playerbot mod: broadcast message to bot members for(GroupReference* itr = group->GetFirstMember(); itr != NULL; itr=itr->next()) { Player* player = itr->GetSource(); if (player && player->GetPlayerbotAI() && lang != LANG_ADDON) { player->GetPlayerbotAI()->HandleCommand(type, msg, *GetPlayer()); GetPlayer()->m_speakTime = 0; GetPlayer()->m_speakCount = 0; } } // END Playerbot mod sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group); WorldPacket data; ChatHandler::BuildChatPacket(data, ChatMsg(type), Language(lang), sender, NULL, msg); group->BroadcastPacket(&data, false, group->GetMemberGroup(GetPlayer()->GetGUID())); } break; case CHAT_MSG_GUILD: { if (GetPlayer()->GetGuildId()) { if (Guild* guild = sGuildMgr->GetGuildById(GetPlayer()->GetGuildId())) { sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, guild); guild->BroadcastToGuild(this, false, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL); } // Playerbot mod: broadcast message to bot members PlayerbotMgr *mgr = GetPlayer()->GetPlayerbotMgr(); if (mgr && lang != LANG_ADDON) { for (PlayerBotMap::const_iterator it = mgr->GetPlayerBotsBegin(); it != mgr->GetPlayerBotsEnd(); ++it) { Player* const bot = it->second; if (bot->GetGuildId() == GetPlayer()->GetGuildId()) bot->GetPlayerbotAI()->HandleCommand(type, msg, *GetPlayer()); } } // END Playerbot mod } } break; case CHAT_MSG_OFFICER: { if (GetPlayer()->GetGuildId()) { if (Guild* guild = sGuildMgr->GetGuildById(GetPlayer()->GetGuildId())) { sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, guild); guild->BroadcastToGuild(this, true, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL); } } } break; case CHAT_MSG_RAID: { // if player is in battleground, he cannot say to battleground members by /ra Group* group = GetPlayer()->GetOriginalGroup(); if (!group) { group = GetPlayer()->GetGroup(); if (!group || group->isBGGroup() || !group->isRaidGroup()) return; } // Playerbot mod: broadcast message to bot members for(GroupReference* itr = group->GetFirstMember(); itr != NULL; itr=itr->next()) { Player* player = itr->GetSource(); if (player && player->GetPlayerbotAI() && lang != LANG_ADDON) { player->GetPlayerbotAI()->HandleCommand(type, msg, *GetPlayer()); GetPlayer()->m_speakTime = 0; GetPlayer()->m_speakCount = 0; } } // END Playerbot mod sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group); WorldPacket data; ChatHandler::BuildChatPacket(data, CHAT_MSG_RAID, Language(lang), sender, NULL, msg); group->BroadcastPacket(&data, false); } break; case CHAT_MSG_RAID_LEADER: { // if player is in battleground, he cannot say to battleground members by /ra Group* group = GetPlayer()->GetOriginalGroup(); if (!group) { group = GetPlayer()->GetGroup(); if (!group || group->isBGGroup() || !group->isRaidGroup() || !group->IsLeader(sender->GetGUID())) return; } // Playerbot mod: broadcast message to bot members for(GroupReference* itr = group->GetFirstMember(); itr != NULL; itr=itr->next()) { Player* player = itr->GetSource(); if (player && player->GetPlayerbotAI() && lang != LANG_ADDON) { player->GetPlayerbotAI()->HandleCommand(type, msg, *GetPlayer()); GetPlayer()->m_speakTime = 0; GetPlayer()->m_speakCount = 0; } } // END Playerbot mod sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group); WorldPacket data; ChatHandler::BuildChatPacket(data, CHAT_MSG_RAID_LEADER, Language(lang), sender, NULL, msg); group->BroadcastPacket(&data, false); } break; case CHAT_MSG_RAID_WARNING: { Group* group = GetPlayer()->GetGroup(); if (!group || !group->isRaidGroup() || !(group->IsLeader(GetPlayer()->GetGUID()) || group->IsAssistant(GetPlayer()->GetGUID())) || group->isBGGroup()) return; // Playerbot mod: broadcast message to bot members for(GroupReference* itr = group->GetFirstMember(); itr != NULL; itr=itr->next()) { Player* player = itr->GetSource(); if (player && player->GetPlayerbotAI() && lang != LANG_ADDON) { player->GetPlayerbotAI()->HandleCommand(type, msg, *GetPlayer()); GetPlayer()->m_speakTime = 0; GetPlayer()->m_speakCount = 0; } } // END Playerbot mod sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group); WorldPacket data; //in battleground, raid warning is sent only to players in battleground - code is ok ChatHandler::BuildChatPacket(data, CHAT_MSG_RAID_WARNING, Language(lang), sender, NULL, msg); group->BroadcastPacket(&data, false); } break; case CHAT_MSG_BATTLEGROUND: { //battleground raid is always in Player->GetGroup(), never in GetOriginalGroup() Group* group = GetPlayer()->GetGroup(); if (!group || !group->isBGGroup()) return; sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group); WorldPacket data; ChatHandler::BuildChatPacket(data, CHAT_MSG_BATTLEGROUND, Language(lang), sender, NULL, msg); group->BroadcastPacket(&data, false); } break; case CHAT_MSG_BATTLEGROUND_LEADER: { // battleground raid is always in Player->GetGroup(), never in GetOriginalGroup() Group* group = GetPlayer()->GetGroup(); if (!group || !group->isBGGroup() || !group->IsLeader(GetPlayer()->GetGUID())) return; sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, group); WorldPacket data; ChatHandler::BuildChatPacket(data, CHAT_MSG_BATTLEGROUND_LEADER, Language(lang), sender, NULL, msg);; group->BroadcastPacket(&data, false); } break; case CHAT_MSG_CHANNEL: { if (!HasPermission(rbac::RBAC_PERM_SKIP_CHECK_CHAT_CHANNEL_REQ)) { if (sender->getLevel() < sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ)) { SendNotification(GetTrinityString(LANG_CHANNEL_REQ), sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ)); return; } } if (ChannelMgr* cMgr = ChannelMgr::forTeam(sender->GetTeam())) { if (Channel* chn = cMgr->GetChannel(channel, sender)) { // Playerbot mod: broadcast message to bot members if (_player->GetPlayerbotMgr() && lang != LANG_ADDON && chn->GetFlags() & 0x18) { _player->GetPlayerbotMgr()->HandleCommand(type, msg); } sRandomPlayerbotMgr.HandleCommand(type, msg, *_player); // END Playerbot mod sScriptMgr->OnPlayerChat(sender, type, lang, msg, chn); chn->Say(sender->GetGUID(), msg.c_str(), lang); } } } break; case CHAT_MSG_AFK: { if (!sender->IsInCombat()) { if (sender->isAFK()) // Already AFK { if (msg.empty()) sender->ToggleAFK(); // Remove AFK else sender->autoReplyMsg = msg; // Update message } else // New AFK mode { sender->autoReplyMsg = msg.empty() ? GetTrinityString(LANG_PLAYER_AFK_DEFAULT) : msg; if (sender->isDND()) sender->ToggleDND(); sender->ToggleAFK(); } sScriptMgr->OnPlayerChat(sender, type, lang, msg); } break; } case CHAT_MSG_DND: { if (sender->isDND()) // Already DND { if (msg.empty()) sender->ToggleDND(); // Remove DND else sender->autoReplyMsg = msg; // Update message } else // New DND mode { sender->autoReplyMsg = msg.empty() ? GetTrinityString(LANG_PLAYER_DND_DEFAULT) : msg; if (sender->isAFK()) sender->ToggleAFK(); sender->ToggleDND(); } sScriptMgr->OnPlayerChat(sender, type, lang, msg); break; } default: TC_LOG_ERROR("network", "CHAT: unknown message type %u, lang: %u", type, lang); break; } }