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