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