]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Fix being able to see the modes of private/secret channels.
[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 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("Provides user mode +T and channel mode +C to block 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                                 bool modeset = c->IsModeSet(nc);
92                                 if (!c->GetExtBanStatus(user, 'C').check(!modeset))
93                                 {
94                                         user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, InspIRCd::Format("Can't send CTCP to channel (%s)",
95                                                 modeset ? "+C is set" : "you're extbanned"));
96                                         return MOD_RES_DENY;
97                                 }
98                                 break;
99                         }
100                         case MessageTarget::TYPE_USER:
101                         {
102                                 if (user->HasPrivPermission("users/ignore-noctcp"))
103                                         return MOD_RES_PASSTHRU;
104
105                                 User* u = target.Get<User>();
106                                 if (u->IsModeSet(ncu))
107                                 {
108                                         user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "Can't send CTCP to user (+T is set)");
109                                         return MOD_RES_DENY;
110                                 }
111                                 break;
112                         }
113                         case MessageTarget::TYPE_SERVER:
114                                 break;
115                 }
116                 return MOD_RES_PASSTHRU;
117         }
118
119         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
120         {
121                 tokens["EXTBAN"].push_back('C');
122         }
123 };
124
125 MODULE_INIT(ModuleNoCTCP)