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