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