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