2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2004, 2008-2009 Craig Edwards <craigedwards@brainbox.cc>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2005, 2007 Robin Burchell <robin+git@viroteck.net>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define _CRT_SECURE_NO_DEPRECATE
24 #define _SCL_SECURE_NO_DEPRECATE
29 typedef std::map<irc::string,irc::string> censor_t;
31 /** Handles usermode +G
33 class CensorUser : public SimpleUserModeHandler
36 CensorUser(Module* Creator) : SimpleUserModeHandler(Creator, "u_censor", 'G') { }
39 /** Handles channel mode +G
41 class CensorChannel : public SimpleChannelModeHandler
44 CensorChannel(Module* Creator) : SimpleChannelModeHandler(Creator, "censor", 'G') { }
47 class ModuleCensor : public Module
54 ModuleCensor() : cu(this), cc(this) { }
56 // format of a config entry is <badword text="shit" replace="poo">
57 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
60 return MOD_RES_PASSTHRU;
64 if (target_type == TYPE_USER)
65 active = ((User*)dest)->IsModeSet(cu);
66 else if (target_type == TYPE_CHANNEL)
68 Channel* c = (Channel*)dest;
69 active = c->IsModeSet(cc);
70 ModResult res = ServerInstance->OnCheckExemption(user,c,"censor");
72 if (res == MOD_RES_ALLOW)
73 return MOD_RES_PASSTHRU;
77 return MOD_RES_PASSTHRU;
79 irc::string text2 = text.c_str();
80 for (censor_t::iterator index = censors.begin(); index != censors.end(); index++)
82 if (text2.find(index->first) != irc::string::npos)
84 if (index->second.empty())
86 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());
90 SearchAndReplace(text2, index->first, index->second);
94 return MOD_RES_PASSTHRU;
97 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
100 * reload our config file on rehash - we must destroy and re-allocate the classes
101 * to call the constructor again and re-read our data.
105 ConfigTagList badwords = ServerInstance->Config->ConfTags("badword");
106 for (ConfigIter i = badwords.first; i != badwords.second; ++i)
108 ConfigTag* tag = i->second;
109 std::string str = tag->getString("text");
110 irc::string pattern(str.c_str());
111 str = tag->getString("replace");
112 censors[pattern] = irc::string(str.c_str());
116 Version GetVersion() CXX11_OVERRIDE
118 return Version("Provides user and channel +G mode",VF_VENDOR);
123 MODULE_INIT(ModuleCensor)