1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 #include "helperfuncs.h"
26 /* $ModDesc: Provides user and channel +G mode */
28 class CensorException : public ModuleException
30 virtual char* GetReason()
32 return "Could not find <censor file=\"\"> definition in your config file!";
36 class ModuleCensor : public Module
39 ConfigReader *Conf, *MyConf;
42 ModuleCensor(Server* Me)
46 * read the configuration file on startup.
47 * it is perfectly valid to set <censor file> to the value of the
48 * main config file, then append your <badword> tags to the bottom
49 * of the main config... but rather messy. That's why the capability
50 * of using a seperate config file is provided.
52 * XXX - Really, it'd be nice to scraip this kind of thing, and have something like
53 * an include directive to include additional configuration files. Might make our lives easier. --w00t
55 * XXX - These module pre-date the include directive which exists since beta 5 -- Brain
58 Conf = new ConfigReader;
59 std::string Censorfile = Conf->ReadValue("censor","file",0);
60 MyConf = new ConfigReader(Censorfile);
61 if ((Censorfile == "") || (!MyConf->Verify()))
66 Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile);
67 Srv->AddExtendedMode('G',MT_CHANNEL,false,0,0);
68 Srv->AddExtendedMode('G',MT_CLIENT,false,0,0);
71 void Implements(char* List)
73 List[I_OnRehash] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1;
77 virtual void On005Numeric(std::string &output)
79 InsertMode(output,"G",4);
83 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
85 // check if this is our mode character...
96 virtual ~ModuleCensor()
102 virtual void ReplaceLine(std::string &text,std::string pattern, std::string replace)
104 if ((pattern != "") && (text != ""))
106 while (text.find(pattern) != std::string::npos)
108 int pos = text.find(pattern);
109 text.erase(pos,pattern.length());
110 text.insert(pos,replace);
115 // format of a config entry is <badword text="shit" replace="poo">
117 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
120 irc::string text2 = text.c_str();
121 for (int index = 0; index < MyConf->Enumerate("badword"); index++)
123 irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str();
124 if (text2.find(pattern) != std::string::npos)
126 std::string replace = MyConf->ReadValue("badword","replace",index);
128 if (target_type == TYPE_USER)
130 userrec* t = (userrec*)dest;
131 active = (strchr(t->modes,'G') > 0);
133 else if (target_type == TYPE_CHANNEL)
135 chanrec* t = (chanrec*)dest;
136 active = (t->IsCustomModeSet('G'));
141 this->ReplaceLine(text,std::string(pattern.c_str()),replace);
148 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
150 return OnUserPreMessage(user,dest,target_type,text,status);
153 virtual void OnRehash(std::string parameter)
156 * reload our config file on rehash - we must destroy and re-allocate the classes
157 * to call the constructor again and re-read our data.
161 Conf = new ConfigReader;
162 std::string Censorfile = Conf->ReadValue("censor","file",0);
163 // this automatically re-reads the configuration file into the class
164 MyConf = new ConfigReader(Censorfile);
165 if ((Censorfile == "") || (!MyConf->Verify()))
170 Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile);
173 virtual Version GetVersion()
175 // This is version 2 because version 1.x is the unreleased unrealircd module
176 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
181 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
183 class ModuleCensorFactory : public ModuleFactory
186 ModuleCensorFactory()
190 ~ModuleCensorFactory()
194 virtual Module * CreateModule(Server* Me)
196 return new ModuleCensor(Me);
202 extern "C" void * init_module( void )
204 return new ModuleCensorFactory;