1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #include "configreader.h"
19 #include "commands/cmd_nick.h"
23 extern "C" command_t* init_command(InspIRCd* Instance)
25 return new cmd_nick(Instance);
28 CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
30 char oldnick[NICKMAX];
32 if (!parameters[0][0])
34 ServerInstance->Log(DEBUG,"zero length new nick passed to handle_nick");
39 ServerInstance->Log(DEBUG,"invalid old nick passed to handle_nick");
42 ServerInstance->Log(DEBUG,"Fall through");
43 if (irc::string(user->nick) == irc::string(parameters[0]))
45 /* If its exactly the same, even case, dont do anything. */
46 if (!strcmp(user->nick,parameters[0]))
49 /* Its a change of case. People insisted that they should be
50 * able to do silly things like this even though the RFC says
51 * the nick AAA is the same as the nick aaa.
53 ServerInstance->Log(DEBUG,"old nick is new nick, not updating hash (case change only)");
54 strlcpy(oldnick, user->nick, NICKMAX - 1);
56 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
59 user->InvalidateCache();
60 if (user->registered == REG_ALL)
61 user->WriteCommon("NICK %s",parameters[0]);
62 strlcpy(user->nick, parameters[0], NICKMAX - 1);
63 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
68 QLine* mq = ServerInstance->XLines->matches_qline(parameters[0]);
71 ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
72 user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason);
75 if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user) && (ServerInstance->IsNick(parameters[0])))
77 userrec* InUse = ServerInstance->FindNick(parameters[0]);
78 if (InUse->registered != REG_ALL)
80 userrec::QuitUser(ServerInstance, InUse, "Nickname overruled");
84 user->WriteServ("433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
89 if ((!ServerInstance->IsNick(parameters[0])) && (IS_LOCAL(user)))
91 user->WriteServ("432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
95 if (user->registered == REG_ALL)
98 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
100 // if a module returns true, the nick change is silently forbidden.
104 user->WriteCommon("NICK %s",parameters[0]);
108 strlcpy(oldnick, user->nick, NICKMAX - 1);
110 /* change the nick of the user in the users_hash */
111 user = user->UpdateNickHash(parameters[0]);
113 /* actually change the nick within the record */
114 if (!user) return CMD_FAILURE;
115 if (!*user->nick) return CMD_FAILURE;
117 strlcpy(user->nick, parameters[0], NICKMAX - 1);
119 user->InvalidateCache();
121 ServerInstance->Log(DEBUG,"new nick set: %s",user->nick);
123 if (user->registered < REG_NICKUSER)
125 user->registered = (user->registered | REG_NICK);
126 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
127 // and unless we're lucky we'll get a duff one later on.
128 //user->dns_done = (!lookup_dns(user->nick));
129 //if (user->dns_done)
130 // ServerInstance->Log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
132 if (ServerInstance->Config->NoUserDns)
134 user->dns_done = true;
135 ServerInstance->next_call = ServerInstance->Time();
139 user->StartDNSLookup();
142 /* Cached result or instant failure - fall right through if possible */
143 ServerInstance->next_call = ServerInstance->Time();
147 if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
148 ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
152 if (user->registered == REG_NICKUSER)
154 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
155 FOREACH_MOD(I_OnUserRegister,OnUserRegister(user));
156 //ConnectUser(user,NULL);
158 if (user->registered == REG_ALL)
160 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));