]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_commonchans.cpp
Some more to fix still, modules probably wont load correctly atm
[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         void Implements(char* List)
62         {
63                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
64         }
65         
66         virtual ~ModulePrivacyMode()
67         {
68                 ServerInstance->Modes->DelMode(pm);
69                 DELETE(pm);
70         }
71         
72         virtual Version GetVersion()
73         {
74                 return Version(1,1,0,0, VF_COMMON|VF_VENDOR, API_VERSION);
75         }
76
77         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
78         {
79                 if (target_type == TYPE_USER)
80                 {
81                         User* t = (User*)dest;
82                         if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
83                         {
84                                 user->WriteServ("531 %s %s :You are not permitted to send private messages to this user (+c set)", user->nick, t->nick);
85                                 return 1;
86                         }
87                 }
88                 return 0;
89         }
90
91         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
92         {
93                 return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
94         }
95 };
96
97
98 MODULE_INIT(ModulePrivacyMode)