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