Merge commit 'c7bdaf66329b018159c834d75fcc3d807b188ccb'

This commit is contained in:
Siana Gearz
2012-07-23 05:10:56 +02:00
13 changed files with 834 additions and 225 deletions

View File

@@ -178,6 +178,13 @@
#include "llwindebug.h" // For the invalid message handler
#endif
// NaCl - Antispam Registry
#include "NACLantispam.h"
// NaCl - Newline flood protection
#include <boost/regex.hpp>
static const boost::regex NEWLINES("\\n{1}");
// NaCl End
// [RLVa:KB] - Checked: 2009-07-08 (RLVa-1.0.0e)
#include "llfloateravatarinfo.h"
extern LLMap< const LLUUID, LLFloaterAvatarInfo* > gAvatarInfoInstances; // Only defined in llfloateravatarinfo.cpp
@@ -238,75 +245,6 @@ const BOOL SCRIPT_QUESTION_IS_CAUTION[SCRIPT_PERMISSION_EOF] =
FALSE // ControlYourCamera
};
template <typename T>
class SH_SpamHandler
{
public:
SH_SpamHandler(const char *pToggleCtrl, const char *pDurCtrl, const char *pFreqCtrl) :
mDuration(pDurCtrl, 1.f),
mFrequency(pFreqCtrl, 5),
mEnabled(false)
{
gSavedSettings.getControl(pToggleCtrl)->getSignal()->connect(boost::bind(&SH_SpamHandler::CtrlToggle, this, _2));
CtrlToggle(gSavedSettings.getBOOL(pToggleCtrl));
}
bool CtrlToggle(const LLSD& newvalue)
{
bool on = newvalue.asBoolean();
if(on == mEnabled)
return true;
mEnabled = on;
mTimer.stop();
mActiveList.clear();
mBlockedList.clear();
return true;
}
bool isBlocked(const T &owner, const LLUUID &source_id, const char *pNotification, LLSD args=LLSD())
{
if(!mEnabled || isAgent(owner))
return false;
if(mBlockedList.find(owner) != mBlockedList.end())
return true;
if(mTimer.getStarted() && mTimer.getElapsedTimeF32() < mDuration)
{
typename std::map<const T,U32>::iterator it = mActiveList.insert(std::pair<const T, U32>(owner,0)).first;
if(++(it->second)>=mFrequency)
{
mBlockedList.insert(owner);
if(pNotification)
{
args["OWNER"] = owner;
args["SOURCE"] = source_id;
LLNotifications::getInstance()->add(pNotification,args);
}
return true;
}
}
else
{
mActiveList.clear();
mTimer.start();
}
return false;
}
private:
//Owner is either a key, or a name. Do not look up perms since object may be unknown.
static bool isAgent(const T &owner);
bool mEnabled;
LLFrameTimer mTimer;
const LLCachedControl<F32> mDuration;
const LLCachedControl<U32> mFrequency;
std::map<const T,U32> mActiveList;
std::set<T> mBlockedList;
};
template<> bool SH_SpamHandler<LLUUID>::isAgent(const LLUUID &owner) { return gAgent.getID() == owner; }
template<> bool SH_SpamHandler<std::string>::isAgent(const std::string &owner)
{
std::string str;
gAgent.getName(str);
return str == owner;
}
bool friendship_offer_callback(const LLSD& notification, const LLSD& response)
{
S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
@@ -1704,7 +1642,12 @@ void inventory_offer_handler(LLOfferInfo* info, BOOL from_task)
info->forceResponse(IOR_BUSY);
return;
}
// NaCl - Antispam Registry
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
if(antispam || NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_INVENTORY,info->mFromID))
return;
// NaCl End
//If muted, don't even go through the messaging stuff. Just curtail the offer here.
if (LLMuteList::getInstance()->isMuted(info->mFromID, info->mFromName))
{
@@ -1958,6 +1901,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
{
return;
}
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
LLUUID from_id;
BOOL from_group;
LLUUID to_id;
@@ -1986,6 +1930,24 @@ 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
LLViewerObject* obj=gObjectList.findObject(from_id);
if(!from_id.isNull() //Not from nothing.
&& gAgent.getID() != from_id //Not from self.
&& !(obj && obj->permYouOwner())) //Not from own object.
{
static LLCachedControl<U32> SpamNewlines(gSavedSettings,"_NACL_AntiSpamNewlines");
boost::sregex_iterator iter(message.begin(), message.end(), NEWLINES);
if(std::abs(std::distance(iter, boost::sregex_iterator())) > SpamNewlines)
{
NACLAntiSpamRegistry::blockOnQueue((U32)NACLAntiSpamRegistry::QUEUE_IM,from_id);
LLSD args;
args["MESSAGE"] = "Message: Blocked newline flood from "+from_id.asString();
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);
@@ -1993,6 +1955,12 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
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)
&& NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_IM,from_id))
return;
// NaCl End
// make sure that we don't have an empty or all-whitespace name
LLStringUtil::trim(name);
if (name.empty())
@@ -2022,15 +1990,6 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
{
LLSD args;
args["NAME"] = name;
static SH_SpamHandler<LLUUID> avatar_spam_check("SGBlockGeneralSpam","SGSpamTime","SGSpamCount");
static SH_SpamHandler<LLUUID> object_spam_check("SGBlockGeneralSpam","SGSpamTime","SGSpamCount");
if(d==IM_FROM_TASK||d==IM_GOTO_URL||d==IM_FROM_TASK_AS_ALERT||d==IM_TASK_INVENTORY_OFFERED||d==IM_TASK_INVENTORY_ACCEPTED||d==IM_TASK_INVENTORY_DECLINED)
{
if(object_spam_check.isBlocked(from_id,session_id,"BlockedGeneralObjects",args))
return;
}
else if(avatar_spam_check.isBlocked(from_id,from_id,"BlockedGeneralAvatar",args))
return;
}
LLViewerObject *source = gObjectList.findObject(session_id); //Session ID is probably the wrong thing.
@@ -2464,6 +2423,10 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
case IM_GROUP_NOTICE:
case IM_GROUP_NOTICE_REQUESTED:
{
// NaCl - Antispam
if(antispam)
return;
// NaCl End
LL_INFOS("Messaging") << "Received IM_GROUP_NOTICE message." << LL_ENDL;
// Read the binary bucket for more information.
struct notice_bucket_header_t
@@ -2559,6 +2522,10 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
break;
case IM_GROUP_INVITATION:
{
// NaCl - Antispam
if(antispam)
return;
// NaCl End
//if (!is_linden && (is_busy || is_muted))
if ((is_busy || is_muted))
{
@@ -2603,6 +2570,10 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
case IM_TASK_INVENTORY_OFFERED:
// Someone has offered us some inventory.
{
// NaCl - Antispam
if(antispam)
return;
// NaCl End
LLOfferInfo* info = new LLOfferInfo;
if (IM_INVENTORY_OFFERED == dialog)
@@ -2855,6 +2826,10 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
}
break;
case IM_FROM_TASK_AS_ALERT:
// NaCl - Antispam
if(antispam)
return;
// NaCl End
if (is_busy && !is_owned_by_me)
{
return;
@@ -2892,6 +2867,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
case IM_LURE_USER:
{
if(antispam) return; //NaCl Antispam
// [RLVa:KB] - Checked: 2010-12-11 (RLVa-1.2.2c) | Added: RLVa-1.2.2c
// If the lure sender is a specific @accepttp exception they will override muted and busy status
bool fRlvSummon = (rlv_handler_t::isEnabled()) && (gRlvHandler.isException(RLV_BHVR_ACCEPTTP, from_id));
@@ -3032,6 +3008,10 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
case IM_GOTO_URL:
{
// NaCl - Antispam
if(antispam)
return;
// NaCl End
LLSD args;
// n.b. this is for URLs sent by the system, not for
// URLs sent by scripts (i.e. llLoadURL)
@@ -3056,6 +3036,10 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
case IM_FRIENDSHIP_OFFERED:
{
// NaCl - Antispam
if(antispam)
return;
// NaCl End
LLSD payload;
payload["from_id"] = from_id;
payload["session_id"] = session_id;;
@@ -3190,11 +3174,22 @@ static LLNotificationFunctorRegistration callingcard_offer_cb_reg("OfferCallingC
void process_offer_callingcard(LLMessageSystem* msg, void**)
{
// NaCl - Antispam
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
if(antispam)
return;
// NaCl End
// someone has offered to form a friendship
LL_DEBUGS("Messaging") << "callingcard offer" << LL_ENDL;
LLUUID source_id;
msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, source_id);
// NaCl - Antispam Registry
if(NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_CALLING_CARD,source_id))
return;
// NaCl End
LLUUID tid;
msg->getUUIDFast(_PREHASH_AgentBlock, _PREHASH_TransactionID, tid);
@@ -3227,9 +3222,6 @@ void process_offer_callingcard(LLMessageSystem* msg, void**)
}
else
{
static SH_SpamHandler<LLUUID> spam_check("SGBlockCardSpam","SHSpamTime","SGSpamCount");
if(spam_check.isBlocked(source_id,source_id,"BlockedCards",args))
return;
LLNotificationsUtil::add("OfferCallingCard", args, payload);
}
}
@@ -3384,6 +3376,14 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
msg->getU8("ChatData", "ChatType", type_temp);
chat.mChatType = (EChatType)type_temp;
// NaCL - Antispam Registry
if((chat.mChatType != CHAT_TYPE_START && chat.mChatType != CHAT_TYPE_STOP) //Chat type isn't typing
&&((owner_id.isNull() && NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_CHAT,from_id)) //Spam from an object?
||(NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_CHAT,owner_id)))) //Spam from a resident?
return;
// NaCl End
msg->getU8Fast(_PREHASH_ChatData, _PREHASH_Audible, audible_temp);
chat.mAudible = (EChatAudible)audible_temp;
@@ -3431,12 +3431,6 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
{
LLSD args;
args["NAME"] = from_name;
static SH_SpamHandler<LLUUID> avatar_spam_check("SGBlockChatSpam","SGChatSpamTime","SGChatSpamCount");
static SH_SpamHandler<LLUUID> object_spam_check("SGBlockChatSpam","SGChatSpamTime","SGChatSpamCount");
if( (chatter->isAvatar() && avatar_spam_check.isBlocked(from_id,from_id,"BlockedChatterAvatar",args)) ||
(!chatter->isAvatar() && object_spam_check.isBlocked(owner_id,from_id,"BlockedChatterObjects",args)) )
return;
chat.mPosAgent = chatter->getPositionAgent();
// Make swirly things only for talking objects. (not script debug messages, though)
@@ -3508,6 +3502,25 @@ void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
if (is_audible)
{
msg->getStringFast(_PREHASH_ChatData, _PREHASH_Message, mesg);
// NaCl - Newline flood protection
LLViewerObject* obj=gObjectList.findObject(from_id);
if(!(from_id.isNull()) //Not from nothing.
|| !(gAgent.getID() != from_id) //Not from self.
|| !(obj && obj->permYouOwner())) //Not from own object.
{
static LLCachedControl<U32> SpamNewlines(gSavedSettings,"_NACL_AntiSpamNewlines");
boost::sregex_iterator iter(mesg.begin(), mesg.end(), NEWLINES);
if(std::abs(std::distance(iter, boost::sregex_iterator())) > SpamNewlines)
{
NACLAntiSpamRegistry::blockOnQueue((U32)NACLAntiSpamRegistry::QUEUE_CHAT,owner_id);
LLSD args;
args["MESSAGE"] = "Chat: Blocked newline flood from "+owner_id.asString();
LLNotificationsUtil::add("SystemMessageTip", args);
return;
}
}
// NaCl End
static std::map<LLUUID, bool> sChatObjectAuth;
@@ -4832,6 +4845,23 @@ void process_sound_trigger(LLMessageSystem *msg, void **)
msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_SoundID, sound_id);
msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_OwnerID, owner_id);
msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ObjectID, object_id);
// NaCl - Antispam Registry
/*if(owner_id.isNull())
{*/
bool bDoSpamCheck=1;
std::string sSound=sound_id.asString();
static LLCachedControl<U32> _NACL_AntiSpamSoundMulti(gSavedSettings,"_NACL_AntiSpamSoundMulti");
for(int i=0;i< COLLISION_SOUNDS_SIZE;i++)
if(COLLISION_SOUNDS[i] == sSound)
bDoSpamCheck=0;
if(bDoSpamCheck)
if(NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SOUND,object_id, _NACL_AntiSpamSoundMulti,true)) return;
/*}
else
if(NACLAntiSpamRegistry::checkQueue("Soundspam",owner_id)) return;*/
// NaCl End
msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ParentID, parent_id);
msg->getU64Fast(_PREHASH_SoundData, _PREHASH_Handle, region_handle);
msg->getVector3Fast(_PREHASH_SoundData, _PREHASH_Position, pos_local);
@@ -4895,6 +4925,14 @@ void process_preload_sound(LLMessageSystem *msg, void **user_data)
msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
// NaCl - Antispam Registry
static LLCachedControl<U32> _NACL_AntiSpamSoundPreloadMulti(gSavedSettings,"_NACL_AntiSpamSoundPreloadMulti");
if((owner_id.isNull()
&& NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SOUND_PRELOAD,object_id,_NACL_AntiSpamSoundPreloadMulti))
|| NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SOUND_PRELOAD,owner_id,_NACL_AntiSpamSoundPreloadMulti))
return;
// NaCl End
LLViewerObject *objectp = gObjectList.findObject(object_id);
if (!objectp) return;
@@ -4930,6 +4968,14 @@ void process_attached_sound(LLMessageSystem *msg, void **user_data)
msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
// NaCl - Antispam Registry
if(/*owner_id.isNull()
&&*/ NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SOUND,object_id))
/*|| (NACLAntiSpamRegistry::checkQueue("Soundspam",owner_id))*/
return;
// NaCl End
msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
msg->getU8Fast(_PREHASH_DataBlock, _PREHASH_Flags, flags);
@@ -6022,6 +6068,10 @@ void process_economy_data(LLMessageSystem *msg, void** /*user_data*/)
void notify_cautioned_script_question(const LLSD& notification, const LLSD& response, S32 orig_questions, BOOL granted)
{
// NaCl - Antispam Registry
LLUUID task_id = notification["payload"]["task_id"].asUUID();
if(NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,task_id)) return;
// NaCl End
// only continue if at least some permissions were requested
if (orig_questions)
{
@@ -6188,7 +6238,12 @@ static LLNotificationFunctorRegistration script_question_cb_reg_2("ScriptQuestio
void process_script_question(LLMessageSystem *msg, void **user_data)
{
// *TODO:translate owner name -> [FIRST] [LAST]
// NaCl - Antispam
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
if(antispam)
return;
// NaCl End
// *TODO: Translate owner name -> [FIRST] [LAST]
LLHost sender = msg->getSender();
@@ -6202,6 +6257,14 @@ void process_script_question(LLMessageSystem *msg, void **user_data)
msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid );
// itemid -> script asset key of script requesting permissions
msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid );
// NaCl - Antispam Registry
if((taskid.isNull()
&& NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,itemid))
|| NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,taskid))
return;
// NaCl End
msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, owner_name);
msg->getS32Fast(_PREHASH_Data, _PREHASH_Questions, questions );
@@ -6860,17 +6923,33 @@ static LLNotificationFunctorRegistration callback_script_dialog_reg_2("ScriptDia
void process_script_dialog(LLMessageSystem* msg, void**)
{
// NaCl - Antispam
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
if(antispam)
return;
// NaCl End
S32 i;
LLSD payload;
LLUUID object_id;
msg->getUUID("Data", "ObjectID", object_id);
// For compability with OS grids first check for presence of extended packet before fetching data.
// NaCl - Antispam Registry
if(NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,object_id))
return;
// NaCl End
// For compability with OS grids first check for presence of extended packet before fetching data.
LLUUID owner_id;
if (gMessageSystem->getNumberOfBlocks("OwnerData") > 0)
{
msg->getUUID("OwnerData", "OwnerID", owner_id);
// NaCl - Antispam Registry
if(NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,owner_id))
return;
// NaCl End
}
if (LLMuteList::getInstance()->isMuted(object_id) || LLMuteList::getInstance()->isMuted(owner_id))
@@ -6943,10 +7022,6 @@ void process_script_dialog(LLMessageSystem* msg, void**)
{
args["NAME"] = LLCacheName::buildFullName(first_name, last_name);
static SH_SpamHandler<std::string> spam_check("SGBlockDialogSpam","SGSpamTime","SGSpamCount");
if(spam_check.isBlocked(first_name + " " + last_name,object_id,"BlockedDialogs",args))
return;
if (is_text_box)
{
args["DEFAULT"] = default_text;
@@ -7030,6 +7105,11 @@ void callback_load_url_name(const LLUUID& id, const std::string& full_name, bool
void process_load_url(LLMessageSystem* msg, void**)
{
// NaCl - Antispam
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
if(antispam)
return;
// NaCl End
LLUUID object_id;
LLUUID owner_id;
BOOL owner_is_group;
@@ -7040,6 +7120,14 @@ void process_load_url(LLMessageSystem* msg, void**)
msg->getString("Data", "ObjectName", 256, object_name);
msg->getUUID( "Data", "ObjectID", object_id);
msg->getUUID( "Data", "OwnerID", owner_id);
// NaCl - Antispam Registry
if((owner_id.isNull()
&& NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,object_id))
|| NACLAntiSpamRegistry::checkQueue((U32)NACLAntiSpamRegistry::QUEUE_SCRIPT_DIALOG,owner_id))
return;
// NaCl End
msg->getBOOL( "Data", "OwnerIsGroup", owner_is_group);
msg->getString("Data", "Message", 256, message);
msg->getString("Data", "URL", 256, url);
@@ -7112,6 +7200,11 @@ void process_initiate_download(LLMessageSystem* msg, void**)
void process_script_teleport_request(LLMessageSystem* msg, void**)
{
// NaCl - Antispam
static LLCachedControl<bool> antispam(gSavedSettings,"_NACL_Antispam");
if(antispam)
return;
// NaCl End
if (!gSavedSettings.getBOOL("ScriptsCanShowUI")) return;
std::string object_name;