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