diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-08-27 15:14:27 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-08-27 15:14:27 +0000 |
commit | cd2406617f5c0c3c5e7f53519ea47b9178b7802a (patch) | |
tree | 30ec5a594820f6f86d102b641da6b135b9ae5ee6 | |
parent | 4bbca0643b56f26f73a05462d226b2dd8871626b (diff) |
More translation stuff
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7888 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/command_parse.h | 4 | ||||
-rw-r--r-- | include/ctables.h | 3 | ||||
-rw-r--r-- | src/command_parse.cpp | 28 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 27 |
4 files changed, 53 insertions, 9 deletions
diff --git a/include/command_parse.h b/include/command_parse.h index 2c3605613..4f8b80000 100644 --- a/include/command_parse.h +++ b/include/command_parse.h @@ -201,6 +201,10 @@ class CoreExport CommandParser : public classbase * stdout then exit with EXIT_STATUS_HANDLER. */ void SetupCommandTable(userrec* user); + + /** Translate nicknames in a string into UIDs, based on the TranslationType given. + */ + int TranslateUIDs(TranslateType to, const std::string &source, std::string &dest); }; /** Command handler class for the RELOAD command. diff --git a/include/ctables.h b/include/ctables.h index c7ccada09..a1f05a3a8 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -38,7 +38,8 @@ enum TranslateType TR_END, /* End of known parameters, everything after this is TR_TEXT */ TR_TEXT, /* Raw text, leave as-is */ TR_NICK, /* Nickname, translate to UUID for server->server */ - TR_NICKLIST /* Comma seperated nickname list, translate to UUIDs */ + TR_NICKLIST, /* Comma seperated nickname list, translate to UUIDs */ + TR_SPACENICKLIST /* Space seperated nickname list, translate to UUIDs */ }; /** For commands which should not be replicated to other diff --git a/src/command_parse.cpp b/src/command_parse.cpp index fb89fd7ad..9cef16ef4 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -594,3 +594,31 @@ void CommandParser::SetupCommandTable(userrec* user) this->CreateCommand(new cmd_reload(ServerInstance)); } +int CommandParser::TranslateUIDs(TranslateType to, const std::string &source, std::string &dest) +{ + userrec* user = NULL; + switch (to) + { + case TR_NICK: + /* Translate single nickname */ + user = ServerInstance->FindNick(source); + if (user) + dest = user->uuid; + else + dest = source; + break; + case TR_NICKLIST: + /* Translate comma seperated list of nicknames */ + break; + case TR_SPACENICKLIST: + /* Translate space seperated list of nicknames */ + break; + case TR_END: + case TR_TEXT: + default: + /* Do nothing */ + dest = source; + break; + } +} + diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 7ff67e458..651afe095 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -803,6 +803,8 @@ void ModuleSpanningTree::OnPostCommand(const std::string &command, const char** { if ((result == CMD_SUCCESS) && (ServerInstance->IsValidModuleCommand(command, pcnt, user))) { + /* Safe, we know its non-null because IsValidModuleCommand returned true */ + command_t* thiscmd = ServerInstance->Parser->GetHandler(command); // this bit of code cleverly routes all module commands // to all remote severs *automatically* so that modules // can just handle commands locally, without having @@ -810,19 +812,28 @@ void ModuleSpanningTree::OnPostCommand(const std::string &command, const char** // commands and linking protocols. std::deque<std::string> params; params.clear(); + size_t n_translate = thiscmd->translation.size(); + TranslationType translate_to; + for (int j = 0; j < pcnt; j++) { - /* XXX UID: Translate nicks in this list to UIDs, potentially using some form of lookup - * table that specifies a value type for each parameter, as part of the command_t. - */ - if (strchr(parameters[j],' ')) + std::string target; + + /* Map all items to UUIDs where neccessary */ + if (j < n_translate) { - params.push_back(":" + std::string(parameters[j])); + /* We have a translation mapping for this index */ + translate_to = thiscmd->translation[j] != TR_END ? thiscmd->translation[j] : TR_TEXT; } else - { - params.push_back(std::string(parameters[j])); - } + translate_to = TR_TEXT; + + ServerInstance->Parser->TranslateUIDs(translate_to, parameters[j], target); + + if (strchr(parameters[j],' ')) + params.push_back(":" + target); + else + params.push_back(target); } Utils->DoOneToMany(user->uuid, command, params); } |