]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
413769ba46e1c859773d7cbb1655c78504045c94
[user/henk/code/inspircd.git] / src / modules / m_commonchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_USER, false) { }
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(InspIRCd* Me) : Module(Me)
53         {
54                 pm = new PrivacyMode(ServerInstance);
55                 if (!ServerInstance->AddMode(pm))
56                         throw ModuleException("Could not add new modes!");
57                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
58                 ServerInstance->Modules->Attach(eventlist, this, 2);
59         }
60
61         
62         virtual ~ModulePrivacyMode()
63         {
64                 ServerInstance->Modes->DelMode(pm);
65                 delete pm;
66         }
67         
68         virtual Version GetVersion()
69         {
70                 return Version(1,1,0,0, VF_COMMON|VF_VENDOR, API_VERSION);
71         }
72
73         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
74         {
75                 if (target_type == TYPE_USER)
76                 {
77                         User* t = (User*)dest;
78                         if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
79                         {
80                                 user->WriteServ("531 %s %s :You are not permitted to send private messages to this user (+c set)", user->nick, t->nick);
81                                 return 1;
82                         }
83                 }
84                 return 0;
85         }
86
87         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
88         {
89                 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
90         }
91 };
92
93
94 MODULE_INIT(ModulePrivacyMode)