From 43b1e2f3e5d1002f110b818bf23b1fb1b0ecfab8 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Tue, 28 Jan 2014 18:14:52 +0100 Subject: [PATCH] FIRE-11815: Send newline flood antispam message only on initial block and only if source is not muted --- indra/newview/NACLantispam.cpp | 47 ++++++++ indra/newview/NACLantispam.h | 2 + indra/newview/llviewermessage.cpp | 107 +++++++++++------- .../skins/default/xui/en/notifications.xml | 16 +++ 4 files changed, 130 insertions(+), 42 deletions(-) diff --git a/indra/newview/NACLantispam.cpp b/indra/newview/NACLantispam.cpp index f445a8b536..0368a97b7f 100644 --- a/indra/newview/NACLantispam.cpp +++ b/indra/newview/NACLantispam.cpp @@ -88,6 +88,19 @@ U32 NACLAntiSpamQueue::getAmount() return mQueueAmount; } +NACLAntiSpamQueueEntry* NACLAntiSpamQueue::getEntry(const LLUUID& source) +{ + spam_queue_entry_map_t::iterator found = mEntries.find(source); + if (found != mEntries.end()) + { + return found->second; + } + else + { + return NULL; + } +} + void NACLAntiSpamQueue::clearEntries() { for (spam_queue_entry_map_t::iterator it = mEntries.begin(); it != mEntries.end(); ++it) @@ -388,6 +401,40 @@ bool NACLAntiSpamRegistry::checkQueue(EAntispamQueue queue, const LLUUID& source return false; } +bool NACLAntiSpamRegistry::isBlockedOnQueue(EAntispamQueue queue, const LLUUID& source) +{ + // skip all checks if we're we've been administratively turned off + static LLCachedControl useAntiSpam(gSavedSettings, "UseAntiSpam"); + if (!useAntiSpam) + { + return false; + } + + if (mGlobalQueue) + { + spam_queue_entry_map_t::iterator found = mGlobalEntries.find(source); + if (found != mGlobalEntries.end()) + { + return (found->second->getBlocked()); + } + else + { + return false; + } + } + else + { + if (queue >= ANTISPAM_QUEUE_MAX || mQueues[queue] == NULL) + { + LL_ERRS("AntiSpam") << "CODE BUG: Attempting to use a antispam queue that was not created or was outside of the reasonable range of queues. Queue: " << getQueueName(queue) << llendl; + return false; + } + + NACLAntiSpamQueueEntry* entry = mQueues[queue]->getEntry(source); + return (entry && entry->getBlocked()); + } +} + // Global queue void NACLAntiSpamRegistry::setGlobalQueue(bool value) { diff --git a/indra/newview/NACLantispam.h b/indra/newview/NACLantispam.h index 50b02899f9..4cb1474621 100644 --- a/indra/newview/NACLantispam.h +++ b/indra/newview/NACLantispam.h @@ -62,6 +62,7 @@ protected: void blockEntry(const LLUUID& source); S32 checkEntry(const LLUUID& source, U32 multiplier); + NACLAntiSpamQueueEntry* getEntry(const LLUUID& source); void clearEntries(); void purgeEntries(); @@ -87,6 +88,7 @@ public: void blockOnQueue(EAntispamQueue queue, const LLUUID& source); bool checkQueue(EAntispamQueue queue, const LLUUID& source, U32 multiplier = 1, bool silent = false); + bool isBlockedOnQueue(EAntispamQueue queue, const LLUUID& source); void clearRegisteredQueue(EAntispamQueue queue); void purgeRegisteredQueue(EAntispamQueue queue); diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 901090e35e..2234146b6f 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -2646,47 +2646,13 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) //msg->getData("MessageBlock", "Count", &count); msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_FromAgentName, name); msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_Message, message); - - // NaCl - Newline flood protection - static LLCachedControl useAntiSpam(gSavedSettings, "UseAntiSpam"); - if (useAntiSpam) - { - bool doCheck = true; - if (from_id.isNull() || gAgentID == from_id) - { - doCheck = false; - } - if (doCheck) - { - LLViewerObject* obj = gObjectList.findObject(from_id); - if (obj && obj->permYouOwner()) - { - doCheck = false; - } - } - if (doCheck) - { - static LLCachedControl _NACL_AntiSpamNewlines(gSavedSettings, "_NACL_AntiSpamNewlines"); - boost::sregex_iterator iter(message.begin(), message.end(), NEWLINES); - if ((std::abs(std::distance(iter, boost::sregex_iterator())) > _NACL_AntiSpamNewlines)) - { - NACLAntiSpamRegistry::instance().blockOnQueue(ANTISPAM_QUEUE_IM, from_id); - LLSD args; - llinfos << "[antispam] blocked owner due to too many newlines: " << from_id << llendl; - args["MESSAGE"] = llformat("AntiSpam: Blocked %s for sending message with %ud lines.", from_id.asString().c_str(), (U32)_NACL_AntiSpamNewlines); - LLNotificationsUtil::add("SystemMessageTip", args); - return; - } - } - } - // NaCl End - msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_ParentEstateID, parent_estate_id); msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_RegionID, region_id); msg->getVector3Fast(_PREHASH_MessageBlock, _PREHASH_Position, position); msg->getBinaryDataFast( _PREHASH_MessageBlock, _PREHASH_BinaryBucket, binary_bucket, 0, 0, MTUBYTES); binary_bucket_size = msg->getSizeFast(_PREHASH_MessageBlock, _PREHASH_BinaryBucket); EInstantMessage dialog = (EInstantMessage)d; + // NaCl - Antispam Registry if (dialog != IM_TYPING_START && dialog != IM_TYPING_STOP) { @@ -2729,6 +2695,52 @@ void process_improved_im(LLMessageSystem *msg, void **user_data) BOOL is_afk = gAgent.getAFK(); // + // NaCl - Newline flood protection + static LLCachedControl useAntiSpam(gSavedSettings, "UseAntiSpam"); + if (useAntiSpam) + { + bool doCheck = true; + if (from_id.isNull() || gAgentID == from_id) + { + doCheck = false; + } + if (doCheck) + { + LLViewerObject* obj = gObjectList.findObject(from_id); + if (obj && obj->permYouOwner()) + { + doCheck = false; + } + } + if (doCheck) + { + if (!NACLAntiSpamRegistry::instance().isBlockedOnQueue(ANTISPAM_QUEUE_IM, from_id)) + { + static LLCachedControl _NACL_AntiSpamNewlines(gSavedSettings, "_NACL_AntiSpamNewlines"); + boost::sregex_iterator iter(message.begin(), message.end(), NEWLINES); + if ((std::abs(std::distance(iter, boost::sregex_iterator())) > _NACL_AntiSpamNewlines)) + { + NACLAntiSpamRegistry::instance().blockOnQueue(ANTISPAM_QUEUE_IM, from_id); + if (!is_muted) + { + LLSD args; + LL_INFOS("AntiSpam") << "[antispam] blocked owner due to too many newlines: " << from_id << LL_ENDL; + args["SOURCE"] = from_id.asString(); + args["COUNT"] = llformat("%u", _NACL_AntiSpamNewlines()); + LLNotificationsUtil::add("AntiSpamImNewLineFloodBlocked", args); + } + return; + } + } + else + { + return; + } + } + } + // NaCl End + + chat.mMuted = is_muted; chat.mFromID = from_id; chat.mFromName = name; @@ -4346,14 +4358,25 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data) } if (doCheck) { - static LLCachedControl _NACL_AntiSpamNewlines(gSavedSettings, "_NACL_AntiSpamNewlines"); - boost::sregex_iterator iter(mesg.begin(), mesg.end(), NEWLINES); - if (std::abs(std::distance(iter, boost::sregex_iterator())) > _NACL_AntiSpamNewlines) + if (!NACLAntiSpamRegistry::instance().isBlockedOnQueue(ANTISPAM_QUEUE_CHAT, owner_id)) + { + static LLCachedControl _NACL_AntiSpamNewlines(gSavedSettings, "_NACL_AntiSpamNewlines"); + boost::sregex_iterator iter(mesg.begin(), mesg.end(), NEWLINES); + if (std::abs(std::distance(iter, boost::sregex_iterator())) > _NACL_AntiSpamNewlines) + { + NACLAntiSpamRegistry::instance().blockOnQueue(ANTISPAM_QUEUE_CHAT, owner_id); + if (!is_muted) + { + LLSD args; + args["SOURCE"] = owner_id.asString(); + args["COUNT"] = llformat("%u", _NACL_AntiSpamNewlines()); + LLNotificationsUtil::add("AntiSpamChatNewLineFloodBlocked", args); + } + return; + } + } + else { - NACLAntiSpamRegistry::instance().blockOnQueue(ANTISPAM_QUEUE_CHAT, owner_id); - LLSD args; - args["MESSAGE"] = "Chat: Blocked newline flood from "+owner_id.asString(); - LLNotificationsUtil::add("SystemMessageTip", args); return; } } diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml index f866c48969..701e9bd7f2 100755 --- a/indra/newview/skins/default/xui/en/notifications.xml +++ b/indra/newview/skins/default/xui/en/notifications.xml @@ -11557,6 +11557,22 @@ Export failed unexpectedly. Please see the log for details. AntiSpam: Blocked [SOURCE] for spamming a [QUEUE] ([COUNT]) times in [PERIOD] seconds. + +AntiSpam: Blocked [SOURCE] for sending an instant message with more than [COUNT] lines. + + + +AntiSpam: Blocked [SOURCE] for sending a chat message with more than [COUNT] lines. + +