]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
m_swhois Switch to OnPostOper hook instead of using OnPostCommand
[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 /* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */
23
24 /** Handles user mode +c
25  */
26 class PrivacyMode : public ModeHandler
27 {
28  public:
29         PrivacyMode(Module* Creator) : ModeHandler(Creator, "deaf_commonchan", 'c', PARAM_NONE, MODETYPE_USER) { }
30
31         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
32         {
33                 if (adding)
34                 {
35                         if (!dest->IsModeSet('c'))
36                         {
37                                 dest->SetMode('c',true);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41                 else
42                 {
43                         if (dest->IsModeSet('c'))
44                         {
45                                 dest->SetMode('c',false);
46                                 return MODEACTION_ALLOW;
47                         }
48                 }
49
50                 return MODEACTION_DENY;
51         }
52 };
53
54 class ModulePrivacyMode : public Module
55 {
56         PrivacyMode pm;
57  public:
58         ModulePrivacyMode() : pm(this)
59         {
60                 if (!ServerInstance->Modes->AddMode(&pm))
61                         throw ModuleException("Could not add new modes!");
62                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
63                 ServerInstance->Modules->Attach(eventlist, this, 2);
64         }
65
66
67         virtual ~ModulePrivacyMode()
68         {
69         }
70
71         virtual Version GetVersion()
72         {
73                 return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
74         }
75
76         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
77         {
78                 if (target_type == TYPE_USER)
79                 {
80                         User* t = (User*)dest;
81                         if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
82                         {
83                                 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());
84                                 return MOD_RES_DENY;
85                         }
86                 }
87                 return MOD_RES_PASSTHRU;
88         }
89
90         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
91         {
92                 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
93         }
94 };
95
96
97 MODULE_INIT(ModulePrivacyMode)