]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_customtitle.cpp
Rewrite the build system directive parser.
[user/henk/code/inspircd.git] / src / modules / m_customtitle.cpp
index efe4b32470b4ee4ca47d98840bf2ce4d3a0e9f26..30c0aa4f2d5826093f7f98865b07f7b5f9a3cc7b 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "inspircd.h"
 
-/* $ModDesc: Provides the TITLE command which allows setting of CUSTOM WHOIS TITLE line */
-
 /** Handle /TITLE
  */
 class CommandTitle : public Command
@@ -30,32 +28,15 @@ class CommandTitle : public Command
  public:
        StringExtItem ctitle;
        CommandTitle(Module* Creator) : Command(Creator,"TITLE", 2),
-               ctitle("ctitle", Creator)
+               ctitle("ctitle", ExtensionItem::EXT_USER, Creator)
        {
                syntax = "<user> <password>";
        }
 
-       bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
-       {
-               std::stringstream hl(hostlist);
-               std::string xhost;
-               while (hl >> xhost)
-               {
-                       if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
-                       {
-                               return true;
-                       }
-               }
-               return false;
-       }
-
        CmdResult Handle(const std::vector<std::string> &parameters, User* user)
        {
-               char TheHost[MAXBUF];
-               char TheIP[MAXBUF];
-
-               snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(), user->host.c_str());
-               snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(), user->GetIPString());
+               const std::string userHost = user->ident + "@" + user->host;
+               const std::string userIP = user->ident + "@" + user->GetIPString();
 
                ConfigTagList tags = ServerInstance->Config->ConfTags("title");
                for (ConfigIter i = tags.first; i != tags.second; ++i)
@@ -67,61 +48,57 @@ class CommandTitle : public Command
                        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) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
+                       if (Name == parameters[0] && ServerInstance->PassCompare(user, pass, parameters[1], hash) &&
+                               InspIRCd::MatchMask(host, userHost, userIP) && !title.empty())
                        {
                                ctitle.set(user, title);
 
                                ServerInstance->PI->SendMetaData(user, "ctitle", title);
 
                                if (!vhost.empty())
-                                       user->ChangeDisplayedHost(vhost.c_str());
+                                       user->ChangeDisplayedHost(vhost);
 
-                               user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
+                               user->WriteNotice("Custom title set to '" + title + "'");
 
                                return CMD_SUCCESS;
                        }
                }
 
-               user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
+               user->WriteNotice("Invalid title credentials");
                return CMD_SUCCESS;
        }
 
 };
 
-class ModuleCustomTitle : public Module
+class ModuleCustomTitle : public Module, public Whois::LineEventListener
 {
        CommandTitle cmd;
 
  public:
-       ModuleCustomTitle() : cmd(this)
+       ModuleCustomTitle()
+               : Whois::LineEventListener(this)
+               , cmd(this)
        {
-               ServerInstance->AddCommand(&cmd);
-               ServerInstance->Extensions.Register(&cmd.ctitle);
-               ServerInstance->Modules->Attach(I_OnWhoisLine, this);
        }
 
        // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
-       ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
+       ModResult OnWhoisLine(Whois::Context& whois, Numeric::Numeric& numeric) CXX11_OVERRIDE
        {
                /* We use this and not OnWhois because this triggers for remote, too */
-               if (numeric == 312)
+               if (numeric.GetNumeric() == 312)
                {
                        /* Insert our numeric before 312 */
-                       const std::string* ctitle = cmd.ctitle.get(dest);
+                       const std::string* ctitle = cmd.ctitle.get(whois.GetTarget());
                        if (ctitle)
                        {
-                               ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
+                               whois.SendLine(320, ctitle);
                        }
                }
                /* Don't block anything */
                return MOD_RES_PASSTHRU;
        }
 
-       ~ModuleCustomTitle()
-       {
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Custom Title for users", VF_OPTCOMMON | VF_VENDOR);
        }