2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
6 * Copyright (C) 2013, 2017, 2019 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2008, 2010 Craig Edwards <brain@inspircd.org>
11 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
12 * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 // User mode +d - filter out channel messages and channel notices
31 class DeafMode : public ModeHandler
34 DeafMode(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { }
36 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
38 if (adding == dest->IsModeSet(this))
39 return MODEACTION_DENY;
42 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.");
44 dest->SetMode(this, adding);
45 return MODEACTION_ALLOW;
49 // User mode +D - filter out user messages and user notices
50 class PrivDeafMode : public ModeHandler
53 PrivDeafMode(Module* Creator) : ModeHandler(Creator, "privdeaf", 'D', PARAM_NONE, MODETYPE_USER)
55 if (!ServerInstance->Config->ConfValue("deaf")->getBool("enableprivdeaf"))
56 DisableAutoRegister();
59 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
61 if (adding == dest->IsModeSet(this))
62 return MODEACTION_DENY;
65 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.");
67 dest->SetMode(this, adding);
68 return MODEACTION_ALLOW;
72 class ModuleDeaf : public Module
75 PrivDeafMode privdeafmode;
76 std::string deaf_bypasschars;
77 std::string deaf_bypasschars_uline;
87 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
89 ConfigTag* tag = ServerInstance->Config->ConfValue("deaf");
90 deaf_bypasschars = tag->getString("bypasschars");
91 deaf_bypasschars_uline = tag->getString("bypasscharsuline");
92 privdeafuline = tag->getBool("privdeafuline", true);
95 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
99 case MessageTarget::TYPE_CHANNEL:
101 Channel* chan = target.Get<Channel>();
102 bool is_bypasschar = (deaf_bypasschars.find(details.text[0]) != std::string::npos);
103 bool is_bypasschar_uline = (deaf_bypasschars_uline.find(details.text[0]) != std::string::npos);
105 // If we have no bypasschars_uline in config, and this is a bypasschar (regular)
106 // Then it is obviously going to get through +d, no exemption list required
107 if (deaf_bypasschars_uline.empty() && is_bypasschar)
108 return MOD_RES_PASSTHRU;
109 // If it matches both bypasschar and bypasschar_uline, it will get through.
110 if (is_bypasschar && is_bypasschar_uline)
111 return MOD_RES_PASSTHRU;
113 const Channel::MemberMap& ulist = chan->GetUsers();
114 for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
117 if (!i->first->IsModeSet(deafmode))
120 bool is_a_uline = i->first->server->IsULine();
121 // matched a U-line only bypass
122 if (is_bypasschar_uline && is_a_uline)
124 // matched a regular bypass
125 if (is_bypasschar && !is_a_uline)
128 // don't deliver message!
129 details.exemptions.insert(i->first);
133 case MessageTarget::TYPE_USER:
135 User* targ = target.Get<User>();
136 if (!targ->IsModeSet(privdeafmode))
137 return MOD_RES_PASSTHRU;
139 if (!privdeafuline && user->server->IsULine())
142 if (!user->HasPrivPermission("users/ignore-privdeaf"))
147 case MessageTarget::TYPE_SERVER:
151 return MOD_RES_PASSTHRU;
154 Version GetVersion() CXX11_OVERRIDE
156 return Version("Provides user modes +d and +D to block channel and user messages/notices", VF_VENDOR);
160 MODULE_INIT(ModuleDeaf)