From 235a0a2035bda6dd214719107083266207f39883 Mon Sep 17 00:00:00 2001 From: brain Date: Sat, 4 Feb 2006 13:09:18 +0000 Subject: Added "char status" parameter to OnUserPreNotice and OnUserPreMessage for NOTICE @#chan etc. Tidied up craq++ in modules (copy and pasting OnUserPreNotice into OnUserPreMessage?! why not just call one from the other!) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3072 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_filter_pcre.cpp | 48 +++-------------------------------- src/modules/m_blockcolor.cpp | 34 +++---------------------- src/modules/m_censor.cpp | 31 +++-------------------- src/modules/m_chanfilter.cpp | 10 +++----- src/modules/m_filter.cpp | 50 +++---------------------------------- src/modules/m_noctcp.cpp | 21 +++------------- src/modules/m_park.cpp | 2 +- src/modules/m_restrictmsg.cpp | 4 +-- src/modules/m_services.cpp | 36 +++----------------------- src/modules/m_silence.cpp | 23 +++-------------- src/modules/m_stripcolor.cpp | 21 +++------------- 11 files changed, 30 insertions(+), 250 deletions(-) (limited to 'src/modules') diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp index ca002f578..f6ec64d6c 100644 --- a/src/modules/extra/m_filter_pcre.cpp +++ b/src/modules/extra/m_filter_pcre.cpp @@ -94,54 +94,12 @@ class ModuleFilterPCRE : public Module // format of a config entry is - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { - for (unsigned int index = 0; index < filters.size(); index++) - { - if (pcre_exec(filters[index],NULL,text.c_str(),text.length(),0,0,NULL,0) > -1) - { - std::string target = ""; - std::string reason = MyConf->ReadValue("keyword","reason",index); - std::string do_action = MyConf->ReadValue("keyword","action",index); - - if (do_action == "") - do_action = "none"; - - if (target_type == TYPE_USER) - { - userrec* t = (userrec*)dest; - target = std::string(t->nick); - } - else if (target_type == TYPE_CHANNEL) - { - chanrec* t = (chanrec*)dest; - target = std::string(t->name); - } - if (do_action == "block") - { - Srv->SendOpers(std::string("FilterPCRE: ")+std::string(user->nick)+ - std::string(" had their message filtered, target was ")+ - target+": "+reason); - // this form of SendTo (with the source as NuLL) sends a server notice - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+ - " :Your message has been filtered and opers notified: "+reason); - } - - Srv->Log(DEFAULT,std::string("Filter: ")+std::string(user->nick)+ - std::string(" had their message filtered, target was ")+ - target+": "+reason+" Action: "+do_action); - - if (do_action == "kill") - { - Srv->QuitUser(user,reason); - } - return 1; - } - } - return 0; + return OnUserPreNotice(user,dest,target_type,text,status); } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { for (unsigned int index = 0; index < filters.size(); index++) { diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp index 461a05de4..c53520adb 100644 --- a/src/modules/m_blockcolor.cpp +++ b/src/modules/m_blockcolor.cpp @@ -47,7 +47,7 @@ class ModuleBlockColor : public Module InsertMode(output,"c",4); } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { if (target_type == TYPE_CHANNEL) { @@ -80,37 +80,9 @@ class ModuleBlockColor : public Module return 0; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { - if (target_type == TYPE_CHANNEL) - { - chanrec* c = (chanrec*)dest; - char ctext[MAXBUF]; - char *ctptr = ctext; - strlcpy(ctext,text.c_str(),MAXBUF); - - - if (c->IsCustomModeSet('c')) - { - /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */ - while (ctptr && *ctptr) - { - switch (*ctptr++) - { - case 2: - case 3: - case 15: - case 21: - case 22: - case 31: - WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name); - return 1; - break; - } - } - } - } - return 0; + return OnUserPreMessage(user,dest,target_type,text,status); } virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index 45f5af551..f455cef53 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -107,7 +107,7 @@ class ModuleCensor : public Module // format of a config entry is - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { bool active = false; for (int index = 0; index < MyConf->Enumerate("badword"); index++) @@ -137,34 +137,9 @@ class ModuleCensor : public Module return 0; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { - bool active = false; - for (int index = 0; index < MyConf->Enumerate("badword"); index++) - { - std::string pattern = MyConf->ReadValue("badword","text",index); - if (text.find(pattern) != std::string::npos) - { - std::string replace = MyConf->ReadValue("badword","replace",index); - - if (target_type == TYPE_USER) - { - userrec* t = (userrec*)dest; - active = (strchr(t->modes,'G') > 0); - } - else if (target_type == TYPE_CHANNEL) - { - chanrec* t = (chanrec*)dest; - active = (t->IsCustomModeSet('G')); - } - - if (active) - { - this->ReplaceLine(text,pattern,replace); - } - } - } - return 0; + return OnUserPreMessage(user,dest,target_type,text,status); } virtual void OnRehash(std::string parameter) diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp index ab7339d7e..953e3c28a 100644 --- a/src/modules/m_chanfilter.cpp +++ b/src/modules/m_chanfilter.cpp @@ -101,7 +101,7 @@ class ModuleChanFilter : public Module return 0; } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { if (target_type == TYPE_CHANNEL) { @@ -110,13 +110,9 @@ class ModuleChanFilter : public Module else return 0; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { - if (target_type == TYPE_CHANNEL) - { - return ProcessMessages(user,(chanrec*)dest,text); - } - else return 0; + return OnUserPreMessage(user,dest,target_type,text,status); } virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 1fa212999..5b2826f5a 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -69,56 +69,12 @@ class ModuleFilter : public Module // format of a config entry is - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { - std::string text2 = text+" "; - for (int index = 0; index < MyConf->Enumerate("keyword"); index++) - { - std::string pattern = MyConf->ReadValue("keyword","pattern",index); - if ((Srv->MatchText(text2,pattern)) || (Srv->MatchText(text,pattern))) - { - std::string target = ""; - std::string reason = MyConf->ReadValue("keyword","reason",index); - std::string do_action = MyConf->ReadValue("keyword","action",index); - - if (do_action == "") - do_action = "none"; - - if (target_type == TYPE_USER) - { - userrec* t = (userrec*)dest; - target = std::string(t->nick); - } - else if (target_type == TYPE_CHANNEL) - { - chanrec* t = (chanrec*)dest; - target = std::string(t->name); - } - if (do_action == "block") - { - Srv->SendOpers(std::string("FILTER: ")+std::string(user->nick)+ - std::string(" had their message filtered, target was ")+ - target+": "+reason); - // this form of SendTo (with the source as NuLL) sends a server notice - Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+ - " :Your message has been filtered and opers notified: "+reason); - } - - Srv->Log(DEFAULT,std::string("FILTER: ")+std::string(user->nick)+ - std::string(" had their message filtered, target was ")+ - target+": "+reason+" Action: "+do_action); - - if (do_action == "kill") - { - Srv->QuitUser(user,reason); - } - return 1; - } - } - return 0; + return OnUserPreNotice(user,dest,target_type,text,status); } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { std::string text2 = text+" "; for (int index = 0; index < MyConf->Enumerate("keyword"); index++) diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp index ad6c74e84..ab0808aa2 100644 --- a/src/modules/m_noctcp.cpp +++ b/src/modules/m_noctcp.cpp @@ -47,27 +47,12 @@ class ModuleNoCTCP : public Module InsertMode(output,"C",4); } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { - if (target_type == TYPE_CHANNEL) - { - chanrec* c = (chanrec*)dest; - if (c->IsCustomModeSet('C')) - { - if ((text.length()) && (text[0] == '\1')) - { - if (strncmp(text.c_str(),"\1ACTION ",8)) - { - WriteServ(user->fd,"492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name); - return 1; - } - } - } - } - return 0; + return OnUserPreNotice(user,dest,target_type,text,status); } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { if (target_type == TYPE_CHANNEL) { diff --git a/src/modules/m_park.cpp b/src/modules/m_park.cpp index 1d7167274..5ac07839e 100644 --- a/src/modules/m_park.cpp +++ b/src/modules/m_park.cpp @@ -322,7 +322,7 @@ class ModulePark : public Module } } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { if (target_type == TYPE_USER) { diff --git a/src/modules/m_restrictmsg.cpp b/src/modules/m_restrictmsg.cpp index b2e2e60ce..0bc03fab1 100644 --- a/src/modules/m_restrictmsg.cpp +++ b/src/modules/m_restrictmsg.cpp @@ -43,7 +43,7 @@ class ModuleRestrictMsg : public Module List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1; } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { if (target_type == TYPE_USER) { @@ -64,7 +64,7 @@ class ModuleRestrictMsg : public Module return 0; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { return this->OnUserPreMessage(user,dest,target_type,text); } diff --git a/src/modules/m_services.cpp b/src/modules/m_services.cpp index c4f867ac3..89074ff7f 100644 --- a/src/modules/m_services.cpp +++ b/src/modules/m_services.cpp @@ -118,7 +118,7 @@ class ModuleServices : public Module return 0; } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { if (target_type == TYPE_CHANNEL) { @@ -153,39 +153,9 @@ class ModuleServices : public Module return 0; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { - if (target_type == TYPE_CHANNEL) - { - chanrec* c = (chanrec*)dest; - if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r'))) - { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) - { - // user is ulined, can speak regardless - return 0; - } - // user noticing a +M channel and is not registered - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel"); - return 1; - } - } - if (target_type == TYPE_USER) - { - userrec* u = (userrec*)dest; - if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r'))) - { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) - { - // user is ulined, can speak regardless - return 0; - } - // user noticing a +R user and is not registered - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user"); - return 1; - } - } - return 0; + return OnUserPreMessage(user,dest,target_type,text,status); } virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index a0207344c..e785265ac 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -164,7 +164,7 @@ class ModuleSilence : public Module output = output + " SILENCE=999"; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { // im not sure how unreal's silence operates but ours is sensible. It blocks notices and // privmsgs from people on the silence list, directed privately at the user. @@ -190,26 +190,9 @@ class ModuleSilence : public Module return 0; } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { - if (target_type == TYPE_USER) - { - userrec* u = (userrec*)dest; - silencelist* sl = (silencelist*)u->GetExt("silence_list"); - if (sl) - { - for (silencelist::const_iterator c = sl->begin(); c != sl->end(); c++) - { - irc::string listitem = c->c_str(); - irc::string target = user->nick; - if (listitem == target) - { - return 1; - } - } - } - } - return 0; + return OnUserPreNotice(user,dest,target_type,text,status); } virtual ~ModuleSilence() diff --git a/src/modules/m_stripcolor.cpp b/src/modules/m_stripcolor.cpp index 2b931daec..19c69ec4b 100644 --- a/src/modules/m_stripcolor.cpp +++ b/src/modules/m_stripcolor.cpp @@ -122,7 +122,7 @@ class ModuleStripColor : public Module text = sentence; } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status) { bool active = false; if (target_type == TYPE_USER) @@ -142,24 +142,9 @@ class ModuleStripColor : public Module return 0; } - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status) { - bool active = false; - if (target_type == TYPE_USER) - { - userrec* t = (userrec*)dest; - active = (strchr(t->modes,'S') > 0); - } - else if (target_type == TYPE_CHANNEL) - { - chanrec* t = (chanrec*)dest; - active = (t->IsCustomModeSet('S')); - } - if (active) - { - this->ReplaceLine(text); - } - return 0; + return OnUserPreMessage(user,dest,target_type,text,status); } virtual Version GetVersion() -- cgit v1.2.3