]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_noctcp.cpp
a3c82bd151bf5253575a4d17ef495040d916576d
[user/henk/code/inspircd.git] / src / modules / m_noctcp.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 #include <stdio.h>
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21 #include "helperfuncs.h"
22
23 /* $ModDesc: Provides support for unreal-style channel mode +c */
24
25 class ModuleNoCTCP : public Module
26 {
27         Server *Srv;
28         
29  public:
30  
31         ModuleNoCTCP()
32         {
33                 Srv = new Server;
34                 Srv->AddExtendedMode('C',MT_CHANNEL,false,0,0);
35         }
36
37         virtual void On005Numeric(std::string &output)
38         {
39                 std::stringstream line(output);
40                 std::string temp1, temp2;
41                 while (!line.eof())
42                 {
43                         line >> temp1;
44                         if (temp1.substr(0,10) == "CHANMODES=")
45                         {
46                                 // append the chanmode to the end
47                                 temp1 = temp1.substr(10,temp1.length());
48                                 temp1 = "CHANMODES=" + temp1 + "C";
49                         }
50                         temp2 = temp2 + temp1 + " ";
51                 }
52                 if (temp2.length())
53                         output = temp2.substr(0,temp2.length()-1);
54         }
55         
56         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
57         {
58                 if (target_type == TYPE_CHANNEL)
59                 {
60                         chanrec* c = (chanrec*)dest;
61                         if (c->IsCustomModeSet('C'))
62                         {
63                                 if ((text.length()) && (text[0] == '\1'))
64                                 {
65                                         if (strncmp(text.c_str(),"\1ACTION ",8))
66                                         {
67                                                 WriteServ(user->fd,"492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
68                                                 return 1;
69                                         }
70                                 }
71                         }
72                 }
73                 return 0;
74         }
75         
76         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
77         {
78                 if (target_type == TYPE_CHANNEL)
79                 {
80                         chanrec* c = (chanrec*)dest;
81                         if (c->IsCustomModeSet('C'))
82                         {
83                                 if ((text.length()) && (text[0] == '\1'))
84                                 {
85                                         if (strncmp(text.c_str(),"\1ACTION ",8))
86                                         {
87                                                 WriteServ(user->fd,"492 %s %s :Can't send CTCP to channel (+C set)",user->nick, c->name);
88                                                 return 1;
89                                         }
90                                 }
91                         }
92                 }
93                 return 0;
94         }
95         
96         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
97         {
98                 // check if this is our mode character...
99                 if ((modechar == 'C') && (type == MT_CHANNEL))
100                 {
101                         log(DEBUG,"Allowing C change");
102                         return 1;
103                 }
104                 else
105                 {
106                         return 0;
107                 }
108         }
109
110         virtual ~ModuleNoCTCP()
111         {
112                 delete Srv;
113         }
114         
115         virtual Version GetVersion()
116         {
117                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
118         }
119 };
120
121
122 class ModuleNoCTCPFactory : public ModuleFactory
123 {
124  public:
125         ModuleNoCTCPFactory()
126         {
127         }
128         
129         ~ModuleNoCTCPFactory()
130         {
131         }
132         
133         virtual Module * CreateModule()
134         {
135                 return new ModuleNoCTCP;
136         }
137         
138 };
139
140
141 extern "C" void * init_module( void )
142 {
143         return new ModuleNoCTCPFactory;
144 }
145