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