]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
58ee4da8b221ca9392d52b3f7acec022ab517668
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 #include <stdio.h>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6
7 /* $ModDesc: Provides support for unreal-style channel mode +c */
8
9 class ModuleBlockColor : public Module
10 {
11         Server *Srv;
12  public:
13  
14         ModuleBlockColor()
15         {
16                 Srv = new Server;
17                 Srv->AddExtendedMode('c',MT_CHANNEL,false,0,0);
18         }
19         
20         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text)
21         {
22                 if (target_type == TYPE_CHANNEL)
23                 {
24                         chanrec* c = (chanrec*)dest;
25                         char ctext[MAXBUF];
26                         snprintf(ctext,MAXBUF,"%s",text.c_str());
27                         if (c->IsCustomModeSet('c'))
28                         {
29                                 if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
30                                 {
31                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
32                                         return 1;
33                                 }
34                         }
35                 }
36                 return 0;
37         }
38         
39         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text)
40         {
41                 if (target_type == TYPE_CHANNEL)
42                 {
43                         chanrec* c = (chanrec*)dest;
44                         char ctext[MAXBUF];
45                         snprintf(ctext,MAXBUF,"%s",text.c_str());
46                         if (c->IsCustomModeSet('c'))
47                         {
48                                 if ((strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31)))
49                                 {
50                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
51                                         return 1;
52                                 }
53                         }
54                 }
55                 return 0;
56         }
57         
58         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
59         {
60                 // check if this is our mode character...
61                 if ((modechar == 'c') && (type == MT_CHANNEL))
62                 {
63                         return 1;
64                 }
65                 else
66                 {
67                         return 0;
68                 }
69         }
70
71         virtual ~ModuleBlockColor()
72         {
73                 delete Srv;
74         }
75         
76         virtual Version GetVersion()
77         {
78                 return Version(1,0,0,0);
79         }
80 };
81
82
83 class ModuleBlockColorFactory : public ModuleFactory
84 {
85  public:
86         ModuleBlockColorFactory()
87         {
88         }
89         
90         ~ModuleBlockColorFactory()
91         {
92         }
93         
94         virtual Module * CreateModule()
95         {
96                 return new ModuleBlockColor;
97         }
98         
99 };
100
101
102 extern "C" void * init_module( void )
103 {
104         return new ModuleBlockColorFactory;
105 }
106