]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
c63a44ea7ca931a0992f11b2e5b401f36a8fa6e3
[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         bool AllowChanOps;      
56         BlockColor *bc;
57  public:
58  
59         ModuleBlockColour(InspIRCd* Me) : Module(Me)
60         {
61                 bc = new BlockColor(ServerInstance);
62                 if (!ServerInstance->AddMode(bc, 'c'))
63                         throw ModuleException("Could not add new modes!");
64         }
65
66         void Implements(char* List)
67         {
68                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
69         }
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                                 if (!CHANOPS_EXEMPT(ServerInstance, 'c') || CHANOPS_EXEMPT(ServerInstance, 'c') && c->GetStatus(user) != STATUS_OP)
81                                 {
82                                         for (std::string::iterator i = text.begin(); i != text.end(); i++)
83                                         {
84                                                 switch (*i)
85                                                 {
86                                                         case 2:
87                                                         case 3:
88                                                         case 15:
89                                                         case 21:
90                                                         case 22:
91                                                         case 31:
92                                                                 user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
93                                                                 return 1;
94                                                         break;
95                                                 }
96                                         }
97                                 }
98                         }
99                 }
100                 return 0;
101         }
102         
103         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
104         {
105                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
106         }
107
108         virtual ~ModuleBlockColour()
109         {
110                 ServerInstance->Modes->DelMode(bc);
111                 DELETE(bc);
112         }
113         
114         virtual Version GetVersion()
115         {
116                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
117         }
118 };
119
120
121 class ModuleBlockColourFactory : public ModuleFactory
122 {
123  public:
124         ModuleBlockColourFactory()
125         {
126         }
127         
128         ~ModuleBlockColourFactory()
129         {
130         }
131         
132         virtual Module * CreateModule(InspIRCd* Me)
133         {
134                 return new ModuleBlockColour(Me);
135         }
136         
137 };
138
139
140 extern "C" DllExport void * init_module( void )
141 {
142         return new ModuleBlockColourFactory;
143 }