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