]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Merge pull request #971 from SaberUK/master+numeric-xline
[user/henk/code/inspircd.git] / src / users.cpp
index cb1bc901ee89a4c038b6d4b8e08c5a0335658daa..12243c64b074df57ab7442f4b5e8a782d79c5858 100644 (file)
@@ -845,95 +845,37 @@ void User::WriteFrom(User *user, const char* text, ...)
        this->WriteFrom(user, textbuffer);
 }
 
-void User::WriteCommon(const char* text, ...)
-{
-       if (this->registered != REG_ALL || quitting)
-               return;
-
-       std::string textbuffer;
-       VAFORMAT(textbuffer, text, text);
-       textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
-       this->WriteCommonRaw(textbuffer, true);
-}
-
-void User::WriteCommonRaw(const std::string &line, bool include_self)
+namespace
 {
-       if (this->registered != REG_ALL || quitting)
-               return;
-
-       LocalUser::already_sent_id++;
-
-       IncludeChanList include_c(chans.begin(), chans.end());
-       std::map<User*,bool> exceptions;
-
-       exceptions[this] = include_self;
-
-       FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
-
-       for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
+       class WriteCommonRawHandler : public User::ForEachNeighborHandler
        {
-               LocalUser* u = IS_LOCAL(i->first);
-               if (u && !u->quitting)
+               const std::string& msg;
+
+               void Execute(LocalUser* user) CXX11_OVERRIDE
                {
-                       u->already_sent = LocalUser::already_sent_id;
-                       if (i->second)
-                               u->Write(line);
+                       user->Write(msg);
                }
-       }
-       for (IncludeChanList::const_iterator v = include_c.begin(); v != include_c.end(); ++v)
-       {
-               Channel* c = (*v)->chan;
-               const Channel::MemberMap& ulist = c->GetUsers();
-               for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
+
+        public:
+               WriteCommonRawHandler(const std::string& message)
+                       : msg(message)
                {
-                       LocalUser* u = IS_LOCAL(i->first);
-                       if (u && u->already_sent != LocalUser::already_sent_id)
-                       {
-                               u->already_sent = LocalUser::already_sent_id;
-                               u->Write(line);
-                       }
                }
-       }
+       };
 }
 
-void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
+void User::WriteCommon(const char* 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));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
+       this->WriteCommonRaw(textbuffer, true);
+}
 
-       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::WriteCommonRaw(const std::string &line, bool include_self)
+{
+       WriteCommonRawHandler handler(line);
+       ForEachNeighbor(handler, include_self);
 }
 
 void User::ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self)