From 15bb93a4ead17d14958883561e6ea143f49c1a66 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 19 Apr 2019 11:51:42 +0100 Subject: Remove the OnNamesListItem event out of the core. --- include/modules.h | 14 +--------- include/modules/names.h | 46 ++++++++++++++++++++++++++++++++ src/coremods/core_channel/cmd_names.cpp | 12 ++++----- src/coremods/core_channel/core_channel.h | 2 ++ src/modules.cpp | 1 - src/modules/m_auditorium.cpp | 7 +++-- src/modules/m_delayjoin.cpp | 7 +++-- src/modules/m_namesx.cpp | 7 +++-- src/modules/m_uhnames.cpp | 12 ++++++--- 9 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 include/modules/names.h diff --git a/include/modules.h b/include/modules.h index eca64eeec..8a672effe 100644 --- a/include/modules.h +++ b/include/modules.h @@ -226,7 +226,7 @@ enum Implementation I_OnPreChangeRealName, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnPostCommand, I_OnPostJoin, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass, - I_OnUserMessage, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric, + I_OnUserMessage, I_OnPassCompare, I_OnNumeric, I_OnPreRehash, I_OnModuleRehash, I_OnChangeIdent, I_OnSetUserIP, I_OnServiceAdd, I_OnServiceDel, I_OnUserWrite, I_END @@ -905,18 +905,6 @@ class CoreExport Module : public classbase, public usecountbase */ virtual ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass); - /** Called for every item in a NAMES list, so that modules may reformat portions of it as they see fit. - * For example NAMESX, channel mode +u and +I, and UHNAMES. - * @param issuer The user who is going to receive the NAMES list being built - * @param item The channel member being considered for inclusion - * @param prefixes The prefix character(s) to display, initially set to the prefix char of the most powerful - * prefix mode the member has, can be changed - * @param nick The nick to display, initially set to the member's nick, can be changed - * @return Return MOD_RES_PASSTHRU to allow the member to be displayed, MOD_RES_DENY to cause them to be - * excluded from this NAMES list - */ - virtual ModResult OnNamesListItem(User* issuer, Membership* item, std::string& prefixes, std::string& nick); - virtual ModResult OnNumeric(User* user, const Numeric::Numeric& numeric); /** Called whenever a local user's IP is set for the first time, or when a local user's IP changes due to diff --git a/include/modules/names.h b/include/modules/names.h new file mode 100644 index 000000000..d3e1969cc --- /dev/null +++ b/include/modules/names.h @@ -0,0 +1,46 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2019 Peter Powell + * + * 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 . + */ + + +#pragma once + +#include "event.h" + +namespace Names +{ + class EventListener; +} + +class Names::EventListener : public Events::ModuleEventListener +{ + public: + EventListener(Module* mod) + : ModuleEventListener(mod, "event/names") + { + } + + /* Called for every item in a NAMES list. + * @param issuer The user who initiated the NAMES request. + * @param memb The channel membership of the user who is being considered for inclusion. + * @param prefixes The prefix character(s) to show in front of the user's nickname. + * @param nick The nickname of the user to show. + * @return Return MOD_RES_PASSTHRU to allow the member to be displayed, MOD_RES_DENY to cause them to be + * excluded from this NAMES list + */ + virtual ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) = 0; +}; diff --git a/src/coremods/core_channel/cmd_names.cpp b/src/coremods/core_channel/cmd_names.cpp index a179cf9dc..b5cd98ec8 100644 --- a/src/coremods/core_channel/cmd_names.cpp +++ b/src/coremods/core_channel/cmd_names.cpp @@ -20,12 +20,14 @@ #include "inspircd.h" #include "core_channel.h" +#include "modules/names.h" CommandNames::CommandNames(Module* parent) : SplitCommand(parent, "NAMES", 0, 0) , secretmode(parent, "secret") , privatemode(parent, "private") , invisiblemode(parent, "invisible") + , namesevprov(parent, "event/names") { syntax = "[,]+"; } @@ -100,13 +102,9 @@ void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible nick = i->first->nick; ModResult res; - FIRST_MOD_RESULT(OnNamesListItem, res, (user, memb, prefixlist, nick)); - - // See if a module wants us to exclude this user from NAMES - if (res == MOD_RES_DENY) - continue; - - reply.Add(prefixlist, nick); + FIRST_MOD_RESULT_CUSTOM(namesevprov, Names::EventListener, OnNamesListItem, res, (user, memb, prefixlist, nick)); + if (res != MOD_RES_DENY) + reply.Add(prefixlist, nick); } reply.Flush(); diff --git a/src/coremods/core_channel/core_channel.h b/src/coremods/core_channel/core_channel.h index 096db8c0d..c054d5265 100644 --- a/src/coremods/core_channel/core_channel.h +++ b/src/coremods/core_channel/core_channel.h @@ -116,9 +116,11 @@ class CommandTopic : public SplitCommand */ class CommandNames : public SplitCommand { + private: ChanModeReference secretmode; ChanModeReference privatemode; UserModeReference invisiblemode; + Events::ModuleEventProvider namesevprov; public: /** Constructor for names. diff --git a/src/modules.cpp b/src/modules.cpp index 690ff0feb..952c115d2 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -137,7 +137,6 @@ void Module::OnBuildNeighborList(User*, IncludeChanList&, std::map& void Module::OnGarbageCollect() { DetachEvent(I_OnGarbageCollect); } ModResult Module::OnSetConnectClass(LocalUser* user, ConnectClass* myclass) { DetachEvent(I_OnSetConnectClass); return MOD_RES_PASSTHRU; } void Module::OnUserMessage(User*, const MessageTarget&, const MessageDetails&) { DetachEvent(I_OnUserMessage); } -ModResult Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { DetachEvent(I_OnNamesListItem); return MOD_RES_PASSTHRU; } ModResult Module::OnNumeric(User*, const Numeric::Numeric&) { DetachEvent(I_OnNumeric); return MOD_RES_PASSTHRU; } ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { DetachEvent(I_OnAcceptConnection); return MOD_RES_PASSTHRU; } void Module::OnSetUserIP(LocalUser*) { DetachEvent(I_OnSetUserIP); } diff --git a/src/modules/m_auditorium.cpp b/src/modules/m_auditorium.cpp index 818242795..6f47c5743 100644 --- a/src/modules/m_auditorium.cpp +++ b/src/modules/m_auditorium.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "modules/exemption.h" +#include "modules/names.h" #include "modules/who.h" class AuditoriumMode : public SimpleChannelModeHandler @@ -58,6 +59,7 @@ class JoinHook : public ClientProtocol::EventHook class ModuleAuditorium : public Module + , public Names::EventListener , public Who::EventListener { CheckExemption::EventProvider exemptionprov; @@ -69,7 +71,8 @@ class ModuleAuditorium public: ModuleAuditorium() - : Who::EventListener(this) + : Names::EventListener(this) + , Who::EventListener(this) , exemptionprov(this) , aum(this) , joinhook(this) @@ -118,7 +121,7 @@ class ModuleAuditorium return false; } - ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE + ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE { if (IsVisible(memb)) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index 469f33439..40a585909 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "modules/ctctags.h" +#include "modules/names.h" class DelayJoinMode : public ModeHandler { @@ -76,6 +77,7 @@ class JoinHook : public ClientProtocol::EventHook class ModuleDelayJoin : public Module , public CTCTags::EventListener + , public Names::EventListener { public: LocalIntExt unjoined; @@ -84,6 +86,7 @@ class ModuleDelayJoin ModuleDelayJoin() : CTCTags::EventListener(this) + , Names::EventListener(this) , unjoined("delayjoin", ExtensionItem::EXT_MEMBERSHIP, this) , joinhook(this, unjoined) , djm(this, unjoined) @@ -91,7 +94,7 @@ class ModuleDelayJoin } Version GetVersion() CXX11_OVERRIDE; - ModResult OnNamesListItem(User* issuer, Membership*, std::string& prefixes, std::string& nick) CXX11_OVERRIDE; + ModResult OnNamesListItem(LocalUser* issuer, Membership*, std::string& prefixes, std::string& nick) CXX11_OVERRIDE; void OnUserJoin(Membership*, bool, bool, CUList&) CXX11_OVERRIDE; void CleanUser(User* user); void OnUserPart(Membership*, std::string &partmessage, CUList&) CXX11_OVERRIDE; @@ -127,7 +130,7 @@ Version ModuleDelayJoin::GetVersion() return Version("Allows for delay-join channels (+D) where users don't appear to join until they speak", VF_VENDOR); } -ModResult ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) +ModResult ModuleDelayJoin::OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) { /* don't prevent the user from seeing themself */ if (issuer == memb->user) diff --git a/src/modules/m_namesx.cpp b/src/modules/m_namesx.cpp index ac15c9723..ffece5cb4 100644 --- a/src/modules/m_namesx.cpp +++ b/src/modules/m_namesx.cpp @@ -22,10 +22,12 @@ #include "inspircd.h" #include "modules/cap.h" +#include "modules/names.h" #include "modules/who.h" class ModuleNamesX : public Module + , public Names::EventListener , public Who::EventListener { private: @@ -33,7 +35,8 @@ class ModuleNamesX public: ModuleNamesX() - : Who::EventListener(this) + : Names::EventListener(this) + , Who::EventListener(this) , cap(this, "multi-prefix") { } @@ -66,7 +69,7 @@ class ModuleNamesX return MOD_RES_PASSTHRU; } - ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE + ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE { if (cap.get(issuer)) prefixes = memb->GetAllPrefixChars(); diff --git a/src/modules/m_uhnames.cpp b/src/modules/m_uhnames.cpp index a8814b343..f750c1a6e 100644 --- a/src/modules/m_uhnames.cpp +++ b/src/modules/m_uhnames.cpp @@ -21,13 +21,19 @@ #include "inspircd.h" #include "modules/cap.h" +#include "modules/names.h" -class ModuleUHNames : public Module +class ModuleUHNames + : public Module + , public Names::EventListener { + private: Cap::Capability cap; public: - ModuleUHNames() : cap(this, "userhost-in-names") + ModuleUHNames() + : Names::EventListener(this) + , cap(this, "userhost-in-names") { } @@ -59,7 +65,7 @@ class ModuleUHNames : public Module return MOD_RES_PASSTHRU; } - ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE + ModResult OnNamesListItem(LocalUser* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE { if (cap.get(issuer)) nick = memb->user->GetFullHost(); -- cgit v1.2.3