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