2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
6 * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2012 Attila Molnar <attilamolnar@hush.com>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
12 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13 * Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
15 * This file is part of InspIRCd. InspIRCd is free software: you can
16 * redistribute it and/or modify it under the terms of the GNU General Public
17 * License as published by the Free Software Foundation, version 2.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include "modules/exemption.h"
32 class NoCTCPUser : public SimpleUserModeHandler
35 NoCTCPUser(Module* Creator)
36 : SimpleUserModeHandler(Creator, "u_noctcp", 'T')
38 if (!ServerInstance->Config->ConfValue("noctcp")->getBool("enableumode"))
39 DisableAutoRegister();
43 class ModuleNoCTCP : public Module
45 CheckExemption::EventProvider exemptionprov;
46 SimpleChannelModeHandler nc;
52 , nc(this, "noctcp", 'C')
57 Version GetVersion() CXX11_OVERRIDE
59 return Version("Adds channel mode C (noctcp) which allows channels to block messages which contain CTCPs and user mode T (u_noctcp) which allows users to block private messages that contain CTCPs.", VF_VENDOR);
62 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
65 return MOD_RES_PASSTHRU;
68 if (!details.IsCTCP(ctcpname) || irc::equals(ctcpname, "ACTION"))
69 return MOD_RES_PASSTHRU;
73 case MessageTarget::TYPE_CHANNEL:
75 if (user->HasPrivPermission("channels/ignore-noctcp"))
76 return MOD_RES_PASSTHRU;
78 Channel* c = target.Get<Channel>();
79 const Channel::MemberMap& members = c->GetUsers();
80 for (Channel::MemberMap::const_iterator member = members.begin(); member != members.end(); ++member)
82 User* u = member->first;
83 if (u->IsModeSet(ncu))
84 details.exemptions.insert(u);
87 ModResult res = CheckExemption::Call(exemptionprov, user, c, "noctcp");
88 if (res == MOD_RES_ALLOW)
89 return MOD_RES_PASSTHRU;
93 user->WriteNumeric(Numerics::CannotSendTo(c, "CTCPs", &nc));
97 if (c->GetExtBanStatus(user, 'C') == MOD_RES_DENY)
99 user->WriteNumeric(Numerics::CannotSendTo(c, "CTCPs", 'C', "noctcp"));
104 case MessageTarget::TYPE_USER:
106 if (user->HasPrivPermission("users/ignore-noctcp"))
107 return MOD_RES_PASSTHRU;
109 User* u = target.Get<User>();
110 if (u->IsModeSet(ncu))
112 user->WriteNumeric(Numerics::CannotSendTo(u, "CTCPs", &ncu));
117 case MessageTarget::TYPE_SERVER:
120 return MOD_RES_PASSTHRU;
123 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
125 tokens["EXTBAN"].push_back('C');
129 MODULE_INIT(ModuleNoCTCP)