]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
c87d2b283370ebcc7a0f375d44ae77cdf827651f
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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                         strlcpy(ctext,text.c_str(),MAXBUF);
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 15:
85                                                 case 21:
86                                                 case 22:
87                                                 case 31:
88                                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
89                                                         return 1;
90                                                 break;
91                                         }
92                                 }
93                         }
94                 }
95                 return 0;
96         }
97         
98         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
99         {
100                 if (target_type == TYPE_CHANNEL)
101                 {
102                         chanrec* c = (chanrec*)dest;
103                         char ctext[MAXBUF];
104                         char *ctptr = ctext;
105                         strlcpy(ctext,text.c_str(),MAXBUF);
106
107
108                         if (c->IsCustomModeSet('c'))
109                         {
110                                 /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */
111                                 while (ctptr && *ctptr)
112                                 {
113                                         switch (*ctptr++)
114                                         {
115                                                 case 2:
116                                                 case 3:
117                                                 case 15:
118                                                 case 21:
119                                                 case 22:
120                                                 case 31:
121                                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
122                                                         return 1;
123                                                 break;
124                                         }
125                                 }
126                         }
127                 }
128                 return 0;
129         }
130         
131         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
132         {
133                 // check if this is our mode character...
134                 if ((modechar == 'c') && (type == MT_CHANNEL))
135                 {
136                         log(DEBUG,"Allowing c change");
137                         return 1;
138                 }
139                 else
140                 {
141                         return 0;
142                 }
143         }
144
145         virtual ~ModuleBlockColor()
146         {
147         }
148         
149         virtual Version GetVersion()
150         {
151                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
152         }
153 };
154
155
156 class ModuleBlockColorFactory : public ModuleFactory
157 {
158  public:
159         ModuleBlockColorFactory()
160         {
161         }
162         
163         ~ModuleBlockColorFactory()
164         {
165         }
166         
167         virtual Module * CreateModule(Server* Me)
168         {
169                 return new ModuleBlockColor(Me);
170         }
171         
172 };
173
174
175 extern "C" void * init_module( void )
176 {
177         return new ModuleBlockColorFactory;
178 }
179