diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-07-19 13:32:41 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-08-22 13:42:20 +0200 |
commit | 67de413cad88194972d55a8ff88464370890c5a9 (patch) | |
tree | 6b8693cda26ee984b609b48eeea4ab19211fa31f | |
parent | 15f4e6b865de11299e7688f28415957737999e02 (diff) |
m_spanningtree Remove duplicate code for sending channel messages from RouteCommand()
-rw-r--r-- | src/modules/m_spanningtree/postcommand.cpp | 15 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 14 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.h | 8 |
3 files changed, 13 insertions, 24 deletions
diff --git a/src/modules/m_spanningtree/postcommand.cpp b/src/modules/m_spanningtree/postcommand.cpp index ac416031d..b36cfec20 100644 --- a/src/modules/m_spanningtree/postcommand.cpp +++ b/src/modules/m_spanningtree/postcommand.cpp @@ -91,20 +91,9 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm Channel* c = ServerInstance->FindChan(dest); if (!c) return; - TreeServerList list; // TODO OnBuildExemptList hook was here - GetListOfServersForChannel(c,list,pfx, CUList()); - std::string data = ":" + user->uuid + " " + sent_cmd; - for (unsigned int x = 0; x < params.size(); x++) - data += " " + params[x]; - for (TreeServerList::iterator i = list.begin(); i != list.end(); i++) - { - TreeSocket* Sock = (*i)->GetSocket(); - if (origin && origin->GetSocket() == Sock) - continue; - if (Sock) - Sock->WriteLine(data); - } + CUList exempts; + SendChannelMessage(user->uuid, c, parameters[1], pfx, exempts, sent_cmd.c_str(), origin ? origin->GetSocket() : NULL); } else if (dest[0] == '$') { diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index e7edc65d6..bd87f2028 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -162,7 +162,7 @@ SpanningTreeUtilities::~SpanningTreeUtilities() } /* returns a list of DIRECT servernames for a specific channel */ -void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list) +void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list) { unsigned int minrank = 0; if (status) @@ -186,7 +186,7 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis { TreeServer* best = this->BestRouteTo(i->first->server); if (best) - list.insert(best); + list.insert(best->GetSocket()); } } return; @@ -379,7 +379,7 @@ Link* SpanningTreeUtilities::FindLink(const std::string& name) return NULL; } -void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const char* message_type) +void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit) { std::string raw(":"); raw.append(prefix).append(1, ' ').append(message_type).push_back(' '); @@ -387,12 +387,12 @@ void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channe raw.push_back(status); raw.append(target->name).append(" :").append(text); - TreeServerList list; + TreeSocketSet list; this->GetListOfServersForChannel(target, list, status, exempt_list); - for (TreeServerList::iterator i = list.begin(); i != list.end(); ++i) + for (TreeSocketSet::iterator i = list.begin(); i != list.end(); ++i) { - TreeSocket* Sock = (*i)->GetSocket(); - if (Sock) + TreeSocket* Sock = *i; + if (Sock != omit) Sock->WriteLine(raw); } } diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 491c4126f..345b62b09 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -40,8 +40,6 @@ extern SpanningTreeUtilities* Utils; */ typedef TR1NS::unordered_map<std::string, TreeServer*, irc::insensitive, irc::StrHashComp> server_hash; -typedef std::set<TreeServer*> TreeServerList; - /** Contains helper functions and variables for this module, * and keeps them out of the global namespace */ @@ -54,6 +52,8 @@ class SpanningTreeUtilities : public classbase CacheRefreshTimer RefreshTimer; public: + typedef std::set<TreeSocket*> TreeSocketSet; + /** Creator module */ ModuleSpanningTree* Creator; @@ -150,7 +150,7 @@ class SpanningTreeUtilities : public classbase /** Compile a list of servers which contain members of channel c */ - void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list); + void GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list); /** Find a server by name */ @@ -178,7 +178,7 @@ class SpanningTreeUtilities : public classbase /** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix */ - void SendChannelMessage(const std::string& prefix, Channel* target, const std::string &text, char status, const CUList& exempt_list, const char* message_type); + void SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit = NULL); }; inline void SpanningTreeUtilities::DoOneToMany(const std::string& prefix, const std::string& command, const parameterlist& params) |