-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
*
- * InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ * Copyright (C) 2013, 2017, 2019-2020 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ * Copyright (C) 2012 Attila Molnar <attilamolnar@hush.com>
+ * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2007 Craig Edwards <brain@inspircd.org>
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
*
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "inspircd.h"
-/* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */
+#include "inspircd.h"
+#include "modules/ctctags.h"
-/** Handles user mode +c
- */
-class PrivacyMode : public ModeHandler
+class ModuleCommonChans
+ : public CTCTags::EventListener
+ , public Module
{
- public:
- PrivacyMode(Module* Creator) : ModeHandler(Creator, "deaf_commonchan", 'c', PARAM_NONE, MODETYPE_USER) { }
+ private:
+ SimpleUserModeHandler mode;
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
+ ModResult HandleMessage(User* user, const MessageTarget& target)
{
- if (adding)
- {
- if (!dest->IsModeSet('c'))
- {
- dest->SetMode('c',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('c'))
- {
- dest->SetMode('c',false);
- return MODEACTION_ALLOW;
- }
- }
+ if (target.type != MessageTarget::TYPE_USER)
+ return MOD_RES_PASSTHRU;
- return MODEACTION_DENY;
- }
-};
+ User* targuser = target.Get<User>();
+ if (!targuser->IsModeSet(mode) || user->SharesChannelWith(targuser))
+ return MOD_RES_PASSTHRU;
-class ModulePrivacyMode : public Module
-{
- PrivacyMode pm;
- public:
- ModulePrivacyMode() : pm(this)
- {
- if (!ServerInstance->Modes->AddMode(&pm))
- throw ModuleException("Could not add new modes!");
- Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
- ServerInstance->Modules->Attach(eventlist, this, 2);
- }
+ if (user->HasPrivPermission("users/ignore-commonchans") || user->server->IsULine())
+ return MOD_RES_PASSTHRU;
+ user->WriteNumeric(Numerics::CannotSendTo(targuser, "messages", &mode));
+ return MOD_RES_DENY;
+ }
- virtual ~ModulePrivacyMode()
+ public:
+ ModuleCommonChans()
+ : CTCTags::EventListener(this)
+ , mode(this, "deaf_commonchan", 'c')
{
}
- virtual Version GetVersion()
+ Version GetVersion() CXX11_OVERRIDE
{
- return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR);
+ return Version("Adds user mode c (deaf_commonchan) which requires users to have a common channel before they can privately message each other.", VF_VENDOR);
}
- virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+ ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
{
- if (target_type == TYPE_USER)
- {
- User* t = (User*)dest;
- if (!IS_OPER(user) && (t->IsModeSet('c')) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t))
- {
- user->WriteNumeric(ERR_CANTSENDTOUSER, "%s %s :You are not permitted to send private messages to this user (+c set)", user->nick.c_str(), t->nick.c_str());
- return MOD_RES_DENY;
- }
- }
- return MOD_RES_PASSTHRU;
+ return HandleMessage(user, target);
}
- virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+ ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE
{
- return OnUserPreMessage(user, dest, target_type, text, status, exempt_list);
+ return HandleMessage(user, target);
}
};
-
-MODULE_INIT(ModulePrivacyMode)
+MODULE_INIT(ModuleCommonChans)