]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_blockcolor.cpp
Rework message handling.
[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 class ModuleBlockColor : public Module
28 {
29         CheckExemption::EventProvider exemptionprov;
30         SimpleChannelModeHandler bc;
31  public:
32
33         ModuleBlockColor()
34                 : exemptionprov(this)
35                 , bc(this, "blockcolor", 'c')
36         {
37         }
38
39         void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
40         {
41                 tokens["EXTBAN"].push_back('c');
42         }
43
44         ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
45         {
46                 if ((target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user)))
47                 {
48                         Channel* c = target.Get<Channel>();
49                         ModResult res = CheckExemption::Call(exemptionprov, user, c, "blockcolor");
50
51                         if (res == MOD_RES_ALLOW)
52                                 return MOD_RES_PASSTHRU;
53
54                         if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet(bc)))
55                         {
56                                 for (std::string::iterator i = details.text.begin(); i != details.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(ERR_CANNOTSENDTOCHAN, c->name, "Can't send colors to channel (+c set)");
67                                                         return MOD_RES_DENY;
68                                                 break;
69                                         }
70                                 }
71                         }
72                 }
73                 return MOD_RES_PASSTHRU;
74         }
75
76         Version GetVersion() CXX11_OVERRIDE
77         {
78                 return Version("Provides channel mode +c to block color",VF_VENDOR);
79         }
80 };
81
82 MODULE_INIT(ModuleBlockColor)