X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_commonchans.cpp;h=23a1472c2ac2f387046a4f7d9717e04f13df5d6a;hb=HEAD;hp=631fd2b2bc11dac5c009fa16137f62f6a8a7467f;hpb=cadc11999ee28545e9beb92de116c151832af5c4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp index 631fd2b2b..23a1472c2 100644 --- a/src/modules/m_commonchans.cpp +++ b/src/modules/m_commonchans.cpp @@ -1,98 +1,73 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2007 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * Copyright (C) 2013, 2017, 2019-2020 Sadie Powell + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2012 Attila Molnar + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2007 Craig Edwards * - * 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 . */ -#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(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_USER, false) { } + 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; - } - } - - return MODEACTION_DENY; + if (target.type != MessageTarget::TYPE_USER) + return MOD_RES_PASSTHRU; + + User* targuser = target.Get(); + if (!targuser->IsModeSet(mode) || user->SharesChannelWith(targuser)) + return MOD_RES_PASSTHRU; + + if (user->HasPrivPermission("users/ignore-commonchans") || user->server->IsULine()) + return MOD_RES_PASSTHRU; + + user->WriteNumeric(Numerics::CannotSendTo(targuser, "messages", &mode)); + return MOD_RES_DENY; } -}; -class ModulePrivacyMode : public Module -{ - PrivacyMode* pm; public: - ModulePrivacyMode(InspIRCd* Me) : Module(Me) + ModuleCommonChans() + : CTCTags::EventListener(this) + , mode(this, "deaf_commonchan", 'c') { - pm = new PrivacyMode(ServerInstance); - if (!ServerInstance->AddMode(pm)) - throw ModuleException("Could not add new modes!"); - Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice }; - ServerInstance->Modules->Attach(eventlist, this, 2); } - void Implements(char* List) - { - List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1; - } - - virtual ~ModulePrivacyMode() + Version GetVersion() CXX11_OVERRIDE { - ServerInstance->Modes->DelMode(pm); - DELETE(pm); - } - - virtual Version GetVersion() - { - return Version(1,1,0,0, VF_COMMON|VF_VENDOR, API_VERSION); + 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 int 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->WriteServ("531 %s %s :You are not permitted to send private messages to this user (+c set)", user->nick, t->nick); - return 1; - } - } - return 0; + return HandleMessage(user, target); } - virtual int 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)