X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_censor.cpp;h=69db8bbe6936d9c304be62c53e6dd161b0c14673;hb=1484a054870bdfe94346057053d5c8e48a708232;hp=03b4f0f9dfc8d2726dac90b43000468050921238;hpb=ced58c3be3f1da8dcf70c3904e5fe4bdaabf0e3d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index 03b4f0f9d..69db8bbe6 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -3,7 +3,7 @@ * +------------------------------------+ * * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: + * E-mail: * * * @@ -36,11 +36,73 @@ class CensorException : public ModuleException } }; +class CensorUser : public ModeHandler +{ + public: + CensorUser() : ModeHandler('G', 0, 0, false, MODETYPE_USER, false) { } + + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + { + /* Only opers can change other users modes */ + if ((source != dest) && (!*source->oper)) + return MODEACTION_DENY; + + if (adding) + { + if (!dest->IsModeSet('G')) + { + dest->SetMode('G',true); + return MODEACTION_ALLOW; + } + } + else + { + if (dest->IsModeSet('G')) + { + dest->SetMode('G',false); + return MODEACTION_ALLOW; + } + } + + return MODEACTION_DENY; + } +}; + +class CensorChannel : public ModeHandler +{ + public: + CensorChannel() : ModeHandler('G', 0, 0, false, MODETYPE_CHANNEL, false) { } + + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + { + if (adding) + { + if (!channel->IsModeSet('G')) + { + channel->SetMode('G',false); + return MODEACTION_ALLOW; + } + } + else + { + if (channel->IsModeSet('G')) + { + channel->SetMode('G',false); + return MODEACTION_ALLOW; + } + } + + return MODEACTION_ALLOW; + } +}; + class ModuleCensor : public Module { Server *Srv; censor_t censors; + CensorUser *cu; + CensorChannel *cc; public: ModuleCensor(Server* Me) @@ -60,37 +122,27 @@ class ModuleCensor : public Module */ Srv = Me; OnRehash(""); - Srv->AddExtendedMode('G',MT_CHANNEL,false,0,0); - Srv->AddExtendedMode('G',MT_CLIENT,false,0,0); + cu = new CensorUser; + cc = new CensorChannel; + Srv->AddMode(cu, 'G'); + Srv->AddMode(cc, 'G'); } void Implements(char* List) { - List[I_OnRehash] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1; + List[I_OnRehash] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1; } - virtual void On005Numeric(std::string &output) - { - InsertMode(output,"G",4); - } - - - virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + virtual void On005Numeric(std::string &output) { - // check if this is our mode character... - if (modechar == 'G') - { - return 1; - } - else - { - return 0; - } + InsertMode(output,"G",4); } - + virtual ~ModuleCensor() { + DELETE(cu); + DELETE(cc); } virtual void ReplaceLine(irc::string &text, irc::string pattern, irc::string replace) @@ -119,12 +171,12 @@ class ModuleCensor : public Module if (target_type == TYPE_USER) { userrec* t = (userrec*)dest; - active = (strchr(t->modes,'G') > 0); + active = t->IsModeSet('G'); } else if (target_type == TYPE_CHANNEL) { chanrec* t = (chanrec*)dest; - active = (t->IsModeSet('G')); + active = t->IsModeSet('G'); } if (active) @@ -158,14 +210,14 @@ class ModuleCensor : public Module throw(e); } censors.clear(); - for (int index = 0; index < MyConf->Enumerate("badword"); index++) - { - irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str(); - irc::string replace = (MyConf->ReadValue("badword","replace",index)).c_str(); + for (int index = 0; index < MyConf->Enumerate("badword"); index++) + { + irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str(); + irc::string replace = (MyConf->ReadValue("badword","replace",index)).c_str(); censors[pattern] = replace; } - delete Conf; - delete MyConf; + DELETE(Conf); + DELETE(MyConf); } virtual Version GetVersion() @@ -201,4 +253,3 @@ extern "C" void * init_module( void ) { return new ModuleCensorFactory; } -