]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
Change to Duration for second param
[user/henk/code/inspircd.git] / src / modules / m_commonchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */
17
18 /** Handles user mode +c
19  */
20 class PrivacyMode : public ModeHandler
21 {
22  public:
23         PrivacyMode(Module* Creator) : ModeHandler(Creator, "deaf_commonchan", 'c', PARAM_NONE, MODETYPE_USER) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
26         {
27                 if (adding)
28                 {
29                         if (!dest->IsModeSet('c'))
30                         {
31                                 dest->SetMode('c',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (dest->IsModeSet('c'))
38                         {
39                                 dest->SetMode('c',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class ModulePrivacyMode : public Module
49 {
50         PrivacyMode pm;
51  public:
52         ModulePrivacyMode() : pm(this)
53         {
54                 if (!ServerInstance->Modes->AddMode(&pm))
55                         throw ModuleException("Could not add new modes!");
56                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
57                 ServerInstance->Modules->Attach(eventlist, this, 2);
58         }
59
60
61         virtual ~ModulePrivacyMode()
62         {
63         }
64
65         virtual Version GetVersion()
66         {
67                 return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_COMMON|VF_VENDOR);
68         }
69
70         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
71         {
72                 if (target_type == TYPE_USER)
73                 {
74                         User* t = (User*)dest;
75                         if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
76                         {
77                                 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());
78                                 return MOD_RES_DENY;
79                         }
80                 }
81                 return MOD_RES_PASSTHRU;
82         }
83
84         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
85         {
86                 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
87         }
88 };
89
90
91 MODULE_INIT(ModulePrivacyMode)