]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
AMD64 warning 'fix' which tested fine when I added it seems to now...stop things...
[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) : Module::Module(Me)
34         {
35                 Srv = Me;
36                 Srv->AddExtendedMode('c',MT_CHANNEL,false,0,0);
37         }
38
39         void Implements(char* List)
40         {
41                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnExtendedMode] = 1;
42         }
43
44         virtual void On005Numeric(std::string &output)
45         {
46                 InsertMode(output,"c",4);
47         }
48         
49         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
50         {
51                 if (target_type == TYPE_CHANNEL)
52                 {
53                         chanrec* c = (chanrec*)dest;
54                         
55                         if(c->IsModeSet('c'))
56                         {
57                                 /* Replace a strlcpy(), which ran even when +c wasn't set, with this (no copies at all) -- Om */
58                                 for(unsigned int i = 0; i < text.length(); i++)
59                                 {
60                                         switch (text[i])
61                                         {
62                                                 case 2:
63                                                 case 3:
64                                                 case 15:
65                                                 case 21:
66                                                 case 22:
67                                                 case 31:
68                                                         WriteServ(user->fd,"404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
69                                                         return 1;
70                                                 break;
71                                         }
72                                 }
73                         }
74                 }
75                 return 0;
76         }
77         
78         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
79         {
80                 return OnUserPreMessage(user,dest,target_type,text,status);
81         }
82         
83         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
84         {
85                 // check if this is our mode character...
86                 if ((modechar == 'c') && (type == MT_CHANNEL))
87                 {
88                         log(DEBUG,"Allowing c change");
89                         return 1;
90                 }
91                 else
92                 {
93                         return 0;
94                 }
95         }
96
97         virtual ~ModuleBlockColour()
98         {
99         }
100         
101         virtual Version GetVersion()
102         {
103                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
104         }
105 };
106
107
108 class ModuleBlockColourFactory : public ModuleFactory
109 {
110  public:
111         ModuleBlockColourFactory()
112         {
113         }
114         
115         ~ModuleBlockColourFactory()
116         {
117         }
118         
119         virtual Module * CreateModule(Server* Me)
120         {
121                 return new ModuleBlockColour(Me);
122         }
123         
124 };
125
126
127 extern "C" void * init_module( void )
128 {
129         return new ModuleBlockColourFactory;
130 }