]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
4d1a3500d6c22aedef028de1d8b25b6f4c83547e
[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 ~ModuleBlockColor()
59         {
60                 delete Srv;
61         }
62         
63         virtual Version GetVersion()
64         {
65                 return Version(1,0,0,0);
66         }
67 };
68
69
70 class ModuleBlockColorFactory : public ModuleFactory
71 {
72  public:
73         ModuleBlockColorFactory()
74         {
75         }
76         
77         ~ModuleBlockColorFactory()
78         {
79         }
80         
81         virtual Module * CreateModule()
82         {
83                 return new ModuleBlockColor;
84         }
85         
86 };
87
88
89 extern "C" void * init_module( void )
90 {
91         return new ModuleBlockColorFactory;
92 }
93