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