2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2013, 2017, 2020-2021 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012 Shawn Smith <ShawnSmith0828@gmail.com>
7 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
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>
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.
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
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/>.
31 #include "modules/exemption.h"
33 class ModuleBlockColor : public Module
35 CheckExemption::EventProvider exemptionprov;
36 SimpleChannelModeHandler bc;
41 , bc(this, "blockcolor", 'c')
45 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
47 tokens["EXTBAN"].push_back('c');
50 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
52 if ((target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user)))
54 Channel* c = target.Get<Channel>();
56 ModResult res = CheckExemption::Call(exemptionprov, user, c, "blockcolor");
57 if (res == MOD_RES_ALLOW)
58 return MOD_RES_PASSTHRU;
60 bool modeset = c->IsModeSet(bc);
61 if (!c->GetExtBanStatus(user, 'c').check(!modeset))
63 std::string ctcpname; // Unused.
65 if (!details.IsCTCP(ctcpname, message))
66 message.assign(details.text);
68 for (std::string::iterator i = message.begin(); i != message.end(); ++i)
70 const unsigned char chr = static_cast<unsigned char>(*i);
74 user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc));
76 user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", 'c', "nocolor"));
82 return MOD_RES_PASSTHRU;
85 Version GetVersion() CXX11_OVERRIDE
87 return Version("Adds channel mode c (blockcolor) which allows channels to block messages which contain IRC formatting codes.",VF_VENDOR);
91 MODULE_INIT(ModuleBlockColor)