]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
So much stuff changed in this one, i forgot most of it.
[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 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for unreal-style channel mode +c */
28
29 extern InspIRCd* ServerInstance;
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         Server *Srv;
62         BlockColor *bc;
63  public:
64  
65         ModuleBlockColour(Server* Me) : Module::Module(Me)
66         {
67                 Srv = Me;
68                 bc = new BlockColor(ServerInstance);
69                 Srv->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                 ServerInstance->ModeGrok->InsertMode(output,"c",4);
80         }
81         
82         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
83         {
84                 if (target_type == TYPE_CHANNEL)
85                 {
86                         chanrec* c = (chanrec*)dest;
87                         
88                         if(c->IsModeSet('c'))
89                         {
90                                 /* Replace a strlcpy(), which ran even when +c wasn't set, with this (no copies at all) -- Om */
91                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
92                                 {
93                                         switch (*i)
94                                         {
95                                                 case 2:
96                                                 case 3:
97                                                 case 15:
98                                                 case 21:
99                                                 case 22:
100                                                 case 31:
101                                                         user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
102                                                         return 1;
103                                                 break;
104                                         }
105                                 }
106                         }
107                 }
108                 return 0;
109         }
110         
111         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
112         {
113                 return OnUserPreMessage(user,dest,target_type,text,status);
114         }
115
116         virtual ~ModuleBlockColour()
117         {
118                 DELETE(bc);
119         }
120         
121         virtual Version GetVersion()
122         {
123                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
124         }
125 };
126
127
128 class ModuleBlockColourFactory : public ModuleFactory
129 {
130  public:
131         ModuleBlockColourFactory()
132         {
133         }
134         
135         ~ModuleBlockColourFactory()
136         {
137         }
138         
139         virtual Module * CreateModule(Server* Me)
140         {
141                 return new ModuleBlockColour(Me);
142         }
143         
144 };
145
146
147 extern "C" void * init_module( void )
148 {
149         return new ModuleBlockColourFactory;
150 }