]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Change the OnNamesListItem() hook to return ModResult
authorAttila Molnar <attilamolnar@hush.com>
Sun, 20 Apr 2014 12:05:21 +0000 (14:05 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Sun, 20 Apr 2014 12:05:21 +0000 (14:05 +0200)
Return MOD_RES_DENY to exclude the user from the NAMES list

include/modules.h
src/channels.cpp
src/modules.cpp
src/modules/m_auditorium.cpp
src/modules/m_delayjoin.cpp
src/modules/m_namesx.cpp
src/modules/m_uhnames.cpp

index 9c0b22b6c075fd90a2cbdba4eaa11919ff64ac25..6717854104f06572d4da8137f535d7781dd33c7f 100644 (file)
@@ -1041,10 +1041,9 @@ class CoreExport Module : public classbase, public usecountbase
 #endif
 
        /** 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. If the nick is set to an empty string by any
-        * module, then this will cause the nickname not to be displayed at all.
+        * For example NAMESX, channel mode +u and +I, and UHNAMES.
         */
-       virtual void OnNamesListItem(User* issuer, Membership* item, std::string &prefixes, std::string &nick);
+       virtual ModResult OnNamesListItem(User* issuer, Membership* item, std::string& prefixes, std::string& nick);
 
        virtual ModResult OnNumeric(User* user, unsigned int numeric, const std::string &text);
 
index 46f9cfe894d2f1edf9608e5a01842b17a272d9bb..a98b4ff87c702062086b5ca9b22a61e115376ec9 100644 (file)
@@ -653,10 +653,11 @@ void Channel::UserList(User* user, bool has_user)
                        prefixlist.push_back(prefix);
                nick = i->first->nick;
 
-               FOREACH_MOD(OnNamesListItem, (user, memb, prefixlist, nick));
+               ModResult res;
+               FIRST_MOD_RESULT(OnNamesListItem, res, (user, memb, prefixlist, nick));
 
-               /* Nick was nuked, a module wants us to skip it */
-               if (nick.empty())
+               // See if a module wants us to exclude this user from NAMES
+               if (res == MOD_RES_DENY)
                        continue;
 
                if (list.size() + prefixlist.length() + nick.length() + 1 > maxlen)
index c27147820579c78aa459c677d35063a244de7090..8396866578e0aaa15a4d16e07b7b0cd89bf7baf9 100644 (file)
@@ -151,7 +151,7 @@ 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::OnText(User*, void*, int, const std::string&, char, CUList&) { DetachEvent(I_OnText); }
-void           Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { DetachEvent(I_OnNamesListItem); }
+ModResult      Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { DetachEvent(I_OnNamesListItem); return MOD_RES_PASSTHRU; }
 ModResult      Module::OnNumeric(User*, unsigned int, const std::string&) { 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::OnSendWhoLine(User*, const std::vector<std::string>&, User*, Membership*, std::string&) { DetachEvent(I_OnSendWhoLine); }
index 8ec80ef469820f14c295110f0ed8ed8a68a0ff62..60bdd258277ab325751c29079a5eb5e0693b764d 100644 (file)
@@ -85,19 +85,16 @@ class ModuleAuditorium : public Module
                return false;
        }
 
-       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
+       ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE
        {
-               // Some module already hid this from being displayed, don't bother
-               if (nick.empty())
-                       return;
-
                if (IsVisible(memb))
-                       return;
+                       return MOD_RES_PASSTHRU;
 
                if (CanSee(issuer, memb))
-                       return;
+                       return MOD_RES_PASSTHRU;
 
-               nick.clear();
+               // Don't display this user in the NAMES list
+               return MOD_RES_DENY;
        }
 
        /** Build CUList for showing this join/part/kick */
index dd07710bdf3e695a7acec82ff256a5977c433b49..b3165c7bec221bf221ab93f0a74387f2c6d73548 100644 (file)
@@ -45,7 +45,7 @@ class ModuleDelayJoin : public Module
        }
 
        Version GetVersion() CXX11_OVERRIDE;
-       void OnNamesListItem(User* issuer, Membership*, std::string &prefixes, std::string &nick) CXX11_OVERRIDE;
+       ModResult OnNamesListItem(User* 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;
@@ -80,15 +80,17 @@ Version ModuleDelayJoin::GetVersion()
        return Version("Allows for delay-join channels (+D) where users don't appear to join until they speak", VF_VENDOR);
 }
 
-void ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
+ModResult ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick)
 {
        /* don't prevent the user from seeing themself */
        if (issuer == memb->user)
-               return;
+               return MOD_RES_PASSTHRU;
 
        /* If the user is hidden by delayed join, hide them from the NAMES list */
        if (unjoined.get(memb))
-               nick.clear();
+               return MOD_RES_DENY;
+
+       return MOD_RES_PASSTHRU;
 }
 
 static void populate(CUList& except, Membership* memb)
index 4dc5ff468f721da7d5b0408f95368c369bc96b0f..f211b01d88a75af838c527b283ef68c81517750d 100644 (file)
@@ -59,16 +59,12 @@ class ModuleNamesX : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
+       ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE
        {
-               if (!cap.ext.get(issuer))
-                       return;
-
-               /* Some module hid this from being displayed, dont bother */
-               if (nick.empty())
-                       return;
+               if (cap.ext.get(issuer))
+                       prefixes = memb->GetAllPrefixChars();
 
-               prefixes = memb->GetAllPrefixChars();
+               return MOD_RES_PASSTHRU;
        }
 
        void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, std::string& line) CXX11_OVERRIDE
index 2534afb9748d847a8ea704d93d8077a298e7904f..0a171c4dc7731a9a71e16217dbcd6b526fb90ac3 100644 (file)
@@ -59,15 +59,12 @@ class ModuleUHNames : public Module
                return MOD_RES_PASSTHRU;
        }
 
-       void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick) CXX11_OVERRIDE
+       ModResult OnNamesListItem(User* issuer, Membership* memb, std::string& prefixes, std::string& nick) CXX11_OVERRIDE
        {
-               if (!cap.ext.get(issuer))
-                       return;
+               if (cap.ext.get(issuer))
+                       nick = memb->user->GetFullHost();
 
-               if (nick.empty())
-                       return;
-
-               nick = memb->user->GetFullHost();
+               return MOD_RES_PASSTHRU;
        }
 
        void OnEvent(Event& ev) CXX11_OVERRIDE