]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Decide that it wasn't quite appropriate :(
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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 using namespace std;
18
19 #include <stdio.h>
20 #include <sstream>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24 #include "helperfuncs.h"
25
26 /* $ModDesc: Provides support for unreal-style channel mode +c */
27
28 class ModuleBlockColour : public Module
29 {
30         Server *Srv;
31  public:
32  
33         ModuleBlockColour(Server* Me)
34                 : Module::Module(Me)
35         {
36                 Srv = Me;
37                 Srv->AddExtendedMode('c',MT_CHANNEL,false,0,0);
38         }
39
40         void Implements(char* List)
41         {
42                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1;
43         }
44
45         virtual void On005Numeric(std::string &output)
46         {
47                 InsertMode(output,"c",4);
48         }
49         
50         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
51         {
52                 if (target_type == TYPE_CHANNEL)
53                 {
54                         chanrec* c = (chanrec*)dest;
55                         char ctext[MAXBUF];
56                         char *ctptr = ctext;
57                         strlcpy(ctext,text.c_str(),MAXBUF);
58
59
60                         if (c->IsCustomModeSet('c'))
61                         {
62                                 /* Instead of using strchr() here, do our own loop. Hopefully faster. --w00t */
63                                 while (ctptr && *ctptr)
64                                 {
65                                         switch (*ctptr++)
66                                         {
67                                                 case 2:
68                                                 case 3:
69                                                 case 15:
70                                                 case 21:
71                                                 case 22:
72                                                 case 31:
73                                                         WriteServ(user->fd,"404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
74                                                         return 1;
75                                                 break;
76                                         }
77                                 }
78                         }
79                 }
80                 return 0;
81         }
82         
83         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
84         {
85                 return OnUserPreMessage(user,dest,target_type,text,status);
86         }
87         
88         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
89         {
90                 // check if this is our mode character...
91                 if ((modechar == 'c') && (type == MT_CHANNEL))
92                 {
93                         log(DEBUG,"Allowing c change");
94                         return 1;
95                 }
96                 else
97                 {
98                         return 0;
99                 }
100         }
101
102         virtual ~ModuleBlockColour()
103         {
104         }
105         
106         virtual Version GetVersion()
107         {
108                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
109         }
110 };
111
112
113 class ModuleBlockColourFactory : public ModuleFactory
114 {
115  public:
116         ModuleBlockColourFactory()
117         {
118         }
119         
120         ~ModuleBlockColourFactory()
121         {
122         }
123         
124         virtual Module * CreateModule(Server* Me)
125         {
126                 return new ModuleBlockColour(Me);
127         }
128         
129 };
130
131
132 extern "C" void * init_module( void )
133 {
134         return new ModuleBlockColourFactory;
135 }
136