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/>.
29 #include "modules/ctctags.h"
31 // User mode +d - filter out channel messages and channel notices
32 class DeafMode : public ModeHandler
35 DeafMode(Module* Creator) : ModeHandler(Creator, "deaf", 'd', PARAM_NONE, MODETYPE_USER) { }
37 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
39 if (adding == dest->IsModeSet(this))
40 return MODEACTION_DENY;
43 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.");
45 dest->SetMode(this, adding);
46 return MODEACTION_ALLOW;
50 // User mode +D - filter out user messages and user notices
51 class PrivDeafMode : public ModeHandler
54 PrivDeafMode(Module* Creator) : ModeHandler(Creator, "privdeaf", 'D', PARAM_NONE, MODETYPE_USER)
56 if (!ServerInstance->Config->ConfValue("deaf")->getBool("enableprivdeaf"))
57 DisableAutoRegister();
60 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE
62 if (adding == dest->IsModeSet(this))
63 return MODEACTION_DENY;
66 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.");
68 dest->SetMode(this, adding);
69 return MODEACTION_ALLOW;
75 , public CTCTags::EventListener
79 PrivDeafMode privdeafmode;
80 std::string deaf_bypasschars;
81 std::string deaf_bypasschars_uline;
84 ModResult HandleChannel(User* source, Channel* target, CUList& exemptions, bool is_bypasschar, bool is_bypasschar_uline)
86 const Channel::MemberMap& ulist = target->GetUsers();
87 for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
89 User* member = i->first;
91 // Allow if the user doesn't have the mode set.
92 if (!member->IsModeSet(deafmode))
95 // Allow if the message begins with a uline char and the
96 // user is on a ulined server.
97 if (is_bypasschar_uline && member->server->IsULine())
100 // Allow if the prefix begins with a normal char and the
101 // user is not on a ulined server.
102 if (is_bypasschar && !member->server->IsULine())
105 exemptions.insert(member);
108 return MOD_RES_PASSTHRU;
111 ModResult HandleUser(User* source, User* target)
113 // Allow if the mode is not set.
114 if (!target->IsModeSet(privdeafmode))
115 return MOD_RES_PASSTHRU;
117 // Reject if the source is ulined and privdeafuline is disaled.
118 if (!privdeafuline && source->server->IsULine())
121 // Reject if the source doesn't have the right priv.
122 if (!source->HasPrivPermission("users/ignore-privdeaf"))
125 return MOD_RES_ALLOW;
130 : CTCTags::EventListener(this)
136 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
138 ConfigTag* tag = ServerInstance->Config->ConfValue("deaf");
139 deaf_bypasschars = tag->getString("bypasschars");
140 deaf_bypasschars_uline = tag->getString("bypasscharsuline");
141 privdeafuline = tag->getBool("privdeafuline", true);
144 ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
148 case MessageTarget::TYPE_CHANNEL:
149 return HandleChannel(user, target.Get<Channel>(), details.exemptions, false, false);
151 case MessageTarget::TYPE_USER:
152 return HandleUser(user, target.Get<User>());
154 case MessageTarget::TYPE_SERVER:
158 return MOD_RES_PASSTHRU;
161 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
165 case MessageTarget::TYPE_CHANNEL:
167 // If we have no bypasschars_uline in config, and this is a bypasschar (regular)
168 // Then it is obviously going to get through +d, no exemption list required
169 bool is_bypasschar = (deaf_bypasschars.find(details.text[0]) != std::string::npos);
170 if (deaf_bypasschars_uline.empty() && is_bypasschar)
171 return MOD_RES_PASSTHRU;
173 // If it matches both bypasschar and bypasschar_uline, it will get through.
174 bool is_bypasschar_uline = (deaf_bypasschars_uline.find(details.text[0]) != std::string::npos);
175 if (is_bypasschar && is_bypasschar_uline)
176 return MOD_RES_PASSTHRU;
178 return HandleChannel(user, target.Get<Channel>(), details.exemptions, is_bypasschar, is_bypasschar_uline);
181 case MessageTarget::TYPE_USER:
182 return HandleUser(user, target.Get<User>());
184 case MessageTarget::TYPE_SERVER:
188 return MOD_RES_PASSTHRU;
191 Version GetVersion() CXX11_OVERRIDE
193 return Version("Adds user mode d (deaf) which prevents users from receiving channel messages.", VF_VENDOR);
197 MODULE_INIT(ModuleDeaf)