]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictmsg.cpp
Fix being able to see the modes of private/secret channels.
[user/henk/code/inspircd.git] / src / modules / m_restrictmsg.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015-2016 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2013, 2015, 2017, 2019 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27 #include "modules/ctctags.h"
28
29 class ModuleRestrictMsg
30         : public Module
31         , public CTCTags::EventListener
32 {
33  private:
34         ModResult HandleMessage(User* user, const MessageTarget& target)
35         {
36                 if ((target.type == MessageTarget::TYPE_USER) && (IS_LOCAL(user)))
37                 {
38                         User* u = target.Get<User>();
39
40                         // message allowed if:
41                         // (1) the sender is opered
42                         // (2) the recipient is opered
43                         // (3) the recipient is on a ulined server
44                         // anything else, blocked.
45                         if (u->IsOper() || user->IsOper() || u->server->IsULine())
46                         {
47                                 return MOD_RES_PASSTHRU;
48                         }
49                         user->WriteNumeric(ERR_CANTSENDTOUSER, u->nick, "You are not permitted to send private messages to this user");
50                         return MOD_RES_DENY;
51                 }
52
53                 // however, we must allow channel messages...
54                 return MOD_RES_PASSTHRU;
55         }
56
57  public:
58         ModuleRestrictMsg()
59                 : CTCTags::EventListener(this)
60         {
61         }
62
63         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
64         {
65                 return HandleMessage(user, target);
66         }
67
68         ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
69         {
70                 return HandleMessage(user, target);
71         }
72
73         Version GetVersion() CXX11_OVERRIDE
74         {
75                 return Version("Forbids users from messaging each other, but users may still message opers and opers may message other opers", VF_VENDOR);
76         }
77 };
78
79 MODULE_INIT(ModuleRestrictMsg)