]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
WHEEEEE!!!!!
[user/henk/code/inspircd.git] / src / modules / m_noctcp.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 +c */
26
27 class NoCTCP : public ModeHandler
28 {
29  public:
30         NoCTCP() : ModeHandler('C', 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('C'))
37                         {
38                                 channel->SetMode('C',true);
39                                 return MODEACTION_ALLOW;
40                         }
41                 }
42                 else
43                 {
44                         if (channel->IsModeSet('C'))
45                         {
46                                 channel->SetMode('C',false);
47                                 return MODEACTION_ALLOW;
48                         }
49                 }
50
51                 return MODEACTION_DENY;
52         }
53 };
54
55 class ModuleNoCTCP : public Module
56 {
57         Server *Srv;
58         NoCTCP* nc;
59         
60  public:
61  
62         ModuleNoCTCP(Server* Me)
63                 : Module::Module(Me)
64         {
65                 Srv = Me;
66                 nc = new NoCTCP();
67                 Srv->AddMode(nc, 'C');
68         }
69
70         void Implements(char* List)
71         {
72                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
73         }
74
75         virtual void On005Numeric(std::string &output)
76         {
77                 InsertMode(output,"C",4);
78         }
79         
80         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
81         {
82                 return OnUserPreNotice(user,dest,target_type,text,status);
83         }
84         
85         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
86         {
87                 if (target_type == TYPE_CHANNEL)
88                 {
89                         chanrec* c = (chanrec*)dest;
90                         if (c->IsModeSet('C'))
91                         {
92                                 if ((text.length()) && (text[0] == '\1'))
93                                 {
94                                         if (strncmp(text.c_str(),"\1ACTION ",8))
95                                         {
96                                                 user->WriteServ("492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
97                                                 return 1;
98                                         }
99                                 }
100                         }
101                 }
102                 return 0;
103         }
104
105         virtual ~ModuleNoCTCP()
106         {
107                 DELETE(nc);
108         }
109
110         virtual Version GetVersion()
111         {
112                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
113         }
114 };
115
116
117 class ModuleNoCTCPFactory : public ModuleFactory
118 {
119  public:
120         ModuleNoCTCPFactory()
121         {
122         }
123         
124         ~ModuleNoCTCPFactory()
125         {
126         }
127         
128         virtual Module * CreateModule(Server* Me)
129         {
130                 return new ModuleNoCTCP(Me);
131         }
132         
133 };
134
135
136 extern "C" void * init_module( void )
137 {
138         return new ModuleNoCTCPFactory;
139 }
140