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