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