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