]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
Add the Numerics::CannotSendTo class and switch stuff to use it.
[user/henk/code/inspircd.git] / src / modules / m_commonchans.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2017, 2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
6  *   Copyright (C) 2012 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007 Craig Edwards <brain@inspircd.org>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25 #include "modules/ctctags.h"
26
27 class ModuleCommonChans
28         : public CTCTags::EventListener
29         , public Module
30 {
31  private:
32         SimpleUserModeHandler mode;
33
34         ModResult HandleMessage(User* user, const MessageTarget& target)
35         {
36                 if (target.type != MessageTarget::TYPE_USER)
37                         return MOD_RES_PASSTHRU;
38
39                 User* targuser = target.Get<User>();
40                 if (!targuser->IsModeSet(mode) || user->SharesChannelWith(targuser))
41                         return MOD_RES_PASSTHRU;
42
43                 if (user->HasPrivPermission("users/ignore-commonchans") || user->server->IsULine())
44                         return MOD_RES_PASSTHRU;
45
46                 user->WriteNumeric(Numerics::CannotSendTo(targuser, "messages", &mode));
47                 return MOD_RES_DENY;
48         }
49
50  public:
51         ModuleCommonChans()
52                 : CTCTags::EventListener(this)
53                 , mode(this, "deaf_commonchan", 'c')
54         {
55         }
56
57         Version GetVersion() CXX11_OVERRIDE
58         {
59                 return Version("Provides user mode +c, requires users to share a common channel with you to private message you", VF_VENDOR);
60         }
61
62         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
63         {
64                 return HandleMessage(user, target);
65         }
66
67         ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
68         {
69                 return HandleMessage(user, target);
70         }
71 };
72
73 MODULE_INIT(ModuleCommonChans)