1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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(Module* Creator) : SimpleUserModeHandler(Creator, "censor", 'G') { }
32 /** Handles channel mode +G
34 class CensorChannel : public SimpleChannelModeHandler
37 CensorChannel(Module* Creator) : SimpleChannelModeHandler(Creator, "censor", 'G') { }
40 class ModuleCensor : public Module
47 ModuleCensor() : cu(this), cc(this) { }
51 /* Read the configuration file on startup.
54 ServerInstance->Modules->AddService(cu);
55 ServerInstance->Modules->AddService(cc);
56 Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice };
57 ServerInstance->Modules->Attach(eventlist, this, 3);
61 virtual ~ModuleCensor()
65 // format of a config entry is <badword text="shit" replace="poo">
66 virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
69 return MOD_RES_PASSTHRU;
73 if (target_type == TYPE_USER)
74 active = ((User*)dest)->IsModeSet('G');
75 else if (target_type == TYPE_CHANNEL)
77 active = ((Channel*)dest)->IsModeSet('G');
78 Channel* c = (Channel*)dest;
80 FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,c,"censor"));
82 if (res == MOD_RES_ALLOW)
83 return MOD_RES_PASSTHRU;
87 return MOD_RES_PASSTHRU;
89 irc::string text2 = text.c_str();
90 for (censor_t::iterator index = censors.begin(); index != censors.end(); index++)
92 if (text2.find(index->first) != irc::string::npos)
94 if (index->second.empty())
96 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());
100 SearchAndReplace(text2, index->first, index->second);
103 text = text2.c_str();
104 return MOD_RES_PASSTHRU;
107 virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
109 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
112 virtual void OnRehash(User* user)
115 * reload our config file on rehash - we must destroy and re-allocate the classes
116 * to call the constructor again and re-read our data.
121 for (int index = 0; index < MyConf.Enumerate("badword"); index++)
123 irc::string pattern = (MyConf.ReadValue("badword","text",index)).c_str();
124 irc::string replace = (MyConf.ReadValue("badword","replace",index)).c_str();
125 censors[pattern] = replace;
129 virtual Version GetVersion()
131 return Version("Provides user and channel +G mode",VF_VENDOR);
136 MODULE_INIT(ModuleCensor)