]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanfilter.cpp
Merge tag 'v2.0.25' into master.
[user/henk/code/inspircd.git] / src / modules / m_chanfilter.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
11  *
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.
15  *
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
19  * details.
20  *
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/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "listmode.h"
28 #include "modules/exemption.h"
29
30 /** Handles channel mode +g
31  */
32 class ChanFilter : public ListModeBase
33 {
34  public:
35         ChanFilter(Module* Creator) : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", 941, 940, false, "chanfilter") { }
36
37         bool ValidateParam(User* user, Channel* chan, std::string &word)
38         {
39                 if (word.length() > 35)
40                 {
41                         user->WriteNumeric(935, chan->name, word, "%word is too long for censor list");
42                         return false;
43                 }
44
45                 return true;
46         }
47
48         void TellListTooLong(User* user, Channel* chan, std::string &word)
49         {
50                 user->WriteNumeric(939, chan->name, word, "Channel spamfilter list is full");
51         }
52
53         void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
54         {
55                 user->WriteNumeric(937, chan->name, InspIRCd::Format("The word %s is already on the spamfilter list", word.c_str()));
56         }
57
58         void TellNotSet(User* user, Channel* chan, std::string &word)
59         {
60                 user->WriteNumeric(938, chan->name, "No such spamfilter word is set");
61         }
62 };
63
64 class ModuleChanFilter : public Module
65 {
66         CheckExemption::EventProvider exemptionprov;
67         ChanFilter cf;
68         bool hidemask;
69
70  public:
71
72         ModuleChanFilter()
73                 : exemptionprov(this)
74                 , cf(this)
75         {
76         }
77
78         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
79         {
80                 hidemask = ServerInstance->Config->ConfValue("chanfilter")->getBool("hidemask");
81                 cf.DoRehash();
82         }
83
84         ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
85         {
86                 if (target_type != TYPE_CHANNEL)
87                         return MOD_RES_PASSTHRU;
88
89                 Channel* chan = static_cast<Channel*>(dest);
90                 ModResult res = CheckExemption::Call(exemptionprov, user, chan, "filter");
91
92                 if (!IS_LOCAL(user) || res == MOD_RES_ALLOW)
93                         return MOD_RES_PASSTHRU;
94
95                 ListModeBase::ModeList* list = cf.GetList(chan);
96
97                 if (list)
98                 {
99                         for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++)
100                         {
101                                 if (InspIRCd::Match(text, i->mask))
102                                 {
103                                         if (hidemask)
104                                                 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)");
105                                         else
106                                                 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, i->mask, "Cannot send to channel (your message contained a censored word)");
107                                         return MOD_RES_DENY;
108                                 }
109                         }
110                 }
111
112                 return MOD_RES_PASSTHRU;
113         }
114
115         Version GetVersion() CXX11_OVERRIDE
116         {
117                 return Version("Provides channel-specific censor lists (like mode +G but varies from channel to channel)", VF_VENDOR);
118         }
119 };
120
121 MODULE_INIT(ModuleChanFilter)