1 /* 2 * InspIRCd -- Internet Relay Chat Daemon 3 * 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> 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 ModuleBlockColor()39 ModuleBlockColor() 40 : exemptionprov(this) 41 , bc(this, "blockcolor", 'c') 42 { 43 } 44 On005Numeric(std::map<std::string,std::string> & tokens)45 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE 46 { 47 tokens["EXTBAN"].push_back('c'); 48 } 49 OnUserPreMessage(User * user,const MessageTarget & target,MessageDetails & details)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 std::string ctcpname; // Unused. 64 std::string message; 65 if (!details.IsCTCP(ctcpname, message)) 66 message.assign(details.text); 67 68 for (std::string::iterator i = message.begin(); i != message.end(); ++i) 69 { 70 const unsigned char chr = static_cast<unsigned char>(*i); 71 if (chr < 32) 72 { 73 if (modeset) 74 user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", &bc)); 75 else 76 user->WriteNumeric(Numerics::CannotSendTo(c, "messages containing formatting characters", 'c', "nocolor")); 77 return MOD_RES_DENY; 78 } 79 } 80 } 81 } 82 return MOD_RES_PASSTHRU; 83 } 84 GetVersion()85 Version GetVersion() CXX11_OVERRIDE 86 { 87 return Version("Adds channel mode c (blockcolor) which allows channels to block messages which contain IRC formatting codes.",VF_VENDOR); 88 } 89 }; 90 91 MODULE_INIT(ModuleBlockColor) 92