char* G_SayCensor(char *msg) { char token2[1024]; char token[1024]; badwordsList_t *this; char* ret = msg; while(1){ msg = Plugin_ParseGetToken(msg); if(msg==NULL) break; int size = Plugin_ParseTokenLength(msg); Q_strncpyz(token,msg,size+1); removeColors(token2,token,sizeof(token2)); CharConv(token,token2,sizeof(token));// 'clear' token censor_ignoreMultiple(token2,token,sizeof(token2)); for(this = badwords ; this ; this = this->next){ if(this->exactmatch){ if(!Q_stricmp(token,this->word)){ memset(msg,'*',size); break; } }else{ if(strstr(token2,this->word)!=NULL){ memset(msg,'*',size); break; } } } } return ret; }
void Being::setSpeech(const std::string &text, int time) { // Remove colors mSpeech = removeColors(text); // Trim whitespace trim(mSpeech); // Check for links std::string::size_type start = mSpeech.find('['); std::string::size_type end = mSpeech.find(']', start); while (start != std::string::npos && end != std::string::npos) { // Catch multiple embeds and ignore them so it doesn't crash the client. while ((mSpeech.find('[', start + 1) != std::string::npos) && (mSpeech.find('[', start + 1) < end)) { start = mSpeech.find('[', start + 1); } std::string::size_type position = mSpeech.find('|'); if (mSpeech[start + 1] == '@' && mSpeech[start + 2] == '@') { mSpeech.erase(end, 1); mSpeech.erase(start, (position - start) + 1); } position = mSpeech.find('@'); while (position != std::string::npos) { mSpeech.erase(position, 2); position = mSpeech.find('@'); } start = mSpeech.find('[', start + 1); end = mSpeech.find(']', start); } if (!mSpeech.empty()) mSpeechTime = time <= SPEECH_MAX_TIME ? time : SPEECH_MAX_TIME; const int speech = config.getIntValue("speech"); if (speech == TEXT_OVERHEAD) { if (mText) delete mText; mText = new Text(mSpeech, getPixelX(), getSpeechTextYPosition(), gcn::Graphics::CENTER, &userPalette->getColor(UserPalette::PARTICLE), true); } }
QVector<triC> mutableSquareImageContainer::checkColorList() { if (colorListCheckNeeded_) { const grid gridImage(image_); const QVector<triC> colorsToRemove = ::findColors(gridImage, colors()); removeColors(colorsToRemove); colorListCheckNeeded_ = false; return colorsToRemove; } else { return QVector<triC>(); } }
void ChatTab::chatLog(const std::string &nick, std::string msg) { if (!localPlayer) return; const ChatMsgTypeT byWho = (nick == localPlayer->getName() ? ChatMsgType::BY_PLAYER : ChatMsgType::BY_OTHER); if (byWho == ChatMsgType::BY_OTHER && config.getBoolValue("removeColors")) msg = removeColors(msg); chatLog(std::string(nick).append(" : ").append(msg), byWho, IgnoreRecord_false, TryRemoveColors_false); }
void ChatTab::chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors) { // Trim whitespace trim(line); if (line.empty()) return; if (tryRemoveColors == TryRemoveColors_true && own == ChatMsgType::BY_OTHER && config.getBoolValue("removeColors")) { line = removeColors(line); if (line.empty()) return; } const unsigned lineLim = config.getIntValue("chatMaxCharLimit"); if (lineLim > 0 && line.length() > lineLim) line = line.substr(0, lineLim); if (line.empty()) return; CHATLOG tmp; tmp.own = own; tmp.nick.clear(); tmp.text = line; const size_t pos = line.find(" : "); if (pos != std::string::npos) { if (line.length() <= pos + 3) return; tmp.nick = line.substr(0, pos); tmp.text = line.substr(pos + 3); } else { // Fix the owner of welcome message. if (line.length() > 7 && line.substr(0, 7) == "Welcome") own = ChatMsgType::BY_SERVER; } // *implements actions in a backwards compatible way* if ((own == ChatMsgType::BY_PLAYER || own == ChatMsgType::BY_OTHER) && tmp.text.at(0) == '*' && tmp.text.at(tmp.text.length()-1) == '*') { tmp.text[0] = ' '; tmp.text.erase(tmp.text.length() - 1); own = ChatMsgType::ACT_IS; } std::string lineColor("##C"); switch (own) { case ChatMsgType::BY_GM: if (tmp.nick.empty()) { // TRANSLATORS: chat message tmp.nick = std::string(_("Global announcement:")).append(" "); lineColor = "##G"; } else { // TRANSLATORS: chat message tmp.nick = strprintf(_("Global announcement from %s:"), tmp.nick.c_str()).append(" "); lineColor = "##g"; // Equiv. to BrowserBox::RED } break; case ChatMsgType::BY_PLAYER: tmp.nick.append(": "); lineColor = "##Y"; break; case ChatMsgType::BY_OTHER: case ChatMsgType::BY_UNKNOWN: tmp.nick.append(": "); lineColor = "##C"; break; case ChatMsgType::BY_SERVER: // TRANSLATORS: chat message tmp.nick.clear(); tmp.text = line; lineColor = "##S"; break; case ChatMsgType::BY_CHANNEL: tmp.nick.clear(); lineColor = "##2"; // Equiv. to BrowserBox::GREEN break; case ChatMsgType::ACT_WHISPER: // TRANSLATORS: chat message tmp.nick = strprintf(_("%s whispers: %s"), tmp.nick.c_str(), ""); lineColor = "##W"; break; case ChatMsgType::ACT_IS: lineColor = "##I"; break; case ChatMsgType::BY_LOGGER: tmp.nick.clear(); tmp.text = line; lineColor = "##L"; break; default: break; } if (tmp.nick == ": ") { tmp.nick.clear(); lineColor = "##S"; } // if configured, move magic messages log to debug chat tab if (!serverFeatures->haveChatChannels() && localChatTab && this == localChatTab && ((config.getBoolValue("showMagicInDebug") && own == ChatMsgType::BY_PLAYER && tmp.text.length() > 1 && tmp.text.at(0) == '#' && tmp.text.at(1) != '#') || (config.getBoolValue("serverMsgInDebug") && (own == ChatMsgType::BY_SERVER || tmp.nick.empty())))) { if (debugChatTab) debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors); return; } // Get the current system time time_t t; time(&t); if (config.getBoolValue("useLocalTime")) { const tm *const timeInfo = localtime(&t); if (timeInfo) { line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(), timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(), tmp.text.c_str()); } else { line = strprintf("%s %s%s", lineColor.c_str(), tmp.nick.c_str(), tmp.text.c_str()); } } else { // Format the time string properly std::stringstream timeStr; timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "") << CAST_S32(((t / 60) / 60) % 24) << ":" << (((t / 60) % 60 < 10) ? "0" : "") << CAST_S32((t / 60) % 60) << "] "; line = std::string(lineColor).append(timeStr.str()).append( tmp.nick).append(tmp.text); } if (config.getBoolValue("enableChatLog")) saveToLogFile(line); mTextOutput->setMaxRow(config.getIntValue("chatMaxLinesLimit")); // We look if the Vertical Scroll Bar is set at the max before // adding a row, otherwise the max will always be a row higher // at comparison. if (mScrollArea->getVerticalScrollAmount() + 2 >= mScrollArea->getVerticalMaxScroll()) { addRow(line); mScrollArea->setVerticalScrollAmount( mScrollArea->getVerticalMaxScroll()); } else { addRow(line); } if (chatWindow && this == localChatTab) chatWindow->addToAwayLog(line); mScrollArea->logic(); if (own != ChatMsgType::BY_PLAYER) { if (own == ChatMsgType::BY_SERVER && (getType() == ChatTabType::PARTY || getType() == ChatTabType::CHANNEL || getType() == ChatTabType::GUILD)) { return; } const TabbedArea *const tabArea = getTabbedArea(); if (!tabArea) return; const bool notFocused = WindowManager::getIsMinimized() || (!settings.mouseFocused && !settings.inputFocused); if (this != tabArea->getSelectedTab() || notFocused) { if (getFlash() == 0) { if (chatWindow && chatWindow->findHighlight(tmp.text)) { setFlash(2); soundManager.playGuiSound(SOUND_HIGHLIGHT); } else { setFlash(1); } } else if (getFlash() == 2) { if (chatWindow && chatWindow->findHighlight(tmp.text)) soundManager.playGuiSound(SOUND_HIGHLIGHT); } } if ((getAllowHighlight() || own == ChatMsgType::BY_GM) && (this != tabArea->getSelectedTab() || notFocused)) { if (own == ChatMsgType::BY_GM) { if (chatWindow) chatWindow->unHideWindow(); soundManager.playGuiSound(SOUND_GLOBAL); } else if (own != ChatMsgType::BY_SERVER) { if (chatWindow) chatWindow->unHideWindow(); playNewMessageSound(); } WindowManager::newChatMessage(); } } }
void ChatHandler::handleMessage(MessageIn &msg) { Being *being; std::string chatMsg; std::string nick; int chatMsgLength; switch (msg.getId()) { case SMSG_WHISPER_RESPONSE: if (mSentWhispers.empty()) nick = "user"; else { nick = mSentWhispers.front(); mSentWhispers.pop(); } switch (msg.readInt8()) { case 0x00: // Success (don't need to report) break; case 0x01: { Event event(Event::WhisperError); event.setString("nick", nick); event.setString("error", strprintf(_("Whisper could " "not be sent, %s is offline."), nick.c_str())); event.trigger(Event::ChatChannel); } break; case 0x02: { Event event(Event::WhisperError); event.setString("nick", nick); event.setString("error", strprintf(_("Whisper could " "not be sent, ignored by %s."), nick.c_str())); event.Event::trigger(Event::ChatChannel); } break; } break; // Received whisper case SMSG_WHISPER: chatMsgLength = msg.readInt16() - 28; nick = msg.readString(24); if (chatMsgLength <= 0) break; chatMsg = msg.readString(chatMsgLength); // This is a sure sign of some special command, none of which are // supported at the moment. if (chatMsg.compare(0, 3, "\302\202!") == 0) return; if (nick != "Server") { // Ignore the shop commands since this client doesn't support // them at the moment. if (chatMsg.find("!selllist ") == 0 || chatMsg.find("!buylist ") == 0 || chatMsg.find("!buyitem ") == 0 || chatMsg.find("!sellitem ") == 0) return; if (player_relations.hasPermission(nick, PlayerRelation::WHISPER)) { Event event(Event::Whisper); event.setString("nick", nick); event.setString("message", chatMsg); event.trigger(Event::ChatChannel); } } else { SERVER_NOTICE(chatMsg) } break; // Received speech from being case SMSG_BEING_CHAT: { chatMsgLength = msg.readInt16() - 8; int beingId = msg.readInt32(); being = actorSpriteManager->findBeing(beingId); if (!being || chatMsgLength <= 0) break; chatMsg = msg.readString(chatMsgLength); std::string::size_type pos = chatMsg.find(" : ", 0); std::string sender_name = ((pos == std::string::npos) ? "" : chatMsg.substr(0, pos)); if (sender_name != being->getName() && being->getType() == Being::PLAYER) { if (!being->getName().empty()) sender_name = being->getName(); } else { chatMsg.erase(0, pos + 3); } int perms; if (being->getType() == Being::PLAYER) { perms = player_relations.checkPermissionSilently(sender_name, PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT); } else { perms = player_relations.getDefault() & (PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT); } trim(chatMsg); std::string reducedMessage = chatMsg; chatMsg = removeColors(sender_name) + " : " + reducedMessage; Event event(Event::Being); event.setString("message", chatMsg); event.setString("text", reducedMessage); event.setString("nick", sender_name); event.setInt("beingId", beingId); event.setInt("permissions", perms); event.trigger(Event::ChatChannel); break; } case SMSG_PLAYER_CHAT: case SMSG_GM_CHAT: { chatMsgLength = msg.readInt16() - 4; if (chatMsgLength <= 0) break; chatMsg = msg.readString(chatMsgLength); if (msg.getId() == SMSG_PLAYER_CHAT) { std::string::size_type pos = chatMsg.find(" : ", 0); std::string mes = chatMsg; if (pos != std::string::npos) chatMsg.erase(0, pos + 3); trim(chatMsg); Event event(Event::Player); event.setString("message", mes); event.setString("text", chatMsg); event.setString("nick", local_player->getName()); event.setInt("beingId", local_player->getId()); event.setInt("permissions", player_relations.getDefault() & (PlayerRelation::SPEECH_LOG | PlayerRelation::SPEECH_FLOAT)); event.trigger(Event::ChatChannel); } else { Event event(Event::Announcement); event.setString("message", chatMsg); event.trigger(Event::ChatChannel); } break; } case SMSG_MVP: // Display MVP player msg.readInt32(); // id SERVER_NOTICE(_("MVP player.")) break; } }