]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_noctcp.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
14  *
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.
18  *
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
22  * details.
23  *
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/>.
26  */
27
28
29 #include "inspircd.h"
30 #include "modules/exemption.h"
31
32 class NoCTCPUser : public SimpleUserModeHandler
33 {
34 public:
35         NoCTCPUser(Module* Creator)
36                 : SimpleUserModeHandler(Creator, "u_noctcp", 'T')
37         {
38                 if (!ServerInstance->Config->ConfValue("noctcp")->getBool("enableumode"))
39                         DisableAutoRegister();
40         }
41 };
42
43 class ModuleNoCTCP : public Module
44 {
45         CheckExemption::EventProvider exemptionprov;
46         SimpleChannelModeHandler nc;
47         NoCTCPUser ncu;
48
49  public:
50         ModuleNoCTCP()
51                 : exemptionprov(this)
52                 , nc(this, "noctcp", 'C')
53                 , ncu(this)
54         {
55         }
56
57         Version GetVersion() CXX11_OVERRIDE
58         {
59                 return Version("Adds channel mode C (noctcp) which allows channels to block messages which contain CTCPs.", VF_VENDOR);
60         }
61
62         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
63         {
64                 if (!IS_LOCAL(user))
65                         return MOD_RES_PASSTHRU;
66
67                 std::string ctcpname;
68                 if (!details.IsCTCP(ctcpname) || irc::equals(ctcpname, "ACTION"))
69                         return MOD_RES_PASSTHRU;
70
71                 switch (target.type)
72                 {
73                         case MessageTarget::TYPE_CHANNEL:
74                         {
75                                 if (user->HasPrivPermission("channels/ignore-noctcp"))
76                                         return MOD_RES_PASSTHRU;
77
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)
81                                 {
82                                         User* u = member->first;
83                                         if (u->IsModeSet(ncu))
84                                                 details.exemptions.insert(u);
85                                 }
86
87                                 ModResult res = CheckExemption::Call(exemptionprov, user, c, "noctcp");
88                                 if (res == MOD_RES_ALLOW)
89                                         return MOD_RES_PASSTHRU;
90
91                                 if (c->IsModeSet(nc))
92                                 {
93                                         user->WriteNumeric(Numerics::CannotSendTo(c, "CTCPs", &nc));
94                                         return MOD_RES_DENY;
95                                 }
96
97                                 if (c->GetExtBanStatus(user, 'C') == MOD_RES_DENY)
98                                 {
99                                         user->WriteNumeric(Numerics::CannotSendTo(c, "CTCPs", 'C', "noctcp"));
100                                         return MOD_RES_DENY;
101                                 }
102                                 break;
103                         }
104                         case MessageTarget::TYPE_USER:
105                         {
106                                 if (user->HasPrivPermission("users/ignore-noctcp"))
107                                         return MOD_RES_PASSTHRU;
108
109                                 User* u = target.Get<User>();
110                                 if (u->IsModeSet(ncu))
111                                 {
112                                         user->WriteNumeric(Numerics::CannotSendTo(u, "CTCPs", &ncu));
113                                         return MOD_RES_DENY;
114                                 }
115                                 break;
116                         }
117                         case MessageTarget::TYPE_SERVER:
118                                 break;
119                 }
120                 return MOD_RES_PASSTHRU;
121         }
122
123         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
124         {
125                 tokens["EXTBAN"].push_back('C');
126         }
127 };
128
129 MODULE_INIT(ModuleNoCTCP)