]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
Add extra parameter to OnUserPreNotice and OnUserPrePrivmsg, CUList &exempt_list...
[user/henk/code/inspircd.git] / src / modules / m_nonotice.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 unreal-style channel mode +T */
25
26 class NoNotice : public ModeHandler
27 {
28  public:
29         NoNotice(InspIRCd* Instance) : ModeHandler(Instance, 'T', 0, 0, false, MODETYPE_CHANNEL, false) { }
30
31         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
32         {
33                 if (adding)
34                 {
35                         if (!channel->IsModeSet('T'))
36                         {
37                                 channel->SetMode('T',true);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41                 else
42                 {
43                         if (channel->IsModeSet('T'))
44                         {
45                                 channel->SetMode('T',false);
46                                 return MODEACTION_ALLOW;
47                         }
48                 }
49
50                 return MODEACTION_DENY;
51         }
52 };
53
54 class ModuleNoNotice : public Module
55 {
56         
57         NoNotice* nt;
58  public:
59  
60         ModuleNoNotice(InspIRCd* Me)
61                 : Module::Module(Me)
62         {
63                 
64                 nt = new NoNotice(ServerInstance);
65                 ServerInstance->AddMode(nt, 'T');
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnUserPreNotice] = 1;
71         }
72         
73         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
74         {
75                 if (target_type == TYPE_CHANNEL)
76                 {
77                         chanrec* c = (chanrec*)dest;
78                         if (c->IsModeSet('T'))
79                         {
80                                 if ((ServerInstance->ULine(user->server)) || (c->GetStatus(user) == STATUS_OP) || (c->GetStatus(user) == STATUS_HOP))
81                                 {
82                                         // ops and halfops can still /NOTICE the channel
83                                         return 0;
84                                 }
85                                 else
86                                 {
87                                         user->WriteServ("404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);
88                                         return 1;
89                                 }
90                         }
91                 }
92                 return 0;
93         }
94
95         virtual ~ModuleNoNotice()
96         {
97                 ServerInstance->Modes->DelMode(nt);
98                 DELETE(nt);
99         }
100         
101         virtual Version GetVersion()
102         {
103                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
104         }
105 };
106
107
108 class ModuleNoNoticeFactory : public ModuleFactory
109 {
110  public:
111         ModuleNoNoticeFactory()
112         {
113         }
114         
115         ~ModuleNoNoticeFactory()
116         {
117         }
118         
119         virtual Module * CreateModule(InspIRCd* Me)
120         {
121                 return new ModuleNoNotice(Me);
122         }
123         
124 };
125
126
127 extern "C" void * init_module( void )
128 {
129         return new ModuleNoNoticeFactory;
130 }
131