]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
7c961d96aab49f2bfd902d5e00dcac03638fd5f9
[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 #include "modules/exemption.h"
26
27 /** Handles the +c channel mode
28  */
29 class BlockColor : public SimpleChannelModeHandler
30 {
31  public:
32         BlockColor(Module* Creator) : SimpleChannelModeHandler(Creator, "blockcolor", 'c') { }
33 };
34
35 class ModuleBlockColor : public Module
36 {
37         CheckExemption::EventProvider exemptionprov;
38         BlockColor bc;
39  public:
40
41         ModuleBlockColor()
42                 : exemptionprov(this)
43                 , bc(this)
44         {
45         }
46
47         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
48         {
49                 tokens["EXTBAN"].push_back('c');
50         }
51
52         ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
53         {
54                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
55                 {
56                         Channel* c = (Channel*)dest;
57                         ModResult res;
58                         FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, c, "blockcolor"));
59
60                         if (res == MOD_RES_ALLOW)
61                                 return MOD_RES_PASSTHRU;
62
63                         if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet(bc)))
64                         {
65                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
66                                 {
67                                         switch (*i)
68                                         {
69                                                 case 2:
70                                                 case 3:
71                                                 case 15:
72                                                 case 21:
73                                                 case 22:
74                                                 case 31:
75                                                         user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, "Can't send colors to channel (+c set)");
76                                                         return MOD_RES_DENY;
77                                                 break;
78                                         }
79                                 }
80                         }
81                 }
82                 return MOD_RES_PASSTHRU;
83         }
84
85         Version GetVersion() CXX11_OVERRIDE
86         {
87                 return Version("Provides channel mode +c to block color",VF_VENDOR);
88         }
89 };
90
91 MODULE_INIT(ModuleBlockColor)