]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Implement User::WriteCommonQuit() using ForEachNeighbor() in UserManager
authorAttila Molnar <attilamolnar@hush.com>
Sat, 24 Jan 2015 13:53:03 +0000 (14:53 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 24 Jan 2015 13:53:03 +0000 (14:53 +0100)
include/users.h
src/usermanager.cpp
src/users.cpp

index 6f319018fd135a3e16cdf3dfe9831b1f52bff461..fa8f610bc915c9c4b57af2f56573bf6e13bbbc0d 100644 (file)
@@ -548,13 +548,6 @@ class CoreExport User : public Extensible
         */
        void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
 
-       /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
-        * quit message for opers only.
-        * @param normal_text Normal user quit message
-        * @param oper_text Oper only quit message
-        */
-       void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
-
        /** Execute a function once for each local neighbor of this user. By default, the neighbors of a user are the users
         * who have at least one common channel with the user. Modules are allowed to alter the set of neighbors freely.
         * This function is used for example to send something conditionally to neighbors, or to send different messages
index 52cb4989fbbaf199ff0eee1aa1718d27337e4aae..5d07c4d792375de68b78bfc870813dcedfaaa536 100644 (file)
 #include "xline.h"
 #include "iohook.h"
 
+namespace
+{
+       class WriteCommonQuit : public User::ForEachNeighborHandler
+       {
+               std::string line;
+               std::string operline;
+
+               void Execute(LocalUser* user) CXX11_OVERRIDE
+               {
+                       user->Write(user->IsOper() ? operline : line);
+               }
+
+        public:
+               WriteCommonQuit(User* user, const std::string& msg, const std::string& opermsg)
+                       : line(":" + user->GetFullHost() + " QUIT :")
+                       , operline(line)
+               {
+                       line += msg;
+                       operline += opermsg;
+                       user->ForEachNeighbor(*this, false);
+               }
+       };
+}
+
 UserManager::UserManager()
        : unregistered_count(0)
 {
@@ -180,7 +204,7 @@ void UserManager::QuitUser(User* user, const std::string& quitreason, const std:
        if (user->registered == REG_ALL)
        {
                FOREACH_MOD(OnUserQuit, (user, reason, *operreason));
-               user->WriteCommonQuit(reason, *operreason);
+               WriteCommonQuit(user, reason, *operreason);
        }
        else
                unregistered_count--;
index cb1bc901ee89a4c038b6d4b8e08c5a0335658daa..5be3963b45b9ffcc66ec00b6eb62d03ac61b8f9a 100644 (file)
@@ -896,46 +896,6 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
        }
 }
 
-void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
-{
-       if (this->registered != REG_ALL)
-               return;
-
-       already_sent_t uniq_id = ++LocalUser::already_sent_id;
-
-       const std::string normalMessage = ":" + this->GetFullHost() + " QUIT :" + normal_text;
-       const std::string operMessage = ":" + this->GetFullHost() + " QUIT :" + oper_text;
-
-       IncludeChanList include_c(chans.begin(), chans.end());
-       std::map<User*,bool> exceptions;
-
-       FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
-
-       for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
-       {
-               LocalUser* u = IS_LOCAL(i->first);
-               if (u && !u->quitting)
-               {
-                       u->already_sent = uniq_id;
-                       if (i->second)
-                               u->Write(u->IsOper() ? operMessage : normalMessage);
-               }
-       }
-       for (IncludeChanList::const_iterator v = include_c.begin(); v != include_c.end(); ++v)
-       {
-               const Channel::MemberMap& ulist = (*v)->chan->GetUsers();
-               for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); i++)
-               {
-                       LocalUser* u = IS_LOCAL(i->first);
-                       if (u && (u->already_sent != uniq_id))
-                       {
-                               u->already_sent = uniq_id;
-                               u->Write(u->IsOper() ? operMessage : normalMessage);
-                       }
-               }
-       }
-}
-
 void User::ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self)
 {
        // The basic logic for visiting the neighbors of a user is to iterate the channel list of the user