]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_customtitle.cpp
Make rehash work more than once per run, and fix some uninitialized values in connect...
[user/henk/code/inspircd.git] / src / modules / m_customtitle.cpp
index b15b308d080d7e6e9859672af1bc343cb91ae322..d2d7e1c5d0998e993b19b64cc4bb8797fb1b89e9 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -12,7 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 
 /* $ModDesc: Provides the TITLE command which allows setting of CUSTOM WHOIS TITLE line */
 
@@ -34,7 +33,7 @@ class CommandTitle : public Command
                std::string xhost;
                while (hl >> xhost)
                {
-                       if (match(host, xhost) || match(ip,xhost, true))
+                       if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
                        {
                                return true;
                        }
@@ -44,9 +43,6 @@ class CommandTitle : public Command
 
        CmdResult Handle(const std::vector<std::string> &parameters, User* user)
        {
-               if (!IS_LOCAL(user))
-                       return CMD_LOCALONLY;
-
                char TheHost[MAXBUF];
                char TheIP[MAXBUF];
 
@@ -66,9 +62,7 @@ class CommandTitle : public Command
                        if (!strcmp(name.c_str(),parameters[0].c_str()) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()) && OneOfMatches(TheHost,TheIP,host.c_str()) && !title.empty())
                        {
                                std::string* text;
-                               user->GetExt("ctitle", text);
-
-                               if (text)
+                               if (user->GetExt("ctitle", text))
                                {
                                        user->Shrink("ctitle");
                                        delete text;
@@ -82,22 +76,14 @@ class CommandTitle : public Command
                                if (!vhost.empty())
                                        user->ChangeDisplayedHost(vhost.c_str());
 
-                               if (!ServerInstance->ULine(user->server))
-                                       // Ulines set TITLEs silently
-                                       ServerInstance->SNO->WriteToSnoMask('A', "%s used TITLE to set custom title '%s'",user->nick.c_str(),title.c_str());
-
                                user->WriteServ("NOTICE %s :Custom title set to '%s'",user->nick.c_str(), title.c_str());
 
-                               return CMD_SUCCESS;
+                               return CMD_LOCALONLY;
                        }
                }
 
-               if (!ServerInstance->ULine(user->server))
-                       // Ulines also fail TITLEs silently
-                       ServerInstance->SNO->WriteToSnoMask('A', "Failed TITLE attempt by %s!%s@%s using login '%s'", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), parameters[0].c_str());
-
                user->WriteServ("NOTICE %s :Invalid title credentials",user->nick.c_str());
-               return CMD_SUCCESS;
+               return CMD_LOCALONLY;
        }
 
 };
@@ -125,8 +111,7 @@ class ModuleCustomTitle : public Module
                {
                        /* Insert our numeric before 312 */
                        std::string* ctitle;
-                       dest->GetExt("ctitle", ctitle);
-                       if (ctitle)
+                       if (dest->GetExt("ctitle", ctitle))
                        {
                                ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick.c_str(), dest->nick.c_str(), ctitle->c_str());
                        }
@@ -147,8 +132,7 @@ class ModuleCustomTitle : public Module
                {
                        // check if this user has an ctitle field to send
                        std::string* ctitle;
-                       user->GetExt("ctitle", ctitle);
-                       if (ctitle)
+                       if (user->GetExt("ctitle", ctitle))
                        {
                                // call this function in the linking module, let it format the data how it
                                // sees fit, and send it on its way. We dont need or want to know how.
@@ -161,8 +145,7 @@ class ModuleCustomTitle : public Module
        virtual void OnUserQuit(User* user, const std::string &message, const std::string &oper_message)
        {
                std::string* ctitle;
-               user->GetExt("ctitle", ctitle);
-               if (ctitle)
+               if (user->GetExt("ctitle", ctitle))
                {
                        user->Shrink("ctitle");
                        delete ctitle;
@@ -176,8 +159,7 @@ class ModuleCustomTitle : public Module
                {
                        User* user = (User*)item;
                        std::string* ctitle;
-                       user->GetExt("ctitle", ctitle);
-                       if (ctitle)
+                       if (user->GetExt("ctitle", ctitle))
                        {
                                user->Shrink("ctitle");
                                delete ctitle;
@@ -198,12 +180,16 @@ class ModuleCustomTitle : public Module
                if ((target_type == TYPE_USER) && (extname == "ctitle"))
                {
                        User* dest = (User*)target;
-                       // if they dont already have an ctitle field, accept the remote server's
                        std::string* text;
-                       if (!dest->GetExt("ctitle", text))
+                       if (dest->GetExt("ctitle", text))
+                       {
+                               dest->Shrink("ctitle");
+                               delete text;
+                       }
+                       if (!extdata.empty())
                        {
-                               std::string* ntext = new std::string(extdata);
-                               dest->Extend("ctitle",ntext);
+                               text = new std::string(extdata);
+                               dest->Extend("ctitle", text);
                        }
                }
        }
@@ -214,7 +200,7 @@ class ModuleCustomTitle : public Module
 
        virtual Version GetVersion()
        {
-               return Version(1, 2, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
        }
 };