]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
d0423dfe9583e13f9516adfad552c585692718af
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 SimpleChannelModeHandler
21 {
22  public:
23         BlockColor(InspIRCd* Instance, Module* Creator) : SimpleChannelModeHandler(Instance, Creator, 'c') { }
24 };
25
26 class ModuleBlockColour : public Module
27 {
28         bool AllowChanOps;
29         BlockColor bc;
30  public:
31
32         ModuleBlockColour(InspIRCd* Me) : Module(Me), bc(Me, this)
33         {
34                 if (!ServerInstance->Modes->AddMode(&bc))
35                         throw ModuleException("Could not add new modes!");
36                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
37                 ServerInstance->Modules->Attach(eventlist, this, 3);
38         }
39
40         virtual void On005Numeric(std::string &output)
41         {
42                 ServerInstance->AddExtBanChar('c');
43         }
44
45         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
46         {
47                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
48                 {
49                         Channel* c = (Channel*)dest;
50
51                         if (CHANOPS_EXEMPT(ServerInstance, 'c') && c->GetPrefixValue(user) == OP_VALUE)
52                         {
53                                 return MOD_RES_PASSTHRU;
54                         }
55
56                         if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet('c')))
57                         {
58                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
59                                 {
60                                         switch (*i)
61                                         {
62                                                 case 2:
63                                                 case 3:
64                                                 case 15:
65                                                 case 21:
66                                                 case 22:
67                                                 case 31:
68                                                         user->WriteNumeric(404, "%s %s :Can't send colours to channel (+c set)",user->nick.c_str(), c->name.c_str());
69                                                         return MOD_RES_DENY;
70                                                 break;
71                                         }
72                                 }
73                         }
74                 }
75                 return MOD_RES_PASSTHRU;
76         }
77
78         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
79         {
80                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
81         }
82
83         virtual ~ModuleBlockColour()
84         {
85                 ServerInstance->Modes->DelMode(&bc);
86         }
87
88         virtual Version GetVersion()
89         {
90                 return Version("Provides support for unreal-style channel mode +c",VF_COMMON|VF_VENDOR,API_VERSION);
91         }
92 };
93
94 MODULE_INIT(ModuleBlockColour)