diff options
Diffstat (limited to 'src/modules/m_customtitle.cpp')
-rw-r--r-- | src/modules/m_customtitle.cpp | 89 |
1 files changed, 71 insertions, 18 deletions
diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index c16b1eda2..2dd378062 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -28,12 +28,49 @@ enum RPL_WHOISSPECIAL = 320 }; +struct CustomTitle +{ + const std::string name; + const std::string password; + const std::string hash; + const std::string host; + const std::string title; + const std::string vhost; + + CustomTitle(const std::string& n, const std::string& p, const std::string& h, const std::string& hst, const std::string& t, const std::string& v) + : name(n) + , password(p) + , hash(h) + , host(hst) + , title(t) + , vhost(v) + { + } + + bool MatchUser(User* user) const + { + const std::string userHost = user->ident + "@" + user->GetRealHost(); + const std::string userIP = user->ident + "@" + user->GetIPString(); + return InspIRCd::MatchMask(host, userHost, userIP); + } + + bool CheckPass(User* user, const std::string& pass) const + { + return ServerInstance->PassCompare(user, password, pass, hash); + } +}; + +typedef std::multimap<std::string, CustomTitle> CustomVhostMap; +typedef std::pair<CustomVhostMap::iterator, CustomVhostMap::iterator> MatchingConfigs; + /** Handle /TITLE */ class CommandTitle : public Command { public: StringExtItem ctitle; + CustomVhostMap configs; + CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2), ctitle("ctitle", ExtensionItem::EXT_USER, Creator) { @@ -42,30 +79,21 @@ class CommandTitle : public Command CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE { - const std::string userHost = user->ident + "@" + user->GetRealHost(); - const std::string userIP = user->ident + "@" + user->GetIPString(); + MatchingConfigs matching = configs.equal_range(parameters[0]); - ConfigTagList tags = ServerInstance->Config->ConfTags("title"); - for (ConfigIter i = tags.first; i != tags.second; ++i) + for (MatchingConfigs::first_type i = matching.first; i != matching.second; ++i) { - std::string Name = i->second->getString("name"); - std::string pass = i->second->getString("password"); - std::string hash = i->second->getString("hash"); - std::string host = i->second->getString("host", "*@*"); - std::string title = i->second->getString("title"); - std::string vhost = i->second->getString("vhost"); - - if (Name == parameters[0] && ServerInstance->PassCompare(user, pass, parameters[1], hash) && - InspIRCd::MatchMask(host, userHost, userIP) && !title.empty()) + CustomTitle config = i->second; + if (config.MatchUser(user) && config.CheckPass(user, parameters[1])) { - ctitle.set(user, title); + ctitle.set(user, config.title); - ServerInstance->PI->SendMetaData(user, "ctitle", title); + ServerInstance->PI->SendMetaData(user, "ctitle", config.title); - if (!vhost.empty()) - user->ChangeDisplayedHost(vhost); + if (!config.vhost.empty()) + user->ChangeDisplayedHost(config.vhost); - user->WriteNotice("Custom title set to '" + title + "'"); + user->WriteNotice("Custom title set to '" + config.title + "'"); return CMD_SUCCESS; } @@ -88,6 +116,31 @@ class ModuleCustomTitle : public Module, public Whois::LineEventListener { } + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE + { + ConfigTagList tags = ServerInstance->Config->ConfTags("title"); + CustomVhostMap newtitles; + for (ConfigIter i = tags.first; i != tags.second; ++i) + { + reference<ConfigTag> tag = i->second; + std::string name = tag->getString("name", "", 1); + if (name.empty()) + throw ModuleException("<title:name> is empty at " + tag->getTagLocation()); + + std::string pass = tag->getString("password"); + if (pass.empty()) + throw ModuleException("<title:password> is empty at " + tag->getTagLocation()); + + std::string hash = tag->getString("hash"); + std::string host = tag->getString("host", "*@*"); + std::string title = tag->getString("title"); + std::string vhost = tag->getString("vhost"); + CustomTitle config(name, pass, hash, host, title, vhost); + newtitles.insert(std::make_pair(name, config)); + } + cmd.configs.swap(newtitles); + } + // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games. ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE { |