]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Fixed strcpy vs. strlcpy problem
[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                 output = temp2.substr(0,temp2.length()-1);
53         }
54         
55         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
56         {
57                 if (target_type == TYPE_CHANNEL)
58                 {
59                         chanrec* c = (chanrec*)dest;
60                         char ctext[MAXBUF];
61                         snprintf(ctext,MAXBUF,"%s",text.c_str());
62                         if (c->IsCustomModeSet('c'))
63                         {
64                                 if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
65                                 {
66                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
67                                         return 1;
68                                 }
69                         }
70                 }
71                 return 0;
72         }
73         
74         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
75         {
76                 if (target_type == TYPE_CHANNEL)
77                 {
78                         chanrec* c = (chanrec*)dest;
79                         char ctext[MAXBUF];
80                         snprintf(ctext,MAXBUF,"%s",text.c_str());
81                         if (c->IsCustomModeSet('c'))
82                         {
83                                 if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
84                                 {
85                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
86                                         return 1;
87                                 }
88                         }
89                 }
90                 return 0;
91         }
92         
93         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
94         {
95                 // check if this is our mode character...
96                 if ((modechar == 'c') && (type == MT_CHANNEL))
97                 {
98                         log(DEBUG,"Allowing c change");
99                         return 1;
100                 }
101                 else
102                 {
103                         return 0;
104                 }
105         }
106
107         virtual ~ModuleBlockColor()
108         {
109                 delete Srv;
110         }
111         
112         virtual Version GetVersion()
113         {
114                 return Version(1,0,0,0);
115         }
116 };
117
118
119 class ModuleBlockColorFactory : public ModuleFactory
120 {
121  public:
122         ModuleBlockColorFactory()
123         {
124         }
125         
126         ~ModuleBlockColorFactory()
127         {
128         }
129         
130         virtual Module * CreateModule()
131         {
132                 return new ModuleBlockColor;
133         }
134         
135 };
136
137
138 extern "C" void * init_module( void )
139 {
140         return new ModuleBlockColorFactory;
141 }
142