X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcmd_nick.cpp;h=78483e2f290b4545add2dc02238ba58d6a7010ae;hb=b8cdcf390fb74469d369ffbec4ce25725cb91a87;hp=38ca0c7e372348447596e869f1df5485452b71b8;hpb=494d7f7489a78df919c1e9effcb0a014e8dc2286;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp index 38ca0c7e3..78483e2f2 100644 --- a/src/cmd_nick.cpp +++ b/src/cmd_nick.cpp @@ -2,12 +2,9 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * + * 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) {