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