]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Remove the OnNamesListItem event out of the core.
authorPeter Powell <petpow@saberuk.com>
Fri, 19 Apr 2019 10:51:42 +0000 (11:51 +0100)
committerPeter Powell <petpow@saberuk.com>
Fri, 19 Apr 2019 10:51:42 +0000 (11:51 +0100)
include/modules.h
include/modules/names.h [new file with mode: 0644]
src/coremods/core_channel/cmd_names.cpp
src/coremods/core_channel/core_channel.h
src/modules.cpp
src/modules/m_auditorium.cpp
src/modules/m_delayjoin.cpp
src/modules/m_namesx.cpp
src/modules/m_uhnames.cpp

index eca64eeeccd371c7c493eae14f574f735be65d96..8a672effe30524406b7aa5633b959e80fcc168b0 100644 (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
diff --git a/include/modules/names.h b/include/modules/names.h
new file mode 100644 (file)
index 0000000..d3e1969
--- /dev/null
@@ -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;
+};
index a179cf9dcc5bf300caeede2c434398160e3eb17e..b5cd98ec841fa24b94e7b6d1d59fe53e84f75651 100644 (file)
 
 #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();
index 096db8c0d5a8f7020096f00b87d80b465ca28587..c054d5265e6c4435361e69aa526653ff67c1aaea 100644 (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.
index 690ff0feb5b4548e648ed8e503ed8649961bbff8..952c115d2be81ea3a4efec08ef47e8442dc00859 100644 (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); }
index 81824279510f5275dd77e1ac0d5aca8eff3d36a8..6f47c5743aecbe301a39ad78c07d3ddfd51fa3c0 100644 (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;
index 469f334393c36142d4976c01453322eba26b0f9f..40a585909b294a399e0042591810655b52638d83 100644 (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)
index ac15c9723d9aafe751173c81dae5c5daaae23145..ffece5cb401654e81d07a1e382e6dd5f97b3d1dd 100644 (file)
 
 #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();
index a8814b343cab8271b581372f3682e6e7aad1822d..f750c1a6e7b238ffeab1e881ce9451e255bf786a 100644 (file)
 
 #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();