]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
A ton more clear() and empty() stuff thats been lingering on the long term todo for...
[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 "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Provides support for unreal-style channel mode +c */
20
21 /** Handles the +c channel mode
22  */
23 class BlockColor : public ModeHandler
24 {
25  public:
26         BlockColor(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_CHANNEL, false) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 if (adding)
31                 {
32                         if (!channel->IsModeSet('c'))
33                         {
34                                 channel->SetMode('c',true);
35                                 return MODEACTION_ALLOW;
36                         }
37                 }
38                 else
39                 {
40                         if (channel->IsModeSet('c'))
41                         {
42                                 channel->SetMode('c',false);
43                                 return MODEACTION_ALLOW;
44                         }
45                 }
46
47                 return MODEACTION_DENY;
48         }
49 };
50
51 class ModuleBlockColour : public Module
52 {
53         bool AllowChanOps;      
54         BlockColor *bc;
55  public:
56  
57         ModuleBlockColour(InspIRCd* Me) : Module(Me)
58         {
59                 bc = new BlockColor(ServerInstance);
60                 if (!ServerInstance->AddMode(bc, 'c'))
61                         throw ModuleException("Could not add new modes!");
62         }
63
64         void Implements(char* List)
65         {
66                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
67         }
68
69
70         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
71         {
72                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
73                 {
74                         chanrec* c = (chanrec*)dest;
75                         
76                         if(c->IsModeSet('c'))
77                         {
78                                 if (!CHANOPS_EXEMPT(ServerInstance, 'c') || CHANOPS_EXEMPT(ServerInstance, 'c') && c->GetStatus(user) != STATUS_OP)
79                                 {
80                                         for (std::string::iterator i = text.begin(); i != text.end(); i++)
81                                         {
82                                                 switch (*i)
83                                                 {
84                                                         case 2:
85                                                         case 3:
86                                                         case 15:
87                                                         case 21:
88                                                         case 22:
89                                                         case 31:
90                                                                 user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
91                                                                 return 1;
92                                                         break;
93                                                 }
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" DllExport void * init_module( void )
139 {
140         return new ModuleBlockColourFactory;
141 }