1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 * ---------------------------------------------------
23 /* $ModDesc: Provides user and channel +G mode */
25 class ModuleCensor : public Module
28 ConfigReader *Conf, *MyConf;
33 // read the configuration file on startup.
34 // it is perfectly valid to set <censor file> to the value of the
35 // main config file, then append your <badword> tags to the bottom
36 // of the main config... but rather messy. That's why the capability
37 // of using a seperate config file is provided.
39 Conf = new ConfigReader;
40 std::string Censorfile = Conf->ReadValue("censor","file",0);
41 MyConf = new ConfigReader(Censorfile);
42 if ((Censorfile == "") || (!MyConf->Verify()))
44 printf("Error, could not find <censor file=\"\"> definition in your config file!");
47 Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile);
48 Srv->AddExtendedMode('G',MT_CHANNEL,false,0,0);
49 Srv->AddExtendedMode('G',MT_CLIENT,false,0,0);
52 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
54 // check if this is our mode character...
65 virtual ~ModuleCensor()
72 virtual void ReplaceLine(std::string &text,std::string pattern, std::string replace)
74 if ((pattern != "") && (text != ""))
76 while (strstr(text.c_str(),pattern.c_str()))
78 int pos = text.find(pattern);
79 text.erase(pos,pattern.length());
80 text.insert(pos,replace);
85 // format of a config entry is <badword text="shit" replace="poo">
87 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
90 for (int index = 0; index < MyConf->Enumerate("badword"); index++)
92 std::string pattern = MyConf->ReadValue("badword","text",index);
93 if (strstr(text.c_str(),pattern.c_str()))
95 std::string replace = MyConf->ReadValue("badword","replace",index);
97 if (target_type == TYPE_USER)
99 userrec* t = (userrec*)dest;
100 active = (strchr(t->modes,'G') > 0);
102 else if (target_type == TYPE_CHANNEL)
104 chanrec* t = (chanrec*)dest;
105 active = (t->IsCustomModeSet('G'));
110 this->ReplaceLine(text,pattern,replace);
119 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
122 for (int index = 0; index < MyConf->Enumerate("badword"); index++)
124 std::string pattern = MyConf->ReadValue("badword","text",index);
125 if (strstr(text.c_str(),pattern.c_str()))
127 std::string replace = MyConf->ReadValue("badword","replace",index);
129 if (target_type == TYPE_USER)
131 userrec* t = (userrec*)dest;
132 active = (strchr(t->modes,'G') > 0);
134 else if (target_type == TYPE_CHANNEL)
136 chanrec* t = (chanrec*)dest;
137 active = (t->IsCustomModeSet('G'));
142 this->ReplaceLine(text,pattern,replace);
151 virtual void OnRehash()
153 // reload our config file on rehash - we must destroy and re-allocate the classes
154 // to call the constructor again and re-read our data.
157 Conf = new ConfigReader;
158 std::string Censorfile = Conf->ReadValue("censor","file",0);
159 // this automatically re-reads the configuration file into the class
160 MyConf = new ConfigReader(Censorfile);
161 if ((Censorfile == "") || (!MyConf->Verify()))
163 // bail if the user forgot to create a config file
164 printf("Error, could not find <censor file=\"\"> definition in your config file!");
167 Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile);
170 virtual Version GetVersion()
172 // This is version 2 because version 1.x is the unreleased unrealircd module
173 return Version(1,0,0,0);
178 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
180 class ModuleCensorFactory : public ModuleFactory
183 ModuleCensorFactory()
187 ~ModuleCensorFactory()
191 virtual Module * CreateModule()
193 return new ModuleCensor;
199 extern "C" void * init_module( void )
201 return new ModuleCensorFactory;