]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Last set converted to 'Implements'
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.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 <sstream>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24 #include "helperfuncs.h"
25
26 /* $ModDesc: Provides support for unreal-style channel mode +c */
27
28 class ModuleBlockColor : public Module
29 {
30         Server *Srv;
31  public:
32  
33         ModuleBlockColor(Server* Me)
34                 : Module::Module(Me)
35         {
36                 Srv = Me;
37                 Srv->AddExtendedMode('c',MT_CHANNEL,false,0,0);
38         }
39
40         void Implements(char* List)
41         {
42                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1;
43         }
44
45         virtual void On005Numeric(std::string &output)
46         {
47                 // we don't really have a limit...
48                 std::stringstream line(output);
49                 std::string temp1, temp2;
50                 while (!line.eof())
51                 {
52                         line >> temp1;
53                         if (temp1.substr(0,10) == "CHANMODES=")
54                         {
55                                 // append the chanmode to the end
56                                 temp1 = temp1.substr(10,temp1.length());
57                                 temp1 = "CHANMODES=" + temp1 + "c";
58                         }
59                         temp2 = temp2 + temp1 + " ";
60                 }
61                 if (temp2.length())
62                         output = temp2.substr(0,temp2.length()-1);
63         }
64         
65         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
66         {
67                 if (target_type == TYPE_CHANNEL)
68                 {
69                         chanrec* c = (chanrec*)dest;
70                         char ctext[MAXBUF];
71                         char *ctptr = ctext;
72                         snprintf(ctext,MAXBUF,"%s",text.c_str());
73
74
75                         if (c->IsCustomModeSet('c'))
76                         {
77                                 /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */
78                                 while (ctptr && *ctptr)
79                                 {
80                                         switch (*ctptr)
81                                         {
82                                                 case 2:
83                                                 case 3:
84                                                 case 31:
85                                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
86                                                         return 1;
87                                                         break;
88                                         }
89
90                                         *ctptr++;
91                                 }
92                         }
93                 }
94                 return 0;
95         }
96         
97         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
98         {
99                 if (target_type == TYPE_CHANNEL)
100                 {
101                         chanrec* c = (chanrec*)dest;
102                         char ctext[MAXBUF];
103                         char *ctptr = ctext;
104                         snprintf(ctext,MAXBUF,"%s",text.c_str());
105
106
107                         if (c->IsCustomModeSet('c'))
108                         {
109                                 /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */
110                                 while (ctptr && *ctptr)
111                                 {
112                                         switch (*ctptr)
113                                         {
114                                                 case 2:
115                                                 case 3:
116                                                 case 31:
117                                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
118                                                         return 1;
119                                                         break;
120                                         }
121
122                                         ctptr++;
123                                 }
124                         }
125                 }
126                 return 0;
127         }
128         
129         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
130         {
131                 // check if this is our mode character...
132                 if ((modechar == 'c') && (type == MT_CHANNEL))
133                 {
134                         log(DEBUG,"Allowing c change");
135                         return 1;
136                 }
137                 else
138                 {
139                         return 0;
140                 }
141         }
142
143         virtual ~ModuleBlockColor()
144         {
145         }
146         
147         virtual Version GetVersion()
148         {
149                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
150         }
151 };
152
153
154 class ModuleBlockColorFactory : public ModuleFactory
155 {
156  public:
157         ModuleBlockColorFactory()
158         {
159         }
160         
161         ~ModuleBlockColorFactory()
162         {
163         }
164         
165         virtual Module * CreateModule(Server* Me)
166         {
167                 return new ModuleBlockColor(Me);
168         }
169         
170 };
171
172
173 extern "C" void * init_module( void )
174 {
175         return new ModuleBlockColorFactory;
176 }
177