X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcmd_nick.cpp;h=78483e2f290b4545add2dc02238ba58d6a7010ae;hb=b8cdcf390fb74469d369ffbec4ce25725cb91a87;hp=4b3317a9fe0bb51a54697584d6b96b3c4af7d5a8;hpb=a4743b222b5fa099434ecfe78921fc77e267c907;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp index 4b3317a9f..78483e2f2 100644 --- a/src/cmd_nick.cpp +++ b/src/cmd_nick.cpp @@ -29,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. */ @@ -50,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])); @@ -59,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; } @@ -76,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; } } @@ -101,7 +102,7 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user) } user->WriteCommon("NICK %s",parameters[0]); - + } strlcpy(oldnick, user->nick, NICKMAX - 1); @@ -117,29 +118,29 @@ CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user) user->InvalidateCache(); - ServerInstance->Log(DEBUG,"new nick set: %s",user->nick); - 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) {