]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
90e3f912a9e9ce2f0066a27a0e3cab3405139852
[user/henk/code/inspircd.git] / src / modules / m_blockcolor.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2004-2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2005, 2007 Robin Burchell <robin+git@viroteck.net>
8  *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25
26 /* $ModDesc: Provides channel mode +c to block color */
27
28 /** Handles the +c channel mode
29  */
30 class BlockColor : public SimpleChannelModeHandler
31 {
32  public:
33         BlockColor(Module* Creator) : SimpleChannelModeHandler(Creator, "blockcolor", 'c') { }
34 };
35
36 class ModuleBlockColor : public Module
37 {
38         bool AllowChanOps;
39         BlockColor bc;
40  public:
41
42         ModuleBlockColor() : bc(this)
43         {
44         }
45
46         void init()
47         {
48                 if (!ServerInstance->Modes->AddMode(&bc))
49                         throw ModuleException("Could not add new modes!");
50                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
51                 ServerInstance->Modules->Attach(eventlist, this, 3);
52         }
53
54         virtual void On005Numeric(std::string &output)
55         {
56                 ServerInstance->AddExtBanChar('c');
57         }
58
59         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
60         {
61                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
62                 {
63                         Channel* c = (Channel*)dest;
64                         ModResult res = ServerInstance->OnCheckExemption(user,c,"blockcolor");
65
66                         if (res == MOD_RES_ALLOW)
67                                 return MOD_RES_PASSTHRU;
68
69                         if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet('c')))
70                         {
71                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
72                                 {
73                                         switch (*i)
74                                         {
75                                                 case 2:
76                                                 case 3:
77                                                 case 15:
78                                                 case 21:
79                                                 case 22:
80                                                 case 31:
81                                                         user->WriteNumeric(404, "%s %s :Can't send colors to channel (+c set)",user->nick.c_str(), c->name.c_str());
82                                                         return MOD_RES_DENY;
83                                                 break;
84                                         }
85                                 }
86                         }
87                 }
88                 return MOD_RES_PASSTHRU;
89         }
90
91         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
92         {
93                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
94         }
95
96         virtual ~ModuleBlockColor()
97         {
98         }
99
100         virtual Version GetVersion()
101         {
102                 return Version("Provides channel mode +c to block color",VF_VENDOR);
103         }
104 };
105
106 MODULE_INIT(ModuleBlockColor)