]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/cmd_nick.cpp
Whoops, typo
[user/henk/code/inspircd.git] / src / cmd_nick.cpp
index 38ca0c7e372348447596e869f1df5485452b71b8..78483e2f290b4545add2dc02238ba58d6a7010ae 100644 (file)
@@ -2,12 +2,9 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *                <Craig@chatspike.net>
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
  *
- * Written by Craig Edwards, Craig McLure, and others.
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
@@ -32,17 +29,12 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
 {
        char oldnick[NICKMAX];
 
-       if (!parameters[0][0])
-       {
-               ServerInstance->Log(DEBUG,"zero length new nick passed to handle_nick");
+       if (!*parameters[0])
                return CMD_FAILURE;
-       }
+
        if (!*user->nick)
-       {
-               ServerInstance->Log(DEBUG,"invalid old nick passed to handle_nick");
                return CMD_FAILURE;
-       }
-       ServerInstance->Log(DEBUG,"Fall through");
+
        if (irc::string(user->nick) == irc::string(parameters[0]))
        {
                /* If its exactly the same, even case, dont do anything. */
@@ -53,7 +45,6 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                 * able to do silly things like this even though the RFC says
                 * the nick AAA is the same as the nick aaa.
                 */
-               ServerInstance->Log(DEBUG,"old nick is new nick, not updating hash (case change only)");
                strlcpy(oldnick, user->nick, NICKMAX - 1);
                int MOD_RESULT = 0;
                FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
@@ -62,6 +53,7 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                if (user->registered == REG_ALL)
                        user->WriteCommon("NICK %s",parameters[0]);
                strlcpy(user->nick, parameters[0], NICKMAX - 1);
+               user->InvalidateCache();
                FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
                return CMD_SUCCESS;
        }
@@ -79,11 +71,17 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                        userrec* InUse = ServerInstance->FindNick(parameters[0]);
                        if (InUse->registered != REG_ALL)
                        {
-                               userrec::QuitUser(ServerInstance, InUse, "Nickname overruled");
+                               /* change the nick of the older user to nnn-overruled,
+                                * where nnn is their file descriptor. We know this to be unique.
+                                */
+                               std::string changeback = ConvToStr(InUse->GetFd()) + "-overruled";
+                               InUse->UpdateNickHash(changeback.c_str());
+                               strlcpy(InUse->nick, changeback.c_str(), NICKMAX - 1);
+                               InUse->InvalidateCache();
                        }
                        else
                        {
-                               user->WriteServ("433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
+                               user->WriteServ("433 %s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick : "*", parameters[0]);
                                return CMD_FAILURE;
                        }
                }
@@ -104,42 +102,45 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
                }
 
                user->WriteCommon("NICK %s",parameters[0]);
-               
+
        }
 
        strlcpy(oldnick, user->nick, NICKMAX - 1);
 
        /* change the nick of the user in the users_hash */
        user = user->UpdateNickHash(parameters[0]);
+
        /* actually change the nick within the record */
        if (!user) return CMD_FAILURE;
        if (!*user->nick) return CMD_FAILURE;
 
        strlcpy(user->nick, parameters[0], NICKMAX - 1);
 
-       ServerInstance->Log(DEBUG,"new nick set: %s",user->nick);
-       
+       user->InvalidateCache();
+
        if (user->registered < REG_NICKUSER)
        {
                user->registered = (user->registered | REG_NICK);
-               // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
-               // and unless we're lucky we'll get a duff one later on.
-               //user->dns_done = (!lookup_dns(user->nick));
-               //if (user->dns_done)
-               //      ServerInstance->Log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
 
                if (ServerInstance->Config->NoUserDns)
                {
                        user->dns_done = true;
+                       ServerInstance->next_call = ServerInstance->Time();
                }
                else
                {
                        user->StartDNSLookup();
                        if (user->dns_done)
-                               ServerInstance->Log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+                       {
+                               /* Cached result or instant failure - fall right through if possible */
+                               ServerInstance->next_call = ServerInstance->Time();
+                       }
+                       else
+                       {
+                               if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
+                                       ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
+                       }
                }
-               if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
-                       ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
        }
        if (user->registered == REG_NICKUSER)
        {