]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_muteban.cpp
e0be4c64749ef6a391821d1577b131cfb3e1175c
[user/henk/code/inspircd.git] / src / modules / m_muteban.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017, 2019-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012, 2018-2019 Robby <robby@chatbelgie.be>
6  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
7  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
9  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24
25 #include "inspircd.h"
26 #include "modules/ctctags.h"
27
28 class ModuleQuietBan
29         : public Module
30         , public CTCTags::EventListener
31 {
32  private:
33         bool notifyuser;
34
35  public:
36         ModuleQuietBan()
37                 : CTCTags::EventListener(this)
38         {
39         }
40
41         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
42         {
43                 ConfigTag* tag = ServerInstance->Config->ConfValue("muteban");
44                 notifyuser = tag->getBool("notifyuser", true);
45         }
46
47         Version GetVersion() CXX11_OVERRIDE
48         {
49                 return Version("Adds extended ban m: which bans specific masks from speaking in a channel.", VF_OPTCOMMON|VF_VENDOR);
50         }
51
52         ModResult HandleMessage(User* user, const MessageTarget& target, bool& echo_original)
53         {
54                 if (!IS_LOCAL(user) || target.type != MessageTarget::TYPE_CHANNEL)
55                         return MOD_RES_PASSTHRU;
56
57                 Channel* chan = target.Get<Channel>();
58                 if (chan->GetExtBanStatus(user, 'm') == MOD_RES_DENY && chan->GetPrefixValue(user) < VOICE_VALUE)
59                 {
60                         if (!notifyuser)
61                         {
62                                 echo_original = true;
63                                 return MOD_RES_DENY;
64                         }
65
66                         user->WriteNumeric(Numerics::CannotSendTo(chan, "messages", 'm', "mute"));
67                         return MOD_RES_DENY;
68                 }
69
70                 return MOD_RES_PASSTHRU;
71         }
72
73         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
74         {
75                 return HandleMessage(user, target, details.echo_original);
76         }
77
78         ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
79         {
80                 return HandleMessage(user, target, details.echo_original);
81         }
82
83         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
84         {
85                 tokens["EXTBAN"].push_back('m');
86         }
87 };
88
89 MODULE_INIT(ModuleQuietBan)