From da61734860ce61203ed460d10a5c18ed971b47e0 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 22 Feb 2013 04:37:29 -0500 Subject: Made FindService less dumb and able to do aliases to aliases --- include/service.h | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/service.h b/include/service.h index 496c25a45..545d1b363 100644 --- a/include/service.h +++ b/include/service.h @@ -26,30 +26,37 @@ class CoreExport Service : public virtual Base { static std::map > Services; static std::map > Aliases; - public: - static Service *FindService(const Anope::string &t, const Anope::string &n) + + static Service *FindService(const std::map &services, const std::map *aliases, const Anope::string &n) { - std::map >::iterator it = Services.find(t); - if (it != Services.end()) + std::map::const_iterator it = services.find(n); + if (it != services.end()) + return it->second; + + if (aliases != NULL) { - Anope::string name = n; - - std::map >::iterator it2 = Aliases.find(t); - if (it2 != Aliases.end()) - { - std::map::iterator it3 = it2->second.find(n); - if (it3 != it2->second.end()) - name = it3->second; - } - - std::map::iterator it4 = it->second.find(name); - if (it4 != it->second.end()) - return it4->second; + std::map::const_iterator it2 = aliases->find(n); + if (it2 != aliases->end()) + return FindService(services, aliases, it2->second); } return NULL; } + public: + static Service *FindService(const Anope::string &t, const Anope::string &n) + { + std::map >::const_iterator it = Services.find(t); + if (it == Services.end()) + return NULL; + + std::map >::const_iterator it2 = Aliases.find(t); + if (it2 != Aliases.end()) + return FindService(it->second, &it2->second, n); + + return FindService(it->second, NULL, n); + } + static std::vector GetServiceKeys(const Anope::string &t) { std::vector keys; -- cgit