]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
WHEEEEE!!!!!
[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 BlockColor : public ModeHandler
29 {
30  public:
31         BlockColor() : ModeHandler('c', 0, 0, false, MODETYPE_CHANNEL, false) { }
32
33         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
34         {
35                 if (adding)
36                 {
37                         if (!channel->IsModeSet('c'))
38                         {
39                                 channel->SetMode('c',true);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43                 else
44                 {
45                         if (channel->IsModeSet('c'))
46                         {
47                                 channel->SetMode('c',false);
48                                 return MODEACTION_ALLOW;
49                         }
50                 }
51
52                 return MODEACTION_DENY;
53         }
54 };
55
56 class ModuleBlockColour : public Module
57 {
58         Server *Srv;
59         BlockColor *bc;
60  public:
61  
62         ModuleBlockColour(Server* Me) : Module::Module(Me)
63         {
64                 Srv = Me;
65                 bc = new BlockColor();
66                 Srv->AddMode(bc, 'c');
67         }
68
69         void Implements(char* List)
70         {
71                 List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
72         }
73
74         virtual void On005Numeric(std::string &output)
75         {
76                 InsertMode(output,"c",4);
77         }
78         
79         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
80         {
81                 if (target_type == TYPE_CHANNEL)
82                 {
83                         chanrec* c = (chanrec*)dest;
84                         
85                         if(c->IsModeSet('c'))
86                         {
87                                 /* Replace a strlcpy(), which ran even when +c wasn't set, with this (no copies at all) -- Om */
88                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
89                                 {
90                                         switch (*i)
91                                         {
92                                                 case 2:
93                                                 case 3:
94                                                 case 15:
95                                                 case 21:
96                                                 case 22:
97                                                 case 31:
98                                                         user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
99                                                         return 1;
100                                                 break;
101                                         }
102                                 }
103                         }
104                 }
105                 return 0;
106         }
107         
108         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
109         {
110                 return OnUserPreMessage(user,dest,target_type,text,status);
111         }
112
113         virtual ~ModuleBlockColour()
114         {
115                 DELETE(bc);
116         }
117         
118         virtual Version GetVersion()
119         {
120                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
121         }
122 };
123
124
125 class ModuleBlockColourFactory : public ModuleFactory
126 {
127  public:
128         ModuleBlockColourFactory()
129         {
130         }
131         
132         ~ModuleBlockColourFactory()
133         {
134         }
135         
136         virtual Module * CreateModule(Server* Me)
137         {
138                 return new ModuleBlockColour(Me);
139         }
140         
141 };
142
143
144 extern "C" void * init_module( void )
145 {
146         return new ModuleBlockColourFactory;
147 }