]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
fixed some indentation and spacing in modules
[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 };
38                 ServerInstance->Modules->Attach(eventlist, this, 2);
39         }
40
41
42
43         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
44         {
45                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
46                 {
47                         Channel* c = (Channel*)dest;
48
49                         if (CHANOPS_EXEMPT(ServerInstance, 'c') && c->GetStatus(user) == STATUS_OP)
50                         {
51                                 return 0;
52                         }
53
54                         if(c->IsModeSet('c'))
55                         {
56                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
57                                 {
58                                         switch (*i)
59                                         {
60                                                 case 2:
61                                                 case 3:
62                                                 case 15:
63                                                 case 21:
64                                                 case 22:
65                                                 case 31:
66                                                         user->WriteNumeric(404, "%s %s :Can't send colours to channel (+c set)",user->nick.c_str(), c->name.c_str());
67                                                         return 1;
68                                                 break;
69                                         }
70                                 }
71                         }
72                 }
73                 return 0;
74         }
75
76         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
77         {
78                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
79         }
80
81         virtual ~ModuleBlockColour()
82         {
83                 ServerInstance->Modes->DelMode(bc);
84                 delete bc;
85         }
86
87         virtual Version GetVersion()
88         {
89                 return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
90         }
91 };
92
93 MODULE_INIT(ModuleBlockColour)