]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_deaf.cpp
Someone is getting slapped for this; the new hidesplits/hidebans behavior doesn't...
[user/henk/code/inspircd.git] / src / modules / m_deaf.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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 /* $ModDesc: Provides support for ircu style usermode +d (deaf to channel messages and channel notices) */
20
21 /** User mode +d - filter out channel messages and channel notices
22  */
23 class User_d : public ModeHandler
24 {
25  public:
26         User_d(InspIRCd* Instance) : ModeHandler(Instance, 'd', 0, 0, false, MODETYPE_USER, false) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 if (adding)
31                 {
32                         if (!dest->IsModeSet('d'))
33                         {
34                                 dest->SetMode('d',true);
35                                 return MODEACTION_ALLOW;
36                         }
37                 }
38                 else
39                 {
40                         if (dest->IsModeSet('d'))
41                         {
42                                 dest->SetMode('d',false);
43                                 return MODEACTION_ALLOW;
44                         }
45                 }
46                 return MODEACTION_DENY;
47         }
48 };
49
50 class ModuleDeaf : public Module
51 {
52         User_d* m1;
53  public:
54         ModuleDeaf(InspIRCd* Me)
55                 : Module::Module(Me)
56         {
57                 m1 = new User_d(ServerInstance);
58                 if (!ServerInstance->AddMode(m1, 'd'))
59                         throw ModuleException("Could not add new modes!");
60         }
61
62         void Implements(char* List)
63         {
64                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnBuildExemptList] = 1;
65         }
66
67         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
68         {
69                 return PreText(user, dest, target_type, text, status, exempt_list);
70         }
71
72         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
73         {
74                 return PreText(user, dest, target_type, text, status, exempt_list);
75         }
76
77         virtual void OnBuildExemptList(MessageType message_type, chanrec* chan, userrec* sender, char status, CUList &exempt_list)
78         {
79                 CUList *ulist;
80                 switch (status)
81                 {
82                         case '@':
83                                 ulist = chan->GetOppedUsers();
84                                 break;
85                         case '%':
86                                 ulist = chan->GetHalfoppedUsers();
87                                 break;
88                         case '+':
89                                 ulist = chan->GetVoicedUsers();
90                                 break;
91                         default:
92                                 ulist = chan->GetUsers();
93                                 break;
94                 }
95
96                 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
97                 {
98                         if (IS_LOCAL(i->second))
99                         {
100                                 if (i->second->IsModeSet('d'))
101                                 {
102                                         exempt_list[i->second] = i->second;
103                                 }
104                         }
105                 }
106         }
107
108         virtual int PreText(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
109         {
110                 if ((target_type == TYPE_CHANNEL) & (IS_LOCAL(user)))
111                 {
112                         chanrec* chan = (chanrec*)dest;
113                         if (chan)
114                         {
115                                 this->OnBuildExemptList(MSG_PRIVMSG, chan, user, status, exempt_list);
116                         }
117                 }
118                 return 0;
119         }
120
121         virtual ~ModuleDeaf()
122         {
123                 ServerInstance->Modes->DelMode(m1);
124                 DELETE(m1);
125         }
126
127         virtual Version GetVersion()
128         {
129                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
130         }
131
132 };
133
134
135 class ModuleDeafFactory : public ModuleFactory
136 {
137  public:
138         ModuleDeafFactory()
139         {
140         }
141         
142         ~ModuleDeafFactory()
143         {
144         }
145         
146         virtual Module * CreateModule(InspIRCd* Me)
147         {
148                 return new ModuleDeaf(Me);
149         }
150         
151 };
152
153
154 extern "C" void * init_module( void )
155 {
156         return new ModuleDeafFactory;
157 }
158