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