X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcommand_parse.cpp;h=d1ae987290bc0a506dca75436237c7b5abafcb28;hb=67de413cad88194972d55a8ff88464370890c5a9;hp=35cb1601bedaf056b4b73485122002e1af31e734;hpb=97449ad5695dd63841c9e8426e75f3c6543c16da;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 35cb1601b..d1ae98729 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -100,7 +100,7 @@ bool CommandParser::LoopCall(User* user, Command* handler, const std::vector= n->second->min_params)) - { - if (IS_LOCAL(user) && n->second->flags_needed) - { - if (user->IsModeSet(n->second->flags_needed)) - { - return (user->HasPermission(commandname)); - } - } - else - { - return true; - } - } - } - return false; -} - Command* CommandParser::GetHandler(const std::string &commandname) { Commandtable::iterator n = cmdlist.find(commandname); @@ -340,7 +316,7 @@ void CommandParser::ProcessCommand(LocalUser *user, std::string &cmd) */ CmdResult result = handler->Handle(command_p, user); - FOREACH_MOD(I_OnPostCommand, OnPostCommand(handler, command_p, user, result, cmd)); + FOREACH_MOD(OnPostCommand, (handler, command_p, user, result, cmd)); } } @@ -351,6 +327,10 @@ void CommandParser::RemoveCommand(Command* x) cmdlist.erase(n); } +CommandBase::~CommandBase() +{ +} + Command::~Command() { ServerInstance->Parser->RemoveCommand(this); @@ -381,88 +361,64 @@ CommandParser::CommandParser() { } -int CommandParser::TranslateUIDs(const std::vector to, const std::vector &source, std::string &dest, bool prefix_final, Command* custom_translator) +std::string CommandParser::TranslateUIDs(const std::vector& to, const std::vector& source, bool prefix_final, CommandBase* custom_translator) { std::vector::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, CommandBase* 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; - case TR_END: + // If no custom translator was given, fall through + } case TR_TEXT: default: /* Do nothing */ - dest = source; + dest.append(item); break; } - - return translations; }