diff options
-rw-r--r-- | docs/censor.conf.example | 12 | ||||
-rw-r--r-- | src/InspIRCd.dev | 12 | ||||
-rw-r--r-- | src/InspIRCd.layout | 39 | ||||
-rw-r--r-- | src/modules/m_censor.cpp | 200 |
4 files changed, 246 insertions, 17 deletions
diff --git a/docs/censor.conf.example b/docs/censor.conf.example new file mode 100644 index 000000000..ff6136e1d --- /dev/null +++ b/docs/censor.conf.example @@ -0,0 +1,12 @@ +# Configuration file for m_censor.so (1.0.0.0) +# C.J.Edwards May 2004. +# + +# The tags for this module are formatted as follows: +# +# <badword text="simple word" +# replace="text to replace with"> + +<badword text="shit" replace="poo"> +<badword pattern="fuck" reason="(censored)"> + diff --git a/src/InspIRCd.dev b/src/InspIRCd.dev index f06735e42..041cc9308 100644 --- a/src/InspIRCd.dev +++ b/src/InspIRCd.dev @@ -1,7 +1,7 @@ [Project] FileName=InspIRCd.dev Name=InspIRCd - The Inspire Internet Relay Chat Daemon -UnitCount=61 +UnitCount=62 Type=1 Ver=1 ObjFiles= @@ -655,3 +655,13 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit62] +FileName=modules\m_censor.cpp +CompileCpp=1 +Folder=Modules/Server +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index fa44b4a6e..695e8f258 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -1,5 +1,5 @@ [Editors] -Focused=43 +Focused=-1 Order=2,4,6,3,7,25,5,24,39,42,43,1,46,0,49,-1 [Editor_0] @@ -165,9 +165,9 @@ LeftChar=1 [Editor_20] Open=1 Top=0 -CursorCol=14 -CursorRow=276 -TopLine=245 +CursorCol=1 +CursorRow=321 +TopLine=263 LeftChar=1 [Editor_21] @@ -216,10 +216,10 @@ CursorRow=16 TopLine=1 LeftChar=1 [Editor_27] -Open=0 +Open=1 Top=0 -CursorCol=1 -CursorRow=16 +CursorCol=44 +CursorRow=34 TopLine=1 LeftChar=1 [Editor_28] @@ -253,9 +253,9 @@ LeftChar=1 [Editor_32] Open=1 Top=0 -CursorCol=86 -CursorRow=65 -TopLine=18 +CursorCol=28 +CursorRow=120 +TopLine=75 LeftChar=1 [Editor_33] Open=0 @@ -329,10 +329,10 @@ TopLine=256 LeftChar=1 [Editor_43] Open=1 -Top=1 -CursorCol=32 -CursorRow=601 -TopLine=552 +Top=0 +CursorCol=26 +CursorRow=683 +TopLine=651 LeftChar=1 [Editor_44] Open=0 @@ -363,11 +363,11 @@ CursorRow=88 TopLine=69 LeftChar=1 [Editor_48] -Open=0 +Open=1 Top=0 CursorCol=1 CursorRow=16 -TopLine=1 +TopLine=112 LeftChar=1 [Editor_49] Open=1 @@ -453,3 +453,10 @@ CursorCol=22 CursorRow=50 TopLine=12 LeftChar=1 +[Editor_61] +Open=1 +Top=1 +CursorCol=19 +CursorRow=179 +TopLine=135 +LeftChar=1 diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp new file mode 100644 index 000000000..40e4ee92b --- /dev/null +++ b/src/modules/m_censor.cpp @@ -0,0 +1,200 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include <stdio.h> +#include <string> +#include "users.h" +#include "channels.h" +#include "modules.h" + +/* $ModDesc: Provides user and channel +G mode */ + +class ModuleCensor : public Module +{ + Server *Srv; + ConfigReader *Conf, *MyConf; + + public: + ModuleCensor() + { + // read the configuration file on startup. + // it is perfectly valid to set <censor file> to the value of the + // main config file, then append your <badword> tags to the bottom + // of the main config... but rather messy. That's why the capability + // of using a seperate config file is provided. + Srv = new Server; + Conf = new ConfigReader; + std::string Censorfile = Conf->ReadValue("censor","file",0); + MyConf = new ConfigReader(Censorfile); + if ((Censorfile == "") || (!MyConf->Verify())) + { + printf("Error, could not find <censor file=\"\"> definition in your config file!"); + exit(0); + } + Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile); + Srv->AddExtendedMode('G',MT_CHANNEL,false,0,0); + Srv->AddExtendedMode('G',MT_CLIENT,false,0,0); + } + + virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + { + // check if this is our mode character... + if (modechar == 'G') + { + return 1; + } + else + { + return 0; + } + } + + virtual ~ModuleCensor() + { + delete Srv; + delete MyConf; + delete Conf; + } + + virtual void ReplaceLine(std::string &text,std::string pattern, std::string replace) + { + while (strstr(text.c_str(),pattern.c_str())) + { + int pos = text.find(pattern); + text.erase(pos,pattern.length()); + text.insert(pos,replace); + } + } + + // format of a config entry is <badword text="shit" replace="poo"> + + virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + { + bool active = false; + for (int index = 0; index < MyConf->Enumerate("badword"); index++) + { + std::string pattern = MyConf->ReadValue("badword","text",index); + if (strstr(text.c_str(),pattern.c_str())) + { + 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 0; + } + + virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + { + bool active = false; + for (int index = 0; index < MyConf->Enumerate("badword"); index++) + { + std::string pattern = MyConf->ReadValue("badword","text",index); + if (strstr(text.c_str(),pattern.c_str())) + { + 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 0; + } + + virtual void OnRehash() + { + // reload our config file on rehash - we must destroy and re-allocate the classes + // to call the constructor again and re-read our data. + delete Conf; + delete MyConf; + Conf = new ConfigReader; + std::string Censorfile = Conf->ReadValue("censor","file",0); + // this automatically re-reads the configuration file into the class + MyConf = new ConfigReader(Censorfile); + if ((Censorfile == "") || (!MyConf->Verify())) + { + // bail if the user forgot to create a config file + printf("Error, could not find <censor file=\"\"> definition in your config file!"); + exit(0); + } + Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile); + } + + virtual Version GetVersion() + { + // This is version 2 because version 1.x is the unreleased unrealircd module + return Version(1,0,0,0); + } + +}; + +// stuff down here is the module-factory stuff. For basic modules you can ignore this. + +class ModuleCensorFactory : public ModuleFactory +{ + public: + ModuleCensorFactory() + { + } + + ~ModuleCensorFactory() + { + } + + virtual Module * CreateModule() + { + return new ModuleCensor; + } + +}; + + +extern "C" void * init_module( void ) +{ + return new ModuleCensorFactory; +} + |