]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
5871f5f9dfada6aa47ef335dbd97cfdbb61fb964
[user/henk/code/inspircd.git] / src / modules / m_commonchans.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 /** Handles user mode +c
23  */
24 class PrivacyMode : public SimpleUserModeHandler
25 {
26  public:
27         PrivacyMode(Module* Creator) : SimpleUserModeHandler(Creator, "deaf_commonchan", 'c') { }
28 };
29
30 class ModulePrivacyMode : public Module
31 {
32         PrivacyMode pm;
33  public:
34         ModulePrivacyMode() : pm(this)
35         {
36         }
37
38         void init() CXX11_OVERRIDE
39         {
40                 ServerInstance->Modules->AddService(pm);
41         }
42
43         Version GetVersion() CXX11_OVERRIDE
44         {
45                 return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
46         }
47
48         ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
49         {
50                 if (target_type == TYPE_USER)
51                 {
52                         User* t = (User*)dest;
53                         if (!user->IsOper() && (t->IsModeSet(pm)) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
54                         {
55                                 user->WriteNumeric(ERR_CANTSENDTOUSER, "%s %s :You are not permitted to send private messages to this user (+c set)", user->nick.c_str(), t->nick.c_str());
56                                 return MOD_RES_DENY;
57                         }
58                 }
59                 return MOD_RES_PASSTHRU;
60         }
61 };
62
63 MODULE_INIT(ModulePrivacyMode)