X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_commonchans.cpp;h=f3c206a4492bf17c4b6015f990820e59d91b04ef;hb=e59cb85871f75b7603c63c6cd274d57536cf6794;hp=d91ab1231237cf56011ba2a71335cab44cf4831e;hpb=ac7defcd3e52695dcf5e5150e9fe3e1624205e64;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp index d91ab1231..f3c206a44 100644 --- a/src/modules/m_commonchans.cpp +++ b/src/modules/m_commonchans.cpp @@ -1,6 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2019 Peter Powell * Copyright (C) 2007 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can @@ -18,61 +19,52 @@ #include "inspircd.h" +#include "modules/ctctags.h" -/* $ModDesc: Adds user mode +c, which if set, users must be on a common channel with you to private message you */ - -/** Handles user mode +c - */ -class PrivacyMode : public SimpleUserModeHandler +class ModuleCommonChans + : public CTCTags::EventListener + , public Module { - public: - PrivacyMode(Module* Creator) : SimpleUserModeHandler(Creator, "deaf_commonchan", 'c') { } -}; + private: + SimpleUserModeHandler mode; -class ModulePrivacyMode : public Module -{ - PrivacyMode pm; - public: - ModulePrivacyMode() : pm(this) + ModResult HandleMessage(User* user, const MessageTarget& target) { - } + if (target.type != MessageTarget::TYPE_USER) + return MOD_RES_PASSTHRU; - void init() - { - if (!ServerInstance->Modes->AddMode(&pm)) - throw ModuleException("Could not add new modes!"); - Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice }; - ServerInstance->Modules->Attach(eventlist, this, 2); + 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(ERR_CANTSENDTOUSER, targuser->nick, "You are not permitted to send private messages to this user (+c is set)"); + 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("Provides user mode +c, requires users to share a common channel with you to private message you", 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)