]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
80fd75e7b993fc9bca61444ccc3852156d992c2b
[user/henk/code/inspircd.git] / src / modules / m_commonchans.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Peter Powell <petpow@saberuk.com>
5  *   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "modules/ctctags.h"
23
24 class ModuleCommonChans
25         : public CTCTags::EventListener
26         , public Module
27 {
28  private:
29         SimpleUserModeHandler mode;
30
31         ModResult HandleMessage(User* user, const MessageTarget& target)
32         {
33                 if (target.type != MessageTarget::TYPE_USER)
34                         return MOD_RES_PASSTHRU;
35
36                 User* targuser = target.Get<User>();
37                 if (!targuser->IsModeSet(mode) || !user->SharesChannelWith(targuser))
38                         return MOD_RES_PASSTHRU;
39
40                 if (user->HasPrivPermission("users/ignore-commonchans") || user->server->IsULine())
41                         return MOD_RES_PASSTHRU;
42
43                 user->WriteNumeric(ERR_CANTSENDTOUSER, targuser->nick, "You are not permitted to send private messages to this user (+c set)");
44                 return MOD_RES_DENY;
45         }
46
47  public:
48         ModuleCommonChans()
49                 : CTCTags::EventListener(this)
50                 , mode(this, "deaf_commonchan", 'c')
51         {
52         }
53
54         Version GetVersion() CXX11_OVERRIDE
55         {
56                 return Version("Adds user mode +c which requires users to share a common channel with you to private message you", VF_VENDOR);
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
70 MODULE_INIT(ModuleCommonChans)