]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5  *   Copyright (C) 2013, 2017, 2020 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012, 2018 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2012 Shawn Smith <ShawnSmith0828@gmail.com>
8  *   Copyright (C) 2012 DjSlash <djslash@djslash.org>
9  *   Copyright (C) 2012 Attila Molnar <attilamolnar@hush.com>
10  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
12  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
13  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
14  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
15  *
16  * This file is part of InspIRCd.  InspIRCd is free software: you can
17  * redistribute it and/or modify it under the terms of the GNU General Public
18  * License as published by the Free Software Foundation, version 2.
19  *
20  * This program is distributed in the hope that it will be useful, but WITHOUT
21  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23  * details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27  */
28
29
30 #include "inspircd.h"
31 #include "modules/exemption.h"
32
33 class ModuleBlockColor : public Module
34 {
35         CheckExemption::EventProvider exemptionprov;
36         SimpleChannelModeHandler bc;
37  public:
38
39         ModuleBlockColor()
40                 : exemptionprov(this)
41                 , bc(this, "blockcolor", 'c')
42         {
43         }
44
45         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
46         {
47                 tokens["EXTBAN"].push_back('c');
48         }
49
50         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
51         {
52                 if ((target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user)))
53                 {
54                         Channel* c = target.Get<Channel>();
55
56                         ModResult res = CheckExemption::Call(exemptionprov, user, c, "blockcolor");
57                         if (res == MOD_RES_ALLOW)
58                                 return MOD_RES_PASSTHRU;
59
60                         bool modeset = c->IsModeSet(bc);
61                         if (!c->GetExtBanStatus(user, 'c').check(!modeset))
62                         {
63                                 for (std::string::iterator i = details.text.begin(); i != details.text.end(); i++)
64                                 {
65                                         // Block all control codes except \001 for CTCP
66                                         if ((*i >= 0) && (*i < 32) && (*i != 1))
67                                         {
68                                                 if (modeset)
69                                                         user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc));
70                                                 else
71                                                         user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", 'c', "nocolor"));
72                                                 return MOD_RES_DENY;
73                                         }
74                                 }
75                         }
76                 }
77                 return MOD_RES_PASSTHRU;
78         }
79
80         Version GetVersion() CXX11_OVERRIDE
81         {
82                 return Version("Adds channel mode c (blockcolor) which allows channels to block messages which contain IRC formatting codes.",VF_VENDOR);
83         }
84 };
85
86 MODULE_INIT(ModuleBlockColor)