bool ClientSession::checkMsgForCommand(std::string msg, WorldPacket & recv_data) { if (msg.c_str()[0] == '!' || msg.c_str()[0] == '.') { if (strContains(msg, ".mute", false) || strContains(msg, ".unmute", false)) { if (ChatHandler(this).ParseDotCommands(msg.c_str()) > 0) SendPacketToNode(&recv_data); } else if (strContains(msg, ".ticket", false)) ChatHandler(this).ParseDotCommands(msg.c_str()); else SendPacketToNode(&recv_data); return true; } return false; }
std::string rangeFromOverflow(const std::string &prefix, const std::string &done){ if (strContains(overflow, prefix)){ if (strEndsWith(overflow, prefix)) return prefix; v1.clear(); std::string tmp = overflow.substr(overflow.find(prefix) + prefix.length()); auto pos = tmp.find(done); if (pos != std::string::npos){ overflow = tmp.substr(pos); return prefix + tmp.substr(0,pos); } else return prefix + tmp; } return ""; }
std::string reallyRead(const std::string &prefix, const std::string &done) { std::string acc = rangeFromOverflow(prefix, done); std::stringstream racc; racc << acc; if (strContains(overflow,done)) return post_substr(acc,prefix); while (r.good()){ std::getline(r,acc); std::string::size_type split = acc.find(done); if (split != std::string::npos){ overflow = acc.substr(split); racc << acc.substr(0,split); std::string ret_w_prefix = racc.str(); return post_substr(ret_w_prefix,prefix); } else racc << acc; } throw call_cont<std::string> (post_substr(racc.str(),prefix)); }
void ClientSession::HandleMessagechatOpcode(WorldPacket & recv_data) { uint32 type; uint32 lang; recv_data >> type; recv_data >> lang; if (type >= MAX_CHAT_MSG_TYPE) { sLog->outError("CHAT: Wrong message type received: %u", type); recv_data.rfinish(); return; } Player* sender = GetPlayer(); // prevent talking at unknown language (cheating) LanguageDesc const* langDesc = GetLanguageDescByID(lang); if (!langDesc) { SendNotification(LANG_UNKNOWN_LANGUAGE); recv_data.rfinish(); return; } bool ignoreChecks = false; 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: ignoreChecks = true; break; default: sLog->outError("Player %s (GUID: %u) sent a chatmessage with an invalid language/message type combination", GetPlayer()->GetName(), GetPlayer()->GetGUIDLow()); recv_data.rfinish(); return; } } std::string to, channel, msg, temp; 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: recv_data >> msg; break; case CHAT_MSG_WHISPER: recv_data >> to; recv_data >> msg; break; case CHAT_MSG_CHANNEL: recv_data >> channel; recv_data >> msg; break; case CHAT_MSG_AFK: case CHAT_MSG_DND: recv_data >> msg; if (checkMsgForCommand(msg, recv_data) || checkMsgForMute(sender, recv_data)) return; ignoreChecks = true; break; } if (!ignoreChecks) { if (msg.empty()) return; if (checkMsgForCommand(msg, recv_data) || checkMsgForMute(sender, recv_data)) { if (!AccountMgr::IsVIPorPlayer(GetSecurity())) { /*if (Player* pPlayer = sender->GetSelectedPlayer()) sGMQualityManager->OnGMChat(CHAT_MSG_SYSTEM, sender, msg, pPlayer->GetName()); else*/ sGMQualityManager->OnGMChat(CHAT_MSG_SYSTEM, sender, msg); } return; } StripLineInvisibleChars(msg); } switch (type) { case CHAT_MSG_SAY: case CHAT_MSG_EMOTE: case CHAT_MSG_YELL: if (lang != LANG_ADDON) { if (!AccountMgr::IsVIPorPlayer(GetSecurity())) sGMQualityManager->OnGMChat(ChatMsg(type), sender, msg); else sGMQualityManager->OnPlayerChat(ChatMsg(type), sender, msg); } 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: { if (GetAntiSpamCounter() > LOGON_DOS_STRIKE_LIMIT || sLogon->CheckForSpam(msg)) { IncAntiSpamCounter(); SendFakeChatNotification(type, msg, lang); return; } SendPacketToNode(&recv_data); break; } case CHAT_MSG_WHISPER: { if (GetAntiSpamCounter() > LOGON_DOS_STRIKE_LIMIT || sLogon->CheckForSpam(msg)) { IncAntiSpamCounter(); SendFakeChatNotification(type, msg, lang); return; } if (sender->getLevel() < sLogon->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ)) { SendNotification(GetTrinityString(LANG_WHISPER_REQ), sLogon->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ)); return; } if (!normalizePlayerName(to)) { SendPlayerNotFoundNotice(to); return; } Player* receiver = sObjectMgr->FindPlayerByName(to.c_str()); bool senderIsPlayer = AccountMgr::IsPlayerAccount(GetSecurity()); bool receiverIsPlayer = AccountMgr::IsPlayerAccount(receiver ? receiver->GetSession()->GetSecurity() : SEC_PLAYER); if (!receiver || (senderIsPlayer && !receiverIsPlayer && !receiver->isAcceptWhispers() && !receiver->IsInWhisperWhiteList(sender->GetGUID()))) { SendPlayerNotFoundNotice(to); return; } if (!sLogon->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT) && senderIsPlayer && receiverIsPlayer) if (GetPlayer()->GetTeam() != receiver->GetTeam()) { SendWrongFactionNotice(); return; } if (!GetPlayer()->CanSpeak() && !receiver->isGameMaster()) { SendNotification(GetTrinityString(LANG_GM_SILENCE), GetPlayer()->GetName()); return; } // If player is a Gamemaster and doesn't accept whisper, we auto-whitelist every player that the Gamemaster is talking to if (!senderIsPlayer && !sender->isAcceptWhispers() && !sender->IsInWhisperWhiteList(receiver->GetGUID())) sender->AddWhisperWhiteList(receiver->GetGUID()); GetPlayer()->Whisper(msg, lang, receiver->GetGUID()); if (sLogon->getBoolConfig(CONFIG_CHATLOG_WHISPER)) sLog->outChat("[WHISPER] Player %s tells %s: %s", GetPlayer()->GetName(), receiver ? receiver->GetName() : "<unknown>", msg.c_str()); if (lang != LANG_ADDON) { if (!AccountMgr::IsVIPorPlayer(GetSecurity())) sGMQualityManager->OnGMChat(ChatMsg(type), sender, msg, to); else sGMQualityManager->OnPlayerChat(ChatMsg(type), sender, msg, to); } break; } case CHAT_MSG_CHANNEL: { if ((channel.compare("GLaDOS") == 0) || (channel.compare("GM") == 0)) { if (AccountMgr::IsVIPorPlayer(GetSecurity())) return; if (ChatHandler(this).ParseCommands(msg.c_str()) > 0) return; } else { if (GetPlayer() && GetPlayer()->getLevel() < 10) return; if (GetAntiSpamCounter() > LOGON_DOS_STRIKE_LIMIT || sLogon->CheckForSpam(msg)) { IncAntiSpamCounter(); SendFakeChannelNotification(channel, msg, lang); return; } if (sLogon->getBoolConfig(CONFIG_CHATLOG_CHANNEL)) sLog->outChat("[CHANNEL] Player %s tells Channel [%s]: %s", GetPlayer()->GetName(), channel.c_str(), msg.c_str()); if (strContains(channel, " - ", false) || strContains(channel, "SucheNachGruppe", false)) { SendPacketToNode(&recv_data); //Send if the Channel is not on our LogonServer return; } if (ChannelMgr* cMgr = channelMgr(_player->GetTeam())) { if (Channel* chn = cMgr->GetChannel(channel, _player)) chn->Say(_player->GetGUID(), msg.c_str(), lang); } } break; } case CHAT_MSG_AFK: { if ((msg.empty() || !_player->isAFK())) //&& !_player->isInCombat()) { if (!_player->isAFK()) { if (msg.empty()) msg = GetTrinityString(LANG_PLAYER_AFK_DEFAULT); _player->afkMsg = msg; } _player->ToggleAFK(); if (_player->isAFK() && _player->isDND()) _player->ToggleDND(); } break; } case CHAT_MSG_DND: { if (msg.empty() || !_player->isDND()) { if (!_player->isDND()) { if (msg.empty()) msg = GetTrinityString(LANG_PLAYER_DND_DEFAULT); _player->dndMsg = msg; } _player->ToggleDND(); if (_player->isDND() && _player->isAFK()) _player->ToggleAFK(); } break; } default: sLog->outError("CHAT: unknown message type %u, lang: %u", type, lang); break; } }