]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add OnSendWhoLine hook, and use it in the oper hiding modules
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:51:56 +0000 (00:51 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:51:56 +0000 (00:51 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11650 e03df62e-2008-0410-955e-edbf42e46eb7

include/modules.h
src/commands/cmd_who.cpp
src/modules.cpp
src/modules/m_hideoper.cpp
src/modules/m_invisible.cpp

index cb8ffdadac1f927c10d3a5bb9ac8db8c4ad97b6d..ebfa52b366e58d3a1f5f5e6e6fd18d757696f5e2 100644 (file)
@@ -428,7 +428,7 @@ enum Implementation
        I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnUserList, I_OnPostCommand, I_OnPostJoin,
        I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
        I_OnText, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookIO,
-       I_OnHostCycle, I_OnPreRehash, I_OnModuleRehash,
+       I_OnHostCycle, I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine,
        I_END
 };
 
@@ -1413,6 +1413,14 @@ class CoreExport Module : public Extensible
         * even if it is enabled.
         */
        virtual ModResult OnHostCycle(User* user);
+
+       /** Called whenever a result from /WHO is about to be returned
+        * @param source The user running the /WHO query
+        * @param user The user that this line of the query is about
+        * @param channel The channel being queried (or NULL if not a channel query)
+        * @param line The raw line to send; modifiable, if empty no line will be returned.
+        */
+       virtual void OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line);
 };
 
 
index 489c668c0c7eb717cd9231ec77d4d697cd301323..a85e00fa3295456922ad36073cfe22aeed099637 100644 (file)
@@ -171,7 +171,11 @@ void CommandWho::SendWhoLine(User* user, const std::string &initial, Channel* ch
        }
 
        wholine = wholine + (ch ? ch->GetPrefixChar(u) : (chlast ? chlast->GetPrefixChar(u) : "")) + " :0 " + u->fullname;
-       whoresults.push_back(wholine);
+
+       FOREACH_MOD(I_OnSendWhoLine, OnSendWhoLine(user, u, ch, wholine));
+
+       if (!wholine.empty())
+               whoresults.push_back(wholine);
 }
 
 CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *user)
index c5c8aa2cae22ac54c0f40f899f7757c9574dfc69..ab2975d7cc236dbe030cee01a90cff60d32c3994 100644 (file)
@@ -198,6 +198,7 @@ void                Module::OnNamesListItem(User*, User*, Channel*, std::string&, std::string&
 ModResult      Module::OnNumeric(User*, unsigned int, const std::string&) { return MOD_RES_PASSTHRU; }
 void           Module::OnHookIO(EventHandler*, ListenSocketBase*) { }
 ModResult      Module::OnHostCycle(User*) { return MOD_RES_PASSTHRU; }
+void           Module::OnSendWhoLine(User*, User*, Channel*, std::string&) { }
 
 ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
 {
index b19ecb97c15529e5c0d99eec750a90582034b157..757f2d9af0083e0cbf66d1ed9dffcac616848505 100644 (file)
@@ -86,6 +86,17 @@ class ModuleHideOper : public Module
 
                return MOD_RES_PASSTHRU;
        }
+
+       void OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line)
+       {
+               if (user->IsModeSet('H') && !source->HasPrivPermission("users/auspex"))
+               {
+                       // hide the "*" that marks the user as an oper from the /WHO line
+                       std::string::size_type pos = line.find("* ");
+                       if (pos != std::string::npos)
+                               line.erase(pos);
+               }
+       }
 };
 
 
index 1d8c8a38541e1285dfc68ab75d03a98b741ab5c0..678b9cc4952217e26840c2a3e5fbb21578cdd95b 100644 (file)
@@ -117,8 +117,11 @@ class ModuleInvisible : public Module
 
                /* Yeah i know people can take this out. I'm not about to obfuscate code just to be a pain in the ass. */
                ServerInstance->Users->ServerNoticeAll("*** m_invisible.so has just been loaded on this network. For more information, please visit http://inspircd.org/wiki/Modules/invisible");
-               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserJoin, I_OnUserPart, I_OnUserQuit, I_OnRehash, I_OnHostCycle };
-               ServerInstance->Modules->Attach(eventlist, this, 7);
+               Implementation eventlist[] = {
+                       I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserJoin, I_OnUserPart, I_OnUserQuit,
+                       I_OnRehash, I_OnHostCycle, I_OnSendWhoLine
+               };
+               ServerInstance->Modules->Attach(eventlist, this, 8);
        };
 
        virtual ~ModuleInvisible()
@@ -128,17 +131,16 @@ class ModuleInvisible : public Module
                delete conf;
        };
 
-       virtual Version GetVersion();
-       virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created);
-       virtual void OnRehash(User* user);
+       Version GetVersion();
+       void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created);
+       void OnRehash(User* user);
        void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent);
        void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message);
        ModResult OnHostCycle(User* user);
-       /* No privmsg response when hiding - submitted by Eric at neowin */
-       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
-       virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
-       /* Fix by Eric @ neowin.net, thanks :) -- Brain */
+       ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
+       ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
        void WriteCommonFrom(User *user, Channel* channel, const char* text, ...) CUSTOM_PRINTF(4, 5);
+       void OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line);
 };
 
 Version ModuleInvisible::GetVersion()
@@ -246,4 +248,10 @@ void ModuleInvisible::WriteCommonFrom(User *user, Channel* channel, const char*
        }
 }
 
+void ModuleInvisible::OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line)
+{
+       if (user->IsModeSet('Q') && !IS_OPER(source))
+               line.clear();
+}
+
 MODULE_INIT(ModuleInvisible)