]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_muteban.cpp
fdfd2c701573970fdeb92025124c7785186e419d
[user/henk/code/inspircd.git] / src / modules / m_muteban.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2013, 2017, 2019 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012, 2018-2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9  *   Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
10  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
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 "modules/ctctags.h"
28
29 class ModuleQuietBan
30         : public Module
31         , public CTCTags::EventListener
32 {
33  private:
34         bool notifyuser;
35
36  public:
37         ModuleQuietBan()
38                 : CTCTags::EventListener(this)
39         {
40         }
41
42         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
43         {
44                 ConfigTag* tag = ServerInstance->Config->ConfValue("muteban");
45                 notifyuser = tag->getBool("notifyuser", true);
46         }
47
48         Version GetVersion() CXX11_OVERRIDE
49         {
50                 return Version("Provides extban 'm', mute bans", VF_OPTCOMMON|VF_VENDOR);
51         }
52
53         ModResult HandleMessage(User* user, const MessageTarget& target, bool& echo_original)
54         {
55                 if (!IS_LOCAL(user) || target.type != MessageTarget::TYPE_CHANNEL)
56                         return MOD_RES_PASSTHRU;
57
58                 Channel* chan = target.Get<Channel>();
59                 if (chan->GetExtBanStatus(user, 'm') == MOD_RES_DENY && chan->GetPrefixValue(user) < VOICE_VALUE)
60                 {
61                         if (!notifyuser)
62                         {
63                                 echo_original = true;
64                                 return MOD_RES_DENY;
65                         }
66
67                         user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're muted)");
68                         return MOD_RES_DENY;
69                 }
70
71                 return MOD_RES_PASSTHRU;
72         }
73
74         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
75         {
76                 return HandleMessage(user, target, details.echo_original);
77         }
78
79         ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
80         {
81                 return HandleMessage(user, target, details.echo_original);
82         }
83
84         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
85         {
86                 tokens["EXTBAN"].push_back('m');
87         }
88 };
89
90 MODULE_INIT(ModuleQuietBan)