2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
5 * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "modules/exemption.h"
27 /** Handles the +B channel mode
29 class BlockCaps : public SimpleChannelModeHandler
32 BlockCaps(Module* Creator) : SimpleChannelModeHandler(Creator, "blockcaps", 'B') { }
35 class ModuleBlockCAPS : public Module
37 CheckExemption::EventProvider exemptionprov;
50 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
52 tokens["EXTBAN"].push_back('B');
55 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
57 if (target_type == TYPE_CHANNEL)
59 if ((!IS_LOCAL(user)) || (text.length() < minlen) || (text == "\1ACTION\1") || (text == "\1ACTION"))
60 return MOD_RES_PASSTHRU;
62 Channel* c = (Channel*)dest;
64 FIRST_MOD_RESULT_CUSTOM(exemptionprov, CheckExemption::EventListener, OnCheckExemption, res, (user, c, "blockcaps"));
66 if (res == MOD_RES_ALLOW)
67 return MOD_RES_PASSTHRU;
69 if (!c->GetExtBanStatus(user, 'B').check(!c->IsModeSet(bc)))
71 std::string::size_type caps = 0;
72 unsigned int offset = 0;
73 // Ignore the beginning of the text if it's a CTCP ACTION (/me)
74 if (!text.compare(0, 8, "\1ACTION ", 8))
77 for (std::string::const_iterator i = text.begin() + offset; i != text.end(); ++i)
78 caps += capsmap[(unsigned char)*i];
80 if (((caps * 100) / text.length()) >= percent)
82 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, c->name, InspIRCd::Format("Your message cannot contain %d%% or more capital letters if it's longer than %d characters", percent, minlen));
87 return MOD_RES_PASSTHRU;
90 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
92 ConfigTag* tag = ServerInstance->Config->ConfValue("blockcaps");
93 percent = tag->getInt("percent", 100, 1, 100);
94 minlen = tag->getInt("minlen", 1, 1, ServerInstance->Config->Limits.MaxLine);
95 std::string hmap = tag->getString("capsmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
96 memset(capsmap, 0, sizeof(capsmap));
97 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
98 capsmap[(unsigned char)*n] = 1;
101 Version GetVersion() CXX11_OVERRIDE
103 return Version("Provides support to block all-CAPS channel messages and notices", VF_VENDOR);
107 MODULE_INIT(ModuleBlockCAPS)