X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=12243c64b074df57ab7442f4b5e8a782d79c5858;hb=7492344e64491cea6bbb5c9354dceb804bb908ac;hp=cb1bc901ee89a4c038b6d4b8e08c5a0335658daa;hpb=662dfa6c181a8c1d97a0c65499679e0eb1b399e2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index cb1bc901e..12243c64b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -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 exceptions; - - exceptions[this] = include_self; - - FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions)); - - for (std::map::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 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::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)