]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Added remote rehash (even to a mask)
[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()
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                 // we don't really have a limit...
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                         char ctext[MAXBUF];
65                         snprintf(ctext,MAXBUF,"%s",text.c_str());
66                         if (c->IsCustomModeSet('c'))
67                         {
68                                 if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
69                                 {
70                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
71                                         return 1;
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                         char ctext[MAXBUF];
84                         snprintf(ctext,MAXBUF,"%s",text.c_str());
85                         if (c->IsCustomModeSet('c'))
86                         {
87                                 if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
88                                 {
89                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
90                                         return 1;
91                                 }
92                         }
93                 }
94                 return 0;
95         }
96         
97         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
98         {
99                 // check if this is our mode character...
100                 if ((modechar == 'c') && (type == MT_CHANNEL))
101                 {
102                         log(DEBUG,"Allowing c change");
103                         return 1;
104                 }
105                 else
106                 {
107                         return 0;
108                 }
109         }
110
111         virtual ~ModuleBlockColor()
112         {
113                 delete Srv;
114         }
115         
116         virtual Version GetVersion()
117         {
118                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
119         }
120 };
121
122
123 class ModuleBlockColorFactory : public ModuleFactory
124 {
125  public:
126         ModuleBlockColorFactory()
127         {
128         }
129         
130         ~ModuleBlockColorFactory()
131         {
132         }
133         
134         virtual Module * CreateModule()
135         {
136                 return new ModuleBlockColor;
137         }
138         
139 };
140
141
142 extern "C" void * init_module( void )
143 {
144         return new ModuleBlockColorFactory;
145 }
146