Remove the OnNamesListItem event out of the core.

This commit is contained in:
Peter Powell 2019-04-19 11:51:42 +01:00
parent d5d1311145
commit 15bb93a4ea
9 changed files with 78 additions and 30 deletions

View File

@ -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

46
include/modules/names.h Normal file
View File

@ -0,0 +1,46 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2019 Peter Powell <petpow@saberuk.com>
*
* 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/>.
*/
#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;
};

View File

@ -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 = "<channel>[,<channel>]+";
}
@ -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();

View File

@ -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.

View File

@ -137,7 +137,6 @@ void Module::OnBuildNeighborList(User*, IncludeChanList&, std::map<User*,bool>&
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); }

View File

@ -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;

View File

@ -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)

View File

@ -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();

View File

@ -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();