2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9 * Copyright (C) 2005 Craig McLure <craig@chatspike.net>
10 * Copyright (C) 2005 Craig Edwards <craigedwards@brainbox.cc>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define _CRT_SECURE_NO_DEPRECATE
27 #define _SCL_SECURE_NO_DEPRECATE
32 /** Handles channel mode +g
34 class ChanFilter : public ListModeBase
37 ChanFilter(Module* Creator) : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", 941, 940, false, "chanfilter") { }
39 bool ValidateParam(User* user, Channel* chan, std::string &word)
41 if ((word.length() > 35) || (word.empty()))
43 user->WriteNumeric(935, "%s %s :word is too %s for censor list", chan->name.c_str(), word.c_str(), (word.empty() ? "short" : "long"));
50 void TellListTooLong(User* user, Channel* chan, std::string &word)
52 user->WriteNumeric(939, "%s %s :Channel spamfilter list is full", chan->name.c_str(), word.c_str());
55 void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
57 user->WriteNumeric(937, "%s :The word %s is already on the spamfilter list", chan->name.c_str(), word.c_str());
60 void TellNotSet(User* user, Channel* chan, std::string &word)
62 user->WriteNumeric(938, "%s :No such spamfilter word is set", chan->name.c_str());
66 class ModuleChanFilter : public Module
78 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
80 hidemask = ServerInstance->Config->ConfValue("chanfilter")->getBool("hidemask");
84 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
86 if (target_type != TYPE_CHANNEL)
87 return MOD_RES_PASSTHRU;
89 Channel* chan = static_cast<Channel*>(dest);
90 ModResult res = ServerInstance->OnCheckExemption(user,chan,"filter");
92 if (!IS_LOCAL(user) || res == MOD_RES_ALLOW)
93 return MOD_RES_PASSTHRU;
95 ListModeBase::ModeList* list = cf.GetList(chan);
99 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++)
101 if (InspIRCd::Match(text, i->mask))
104 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Cannot send to channel (your message contained a censored word)", chan->name.c_str());
106 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s %s :Cannot send to channel (your message contained a censored word)", chan->name.c_str(), i->mask.c_str());
112 return MOD_RES_PASSTHRU;
115 Version GetVersion() CXX11_OVERRIDE
117 return Version("Provides channel-specific censor lists (like mode +G but varies from channel to channel)", VF_VENDOR);
121 MODULE_INIT(ModuleChanFilter)