diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command_parse.cpp | 89 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_spanningtree/postcommand.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_spanningtree/protocolinterface.cpp | 5 |
4 files changed, 36 insertions, 65 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 35cb1601b..08e28557c 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -381,88 +381,65 @@ CommandParser::CommandParser() { } -int CommandParser::TranslateUIDs(const std::vector<TranslateType> to, const std::vector<std::string> &source, std::string &dest, bool prefix_final, Command* custom_translator) +std::string CommandParser::TranslateUIDs(const std::vector<TranslateType>& to, const std::vector<std::string>& source, bool prefix_final, Command* custom_translator) { std::vector<TranslateType>::const_iterator types = to.begin(); - User* user = NULL; - unsigned int i; - int translations = 0; - dest.clear(); + std::string dest; - for(i=0; i < source.size(); i++) + for (unsigned int i = 0; i < source.size(); i++) { - TranslateType t; - std::string item = source[i]; - - if (types == to.end()) - t = TR_TEXT; - else + TranslateType t = TR_TEXT; + // They might supply less translation types than parameters, + // in that case pretend that all remaining types are TR_TEXT + if (types != to.end()) { t = *types; types++; } - if (prefix_final && i == source.size() - 1) - dest.append(":"); + bool last = (i == (source.size() - 1)); + if (prefix_final && last) + dest.push_back(':'); - switch (t) - { - case TR_NICK: - /* Translate single nickname */ - user = ServerInstance->FindNick(item); - if (user) - { - dest.append(user->uuid); - translations++; - } - else - dest.append(item); - break; - case TR_CUSTOM: - if (custom_translator) - custom_translator->EncodeParameter(item, i); - dest.append(item); - break; - case TR_END: - case TR_TEXT: - default: - /* Do nothing */ - dest.append(item); - break; - } - if (i != source.size() - 1) - dest.append(" "); + TranslateSingleParam(t, source[i], dest, custom_translator, i); + + if (!last) + dest.push_back(' '); } - return translations; + return dest; } -int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, std::string &dest) +void CommandParser::TranslateSingleParam(TranslateType to, const std::string& item, std::string& dest, Command* custom_translator, unsigned int paramnumber) { - User* user = NULL; - int translations = 0; - dest.clear(); - switch (to) { case TR_NICK: + { /* Translate single nickname */ - user = ServerInstance->FindNick(source); + User* user = ServerInstance->FindNick(item); if (user) + dest.append(user->uuid); + else + dest.append(item); + break; + } + case TR_CUSTOM: + { + if (custom_translator) { - dest = user->uuid; - translations++; + std::string translated = item; + custom_translator->EncodeParameter(translated, paramnumber); + dest.append(translated); + break; } - else - dest = source; - break; + // If no custom translator was given, fall through + } case TR_END: case TR_TEXT: default: /* Do nothing */ - dest = source; + dest.append(item); break; } - - return translations; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 8c5439fbb..cc8871abd 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -812,9 +812,7 @@ ModResult ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg) void ModuleSpanningTree::ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const parameterlist &modeline, const std::vector<TranslateType> &translate) { TreeSocket* s = (TreeSocket*)opaque; - std::string output_text; - - ServerInstance->Parser->TranslateUIDs(translate, modeline, output_text); + std::string output_text = CommandParser::TranslateUIDs(translate, modeline); if (target) { diff --git a/src/modules/m_spanningtree/postcommand.cpp b/src/modules/m_spanningtree/postcommand.cpp index a2d0c1168..476453e20 100644 --- a/src/modules/m_spanningtree/postcommand.cpp +++ b/src/modules/m_spanningtree/postcommand.cpp @@ -75,8 +75,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, Command* thiscmd, c } } - std::string output_text; - ServerInstance->Parser->TranslateUIDs(thiscmd->translation, parameters, output_text, true, thiscmd); + std::string output_text = CommandParser::TranslateUIDs(thiscmd->translation, parameters, true, thiscmd); params.push_back(output_text); diff --git a/src/modules/m_spanningtree/protocolinterface.cpp b/src/modules/m_spanningtree/protocolinterface.cpp index ce824fef8..0f5c40cc1 100644 --- a/src/modules/m_spanningtree/protocolinterface.cpp +++ b/src/modules/m_spanningtree/protocolinterface.cpp @@ -104,12 +104,9 @@ void SpanningTreeProtocolInterface::SendMode(User* source, User* u, Channel* c, } else { - std::string output_text; - ServerInstance->Parser->TranslateUIDs(translate, modedata, output_text); - params.push_back(c->name); params.push_back(ConvToStr(c->age)); - params.push_back(output_text); + params.push_back(CommandParser::TranslateUIDs(translate, modedata)); Utils->DoOneToMany(source->uuid, "FMODE", params); } } |