]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Add config <options:disablehmac> to support disabling of HMAC, and tidy up to detect...
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include <sstream>
16 #include "users.h"
17 #include "channels.h"
18 #include "modules.h"
19 #include "inspircd.h"
20
21 /* $ModDesc: Provides support for unreal-style channel mode +c */
22
23 /** Handles the +c channel mode
24  */
25 class BlockColor : public ModeHandler
26 {
27  public:
28         BlockColor(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_CHANNEL, false) { }
29
30         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
31         {
32                 if (adding)
33                 {
34                         if (!channel->IsModeSet('c'))
35                         {
36                                 channel->SetMode('c',true);
37                                 return MODEACTION_ALLOW;
38                         }
39                 }
40                 else
41                 {
42                         if (channel->IsModeSet('c'))
43                         {
44                                 channel->SetMode('c',false);
45                                 return MODEACTION_ALLOW;
46                         }
47                 }
48
49                 return MODEACTION_DENY;
50         }
51 };
52
53 class ModuleBlockColour : public Module
54 {
55         
56         BlockColor *bc;
57  public:
58  
59         ModuleBlockColour(InspIRCd* Me) : Module::Module(Me)
60         {
61                 
62                 bc = new BlockColor(ServerInstance);
63                 if (!ServerInstance->AddMode(bc, 'c'))
64                         throw ModuleException("Could not add new modes!");
65         }
66
67         void Implements(char* List)
68         {
69                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
70         }
71
72         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
73         {
74                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
75                 {
76                         chanrec* c = (chanrec*)dest;
77                         
78                         if(c->IsModeSet('c'))
79                         {
80                                 /* Replace a strlcpy(), which ran even when +c wasn't set, with this (no copies at all) -- Om */
81                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
82                                 {
83                                         switch (*i)
84                                         {
85                                                 case 2:
86                                                 case 3:
87                                                 case 15:
88                                                 case 21:
89                                                 case 22:
90                                                 case 31:
91                                                         user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
92                                                         return 1;
93                                                 break;
94                                         }
95                                 }
96                         }
97                 }
98                 return 0;
99         }
100         
101         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
102         {
103                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
104         }
105
106         virtual ~ModuleBlockColour()
107         {
108                 ServerInstance->Modes->DelMode(bc);
109                 DELETE(bc);
110         }
111         
112         virtual Version GetVersion()
113         {
114                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
115         }
116 };
117
118
119 class ModuleBlockColourFactory : public ModuleFactory
120 {
121  public:
122         ModuleBlockColourFactory()
123         {
124         }
125         
126         ~ModuleBlockColourFactory()
127         {
128         }
129         
130         virtual Module * CreateModule(InspIRCd* Me)
131         {
132                 return new ModuleBlockColour(Me);
133         }
134         
135 };
136
137
138 extern "C" void * init_module( void )
139 {
140         return new ModuleBlockColourFactory;
141 }