1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #define _CRT_SECURE_NO_DEPRECATE
15 #define _SCL_SECURE_NO_DEPRECATE
20 typedef std::map<irc::string,irc::string> censor_t;
22 /* $ModDesc: Provides user and channel +G mode */
24 /** Handles usermode +G
26 class CensorUser : public SimpleUserModeHandler
29 CensorUser(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'G') { }
32 /** Handles channel mode +G
34 class CensorChannel : public SimpleChannelModeHandler
37 CensorChannel(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'G') { }
40 class ModuleCensor : public Module
47 ModuleCensor(InspIRCd* Me)
50 /* Read the configuration file on startup.
53 cu = new CensorUser(ServerInstance);
54 cc = new CensorChannel(ServerInstance);
55 if (!ServerInstance->Modes->AddMode(cu) || !ServerInstance->Modes->AddMode(cc))
59 throw ModuleException("Could not add new modes!");
61 Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRunTestSuite };
62 ServerInstance->Modules->Attach(eventlist, this, 4);
66 virtual ~ModuleCensor()
68 ServerInstance->Modes->DelMode(cu);
69 ServerInstance->Modes->DelMode(cc);
74 // format of a config entry is <badword text="shit" replace="poo">
75 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
82 if (target_type == TYPE_USER)
83 active = ((User*)dest)->IsModeSet('G');
84 else if (target_type == TYPE_CHANNEL)
86 active = ((Channel*)dest)->IsModeSet('G');
87 Channel* c = (Channel*)dest;
88 if (CHANOPS_EXEMPT(ServerInstance, 'G') && c->GetStatus(user) == STATUS_OP)
97 irc::string text2 = text.c_str();
98 for (censor_t::iterator index = censors.begin(); index != censors.end(); index++)
100 if (text2.find(index->first) != irc::string::npos)
102 if (index->second.empty())
104 user->WriteNumeric(ERR_WORDFILTERED, "%s %s %s :Your message contained a censored word, and was blocked", user->nick.c_str(), ((Channel*)dest)->name.c_str(), index->first.c_str());
108 SearchAndReplace(text2, index->first, index->second);
111 text = text2.c_str();
115 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
117 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
120 virtual void OnRehash(User* user)
123 * reload our config file on rehash - we must destroy and re-allocate the classes
124 * to call the constructor again and re-read our data.
126 ConfigReader* MyConf = new ConfigReader(ServerInstance);
129 for (int index = 0; index < MyConf->Enumerate("badword"); index++)
131 irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str();
132 irc::string replace = (MyConf->ReadValue("badword","replace",index)).c_str();
133 censors[pattern] = replace;
139 virtual Version GetVersion()
141 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
146 MODULE_INIT(ModuleCensor)