]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
Add support for LOCKSERV/UNLOCKSERV to block/open for new connections. Thanks to...
[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                 ServerInstance->AddMode(nt, 'T');
61         }
62
63         void Implements(char* List)
64         {
65                 List[I_OnUserPreNotice] = 1;
66         }
67         
68         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
69         {
70                 if (target_type == TYPE_CHANNEL)
71                 {
72                         chanrec* c = (chanrec*)dest;
73                         if (c->IsModeSet('T'))
74                         {
75                                 if ((ServerInstance->ULine(user->server)) || (c->GetStatus(user) == STATUS_OP) || (c->GetStatus(user) == STATUS_HOP))
76                                 {
77                                         // ops and halfops can still /NOTICE the channel
78                                         return 0;
79                                 }
80                                 else
81                                 {
82                                         user->WriteServ("404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);
83                                         return 1;
84                                 }
85                         }
86                 }
87                 return 0;
88         }
89
90         virtual ~ModuleNoNotice()
91         {
92                 ServerInstance->Modes->DelMode(nt);
93                 DELETE(nt);
94         }
95         
96         virtual Version GetVersion()
97         {
98                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
99         }
100 };
101
102
103 class ModuleNoNoticeFactory : public ModuleFactory
104 {
105  public:
106         ModuleNoNoticeFactory()
107         {
108         }
109         
110         ~ModuleNoNoticeFactory()
111         {
112         }
113         
114         virtual Module * CreateModule(InspIRCd* Me)
115         {
116                 return new ModuleNoNotice(Me);
117         }
118         
119 };
120
121
122 extern "C" void * init_module( void )
123 {
124         return new ModuleNoNoticeFactory;
125 }
126