X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_commonchans.cpp;h=23a1472c2ac2f387046a4f7d9717e04f13df5d6a;hb=6cfabb0064cab52bbbab59974e53dc0fa1954da7;hp=1e84719554a7151c95b525faa70a1970b4a98dd0;hpb=2630a87bb13b089e6d0fdcff4bcd0f3a9612e52f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp index 1e8471955..23a1472c2 100644 --- a/src/modules/m_commonchans.cpp +++ b/src/modules/m_commonchans.cpp @@ -1,92 +1,73 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/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, bool) + 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(); + if (!targuser->IsModeSet(mode) || user->SharesChannelWith(targuser)) + return MOD_RES_PASSTHRU; -class ModulePrivacyMode : public Module -{ - PrivacyMode pm; - public: - ModulePrivacyMode(InspIRCd* Me) : Module(Me), pm(Me) - { - 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') { - ServerInstance->Modes->DelMode(&pm); } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { - return Version("$Id$", 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->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 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)