]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
Fix to m_redirect to prevent circular link to self
[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                 std::stringstream line(output);
48                 std::string temp1, temp2;
49                 while (!line.eof())
50                 {
51                         line >> temp1;
52                         if (temp1.substr(0,10) == "CHANMODES=")
53                         {
54                                 // append the chanmode to the end
55                                 temp1 = temp1.substr(10,temp1.length());
56                                 temp1 = "CHANMODES=" + temp1 + "C";
57                         }
58                         temp2 = temp2 + temp1 + " ";
59                 }
60                 if (temp2.length())
61                         output = temp2.substr(0,temp2.length()-1);
62         }
63         
64         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
65         {
66                 if (target_type == TYPE_CHANNEL)
67                 {
68                         chanrec* c = (chanrec*)dest;
69                         if (c->IsCustomModeSet('C'))
70                         {
71                                 if ((text.length()) && (text[0] == '\1'))
72                                 {
73                                         if (strncmp(text.c_str(),"\1ACTION ",8))
74                                         {
75                                                 WriteServ(user->fd,"492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
76                                                 return 1;
77                                         }
78                                 }
79                         }
80                 }
81                 return 0;
82         }
83         
84         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
85         {
86                 if (target_type == TYPE_CHANNEL)
87                 {
88                         chanrec* c = (chanrec*)dest;
89                         if (c->IsCustomModeSet('C'))
90                         {
91                                 if ((text.length()) && (text[0] == '\1'))
92                                 {
93                                         if (strncmp(text.c_str(),"\1ACTION ",8))
94                                         {
95                                                 WriteServ(user->fd,"492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
96                                                 return 1;
97                                         }
98                                 }
99                         }
100                 }
101                 return 0;
102         }
103         
104         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
105         {
106                 // check if this is our mode character...
107                 if ((modechar == 'C') && (type == MT_CHANNEL))
108                 {
109                         log(DEBUG,"Allowing C change");
110                         return 1;
111                 }
112                 else
113                 {
114                         return 0;
115                 }
116         }
117
118         virtual ~ModuleNoCTCP()
119         {
120         }
121         
122         virtual Version GetVersion()
123         {
124                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
125         }
126 };
127
128
129 class ModuleNoCTCPFactory : public ModuleFactory
130 {
131  public:
132         ModuleNoCTCPFactory()
133         {
134         }
135         
136         ~ModuleNoCTCPFactory()
137         {
138         }
139         
140         virtual Module * CreateModule(Server* Me)
141         {
142                 return new ModuleNoCTCP(Me);
143         }
144         
145 };
146
147
148 extern "C" void * init_module( void )
149 {
150         return new ModuleNoCTCPFactory;
151 }
152