]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Added m_blockcolor, implements unreal-style mode +c for color blocking
[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         
13  public:
14  
15         ModuleBlockColor()
16         {
17                 Srv = new Server;
18                 Srv->AddExtendedMode('c',MT_CHANNEL,false,0,0);
19         }
20         
21         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text)
22         {
23                 if (target_type == TYPE_CHANNEL)
24                 {
25                         chanrec* c = (chanrec*)dest;
26                         char ctext[MAXBUF];
27                         snprintf(ctext,MAXBUF,"%s",text.c_str());
28                         if (c->IsCustomModeSet('c'))
29                         {
30                                 if (strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31))
31                                 {
32                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
33                                         return 1;
34                                 }
35                         }
36                 }
37                 return 0;
38         }
39         
40         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text)
41         {
42                 if (target_type == TYPE_CHANNEL)
43                 {
44                         chanrec* c = (chanrec*)dest;
45                         char ctext[MAXBUF];
46                         snprintf(ctext,MAXBUF,"%s",text.c_str());
47                         if (c->IsCustomModeSet('c'))
48                         {
49                                 if (strchr(ctext,'\2')) || (strchr(ctext,'\3')) || (strchr(ctext,31))
50                                 {
51                                         WriteServ(user->fd,"404 %s %s :Can't send colors to channel (+c set)",user->nick, c->name);
52                                         return 1;
53                                 }
54                         }
55                 }
56                 return 0;
57         }
58         
59         virtual ~ModuleBlockColor()
60         {
61                 delete Srv;
62         }
63         
64         virtual Version GetVersion()
65         {
66                 return Version(1,0,0,0);
67         }
68 };
69
70
71 class ModuleBlockColorFactory : public ModuleFactory
72 {
73  public:
74         ModuleBlockColorFactory()
75         {
76         }
77         
78         ~ModuleBlockColorFactory()
79         {
80         }
81         
82         virtual Module * CreateModule()
83         {
84                 return new ModuleBlockColor;
85         }
86         
87 };
88
89
90 extern "C" void * init_module( void )
91 {
92         return new ModuleBlockColorFactory;
93 }
94