2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2012 satmd <satmd@satmd.dyndns.org>
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/>.
25 // User mode +d - filter out channel messages and channel notices
26 class DeafMode : public ModeHandler
29 DeafMode(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { }
31 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
33 if (adding == dest->IsModeSet(this))
34 return MODEACTION_DENY;
37 dest->WriteNotice("*** You have enabled user mode +d, deaf mode. This mode means you WILL NOT receive any messages from any channels you are in. If you did NOT mean to do this, use /mode " + dest->nick + " -d.");
39 dest->SetMode(this, adding);
40 return MODEACTION_ALLOW;
44 // User mode +D - filter out user messages and user notices
45 class PrivDeafMode : public ModeHandler
48 PrivDeafMode(Module* Creator) : ModeHandler(Creator, "privdeaf", 'D', PARAM_NONE, MODETYPE_USER)
50 if (!ServerInstance->Config->ConfValue("deaf")->getBool("enableprivdeaf"))
51 DisableAutoRegister();
54 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
56 if (adding == dest->IsModeSet(this))
57 return MODEACTION_DENY;
60 dest->WriteNotice("*** You have enabled user mode +D, private deaf mode. This mode means you WILL NOT receive any messages and notices from any nicks. If you did NOT mean to do this, use /mode " + dest->nick + " -D.");
62 dest->SetMode(this, adding);
63 return MODEACTION_ALLOW;
67 class ModuleDeaf : public Module
70 PrivDeafMode privdeafmode;
71 std::string deaf_bypasschars;
72 std::string deaf_bypasschars_uline;
82 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
84 ConfigTag* tag = ServerInstance->Config->ConfValue("deaf");
85 deaf_bypasschars = tag->getString("bypasschars");
86 deaf_bypasschars_uline = tag->getString("bypasscharsuline");
87 privdeafuline = tag->getBool("privdeafuline", true);
90 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
92 if (target.type == MessageTarget::TYPE_CHANNEL)
94 Channel* chan = target.Get<Channel>();
95 bool is_bypasschar = (deaf_bypasschars.find(details.text[0]) != std::string::npos);
96 bool is_bypasschar_uline = (deaf_bypasschars_uline.find(details.text[0]) != std::string::npos);
98 // If we have no bypasschars_uline in config, and this is a bypasschar (regular)
99 // Then it is obviously going to get through +d, no exemption list required
100 if (deaf_bypasschars_uline.empty() && is_bypasschar)
101 return MOD_RES_PASSTHRU;
102 // If it matches both bypasschar and bypasschar_uline, it will get through.
103 if (is_bypasschar && is_bypasschar_uline)
104 return MOD_RES_PASSTHRU;
106 const Channel::MemberMap& ulist = chan->GetUsers();
107 for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
110 if (!i->first->IsModeSet(deafmode))
113 bool is_a_uline = i->first->server->IsULine();
114 // matched a U-line only bypass
115 if (is_bypasschar_uline && is_a_uline)
117 // matched a regular bypass
118 if (is_bypasschar && !is_a_uline)
121 // don't deliver message!
122 details.exemptions.insert(i->first);
125 else if (target.type == MessageTarget::TYPE_USER)
127 User* targ = target.Get<User>();
128 if (!targ->IsModeSet(privdeafmode))
129 return MOD_RES_PASSTHRU;
131 if (!privdeafuline && user->server->IsULine())
134 if (!user->HasPrivPermission("users/ignore-privdeaf"))
138 return MOD_RES_PASSTHRU;
141 Version GetVersion() CXX11_OVERRIDE
143 return Version("Provides user modes +d and +D to block channel and user messages/notices", VF_VENDOR);
147 MODULE_INIT(ModuleDeaf)