]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Replace [cC]olour with [cC]olor
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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(Module* Creator) : SimpleChannelModeHandler(Creator, "blockcolor", 'c') { }
24 };
25
26 class ModuleBlockColor : public Module
27 {
28         bool AllowChanOps;
29         BlockColor bc;
30  public:
31
32         ModuleBlockColor() : bc(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                         ModResult res = ServerInstance->OnCheckExemption(user,c,"blockcolor");
51
52                         if (res == MOD_RES_ALLOW)
53                                 return MOD_RES_PASSTHRU;
54
55                         if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet('c')))
56                         {
57                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
58                                 {
59                                         switch (*i)
60                                         {
61                                                 case 2:
62                                                 case 3:
63                                                 case 15:
64                                                 case 21:
65                                                 case 22:
66                                                 case 31:
67                                                         user->WriteNumeric(404, "%s %s :Can't send colors to channel (+c set)",user->nick.c_str(), c->name.c_str());
68                                                         return MOD_RES_DENY;
69                                                 break;
70                                         }
71                                 }
72                         }
73                 }
74                 return MOD_RES_PASSTHRU;
75         }
76
77         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
78         {
79                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
80         }
81
82         virtual ~ModuleBlockColor()
83         {
84         }
85
86         virtual Version GetVersion()
87         {
88                 return Version("Provides support for unreal-style channel mode +c",VF_VENDOR);
89         }
90 };
91
92 MODULE_INIT(ModuleBlockColor)