From 526f5a4a02882b19056fe755dff1f64b764ff313 Mon Sep 17 00:00:00 2001 From: danieldg Date: Fri, 6 Mar 2009 22:28:57 +0000 Subject: Construct explicit parameter type list for MODE parameters Previously, we used TR_SPACENICKLIST on the parameters. This worked only because usually, if anything in the list parsed as a nick, then it was a nick. However, some modes like +k and +g allow free-form text, which could also resolve as a nick. Add extra parameters to allow modes to specify their TranslateType, defaulting to TR_TEXT. This fixes bug #757, found by Taros git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11180 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/command_parse.cpp | 83 ++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 40 deletions(-) (limited to 'src/command_parse.cpp') diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 7c18c8ab1..d0b114816 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -609,32 +609,24 @@ void CommandParser::SetupCommandTable() this->CreateCommand(new CommandReload(ServerInstance)); } -int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, std::string &dest) +int CommandParser::TranslateUIDs(const std::vector to, const std::string &source, std::string &dest) { + irc::spacesepstream items(source); + std::vector::const_iterator types = to.begin(); User* user = NULL; std::string item; int translations = 0; dest.clear(); - switch (to) + while (items.GetToken(item)) { - case TR_NICK: - /* Translate single nickname */ - user = ServerInstance->FindNick(source); - if (user) - { - dest = user->uuid; - translations++; - } - else - dest = source; - break; - case TR_NICKLIST: + TranslateType t = *types; + types++; + + switch (t) { - /* Translate comma seperated list of nicknames */ - irc::commasepstream items(source); - while (items.GetToken(item)) - { + case TR_NICK: + /* Translate single nickname */ user = ServerInstance->FindNick(item); if (user) { @@ -643,31 +635,42 @@ int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, st } else dest.append(item); - dest.append(","); - } - if (!dest.empty()) - dest.erase(dest.end() - 1); + break; + break; + case TR_END: + case TR_TEXT: + default: + /* Do nothing */ + dest.append(item); + break; } - break; - case TR_SPACENICKLIST: - { - /* Translate space seperated list of nicknames */ - irc::spacesepstream items(source); - while (items.GetToken(item)) + dest.append(" "); + } + + if (!dest.empty()) + dest.erase(dest.end() - 1); + return translations; +} + +int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, std::string &dest) +{ + User* user = NULL; + std::string item; + int translations = 0; + dest.clear(); + + switch (to) + { + case TR_NICK: + /* Translate single nickname */ + user = ServerInstance->FindNick(source); + if (user) { - user = ServerInstance->FindNick(item); - if (user) - { - dest.append(user->uuid); - translations++; - } - else - dest.append(item); - dest.append(" "); + dest = user->uuid; + translations++; } - if (!dest.empty()) - dest.erase(dest.end() - 1); - } + else + dest = source; break; case TR_END: case TR_TEXT: -- cgit v1.2.3