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