summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-01-24 14:55:10 +0100
committerAttila Molnar <attilamolnar@hush.com>2015-01-24 14:55:10 +0100
commit30bcf4894f1da0db8dde15329260c801f748a019 (patch)
tree3b8968d10d161ec8d929346ea74d1503fe35e86b /src/users.cpp
parentcf728bd8a3de0942c2294ca5b49745092565d87c (diff)
Implement User::WriteCommonRaw() using ForEachNeighbor()
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/users.cpp b/src/users.cpp
index 5be3963b4..4dffe6056 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -845,6 +845,25 @@ void User::WriteFrom(User *user, const char* text, ...)
this->WriteFrom(user, textbuffer);
}
+namespace
+{
+ class WriteCommonRawHandler : public User::ForEachNeighborHandler
+ {
+ const std::string& msg;
+
+ void Execute(LocalUser* user) CXX11_OVERRIDE
+ {
+ user->Write(msg);
+ }
+
+ public:
+ WriteCommonRawHandler(const std::string& message)
+ : msg(message)
+ {
+ }
+ };
+}
+
void User::WriteCommon(const char* text, ...)
{
if (this->registered != REG_ALL || quitting)
@@ -861,39 +880,8 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
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)
- {
- LocalUser* u = IS_LOCAL(i->first);
- if (u && !u->quitting)
- {
- u->already_sent = LocalUser::already_sent_id;
- if (i->second)
- u->Write(line);
- }
- }
- 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)
- {
- 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);
- }
- }
- }
+ WriteCommonRawHandler handler(line);
+ ForEachNeighbor(handler, include_self);
}
void User::ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self)