2 * InspIRCd -- Internet Relay Chat Daemon
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>
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 for (std::string::iterator i = details.text.begin(); i != details.text.end(); i++)
65 // Block all control codes except \001 for CTCP
66 if ((*i >= 0) && (*i < 32) && (*i != 1))
69 user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc));
71 user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", 'c', "nocolor"));
77 return MOD_RES_PASSTHRU;
80 Version GetVersion() CXX11_OVERRIDE
82 return Version("Adds channel mode c (blockcolor) which allows channels to block messages which contain IRC formatting codes.",VF_VENDOR);
86 MODULE_INIT(ModuleBlockColor)