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