diff options
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 37 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.h | 4 |
2 files changed, 22 insertions, 19 deletions
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 076d07470..aa8f74d86 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -202,15 +202,24 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis return; } -bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& omit) +std::string SpanningTreeUtilities::ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params) { - TreeServer* omitroute = this->BestRouteTo(omit); - std::string FullLine = ":" + prefix + " " + command; - unsigned int words = params.size(); - for (unsigned int x = 0; x < words; x++) + std::string FullLine; + FullLine.reserve(MAXBUF); + FullLine = ":" + prefix + " " + command; + for (parameterlist::const_iterator x = params.begin(); x != params.end(); ++x) { - FullLine = FullLine + " " + params[x]; + FullLine.push_back(' '); + FullLine.append(*x); } + return FullLine; +} + +bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& omit) +{ + TreeServer* omitroute = this->BestRouteTo(omit); + std::string FullLine = ConstructLine(prefix, command, params); + unsigned int items = this->TreeRoot->ChildCount(); for (unsigned int x = 0; x < items; x++) { @@ -231,12 +240,8 @@ bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist ¶ms) { - std::string FullLine = ":" + prefix + " " + command; - unsigned int words = params.size(); - for (unsigned int x = 0; x < words; x++) - { - FullLine = FullLine + " " + params[x]; - } + std::string FullLine = ConstructLine(prefix, command, params); + unsigned int items = this->TreeRoot->ChildCount(); for (unsigned int x = 0; x < items; x++) { @@ -256,17 +261,11 @@ bool SpanningTreeUtilities::DoOneToOne(const std::string& prefix, const std::str TreeServer* Route = this->BestRouteTo(target); if (Route) { - std::string FullLine = ":" + prefix + " " + command; - unsigned int words = params.size(); - for (unsigned int x = 0; x < words; x++) - { - FullLine = FullLine + " " + params[x]; - } if (Route && Route->GetSocket()) { TreeSocket* Sock = Route->GetSocket(); if (Sock) - Sock->WriteLine(FullLine); + Sock->WriteLine(ConstructLine(prefix, command, params)); } return true; } diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 8b73359c3..f3e16230a 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -44,6 +44,10 @@ typedef std::map<TreeServer*,TreeServer*> TreeServerList; */ class SpanningTreeUtilities : public classbase { + /** Creates a line in the :<prefix> <command> [<params>] format + */ + std::string ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params); + public: /** Creator module */ |