]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
d46e5a9d6f36e4044cdd0a97226ab4e7424a3789
[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
16 /* $ModDesc: Provides support for unreal-style channel mode +c */
17
18 /** Handles the +c channel mode
19  */
20 class BlockColor : public ModeHandler
21 {
22  public:
23         BlockColor(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_CHANNEL, false) { }
24
25         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
26         {
27                 if (adding)
28                 {
29                         if (!channel->IsModeSet('c'))
30                         {
31                                 channel->SetMode('c',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (channel->IsModeSet('c'))
38                         {
39                                 channel->SetMode('c',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class ModuleBlockColour : public Module
49 {
50         bool AllowChanOps;      
51         BlockColor *bc;
52  public:
53  
54         ModuleBlockColour(InspIRCd* Me) : Module(Me)
55         {
56                 bc = new BlockColor(ServerInstance);
57                 if (!ServerInstance->AddMode(bc, 'c'))
58                         throw ModuleException("Could not add new modes!");
59         }
60
61         void Implements(char* List)
62         {
63                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
64         }
65
66
67         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
68         {
69                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
70                 {
71                         chanrec* c = (chanrec*)dest;
72                         
73                         if(c->IsModeSet('c'))
74                         {
75                                 if (!CHANOPS_EXEMPT(ServerInstance, 'c') || CHANOPS_EXEMPT(ServerInstance, 'c') && c->GetStatus(user) != STATUS_OP)
76                                 {
77                                         for (std::string::iterator i = text.begin(); i != text.end(); i++)
78                                         {
79                                                 switch (*i)
80                                                 {
81                                                         case 2:
82                                                         case 3:
83                                                         case 15:
84                                                         case 21:
85                                                         case 22:
86                                                         case 31:
87                                                                 user->WriteServ("404 %s %s :Can't send colours to channel (+c set)",user->nick, c->name);
88                                                                 return 1;
89                                                         break;
90                                                 }
91                                         }
92                                 }
93                         }
94                 }
95                 return 0;
96         }
97         
98         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
99         {
100                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
101         }
102
103         virtual ~ModuleBlockColour()
104         {
105                 ServerInstance->Modes->DelMode(bc);
106                 DELETE(bc);
107         }
108         
109         virtual Version GetVersion()
110         {
111                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
112         }
113 };
114
115 MODULE_INIT(ModuleBlockColour)