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];
38 if (irc::string(user->nick) == irc::string(parameters[0]))
40 /* If its exactly the same, even case, dont do anything. */
41 if (!strcmp(user->nick,parameters[0]))
44 /* Its a change of case. People insisted that they should be
45 * able to do silly things like this even though the RFC says
46 * the nick AAA is the same as the nick aaa.
48 strlcpy(oldnick, user->nick, NICKMAX - 1);
50 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
53 if (user->registered == REG_ALL)
54 user->WriteCommon("NICK %s",parameters[0]);
55 strlcpy(user->nick, parameters[0], NICKMAX - 1);
56 user->InvalidateCache();
57 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
62 QLine* mq = ServerInstance->XLines->matches_qline(parameters[0]);
65 ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
66 user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason);
69 if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user) && (ServerInstance->IsNick(parameters[0])))
71 userrec* InUse = ServerInstance->FindNick(parameters[0]);
72 if (InUse->registered != REG_ALL)
74 /* change the nick of the older user to nnn-overruled,
75 * where nnn is their file descriptor. We know this to be unique.
77 std::string changeback = ConvToStr(InUse->GetFd()) + "-overruled";
78 InUse->WriteTo(InUse, "NICK %s", changeback.c_str());
79 InUse->WriteServ("433 %s %s :Nickname overruled.", InUse->nick, InUse->nick);
80 InUse->UpdateNickHash(changeback.c_str());
81 strlcpy(InUse->nick, changeback.c_str(), NICKMAX - 1);
82 InUse->InvalidateCache();
83 /* Take away their nickname-sent state forcing them to send a nick again */
84 InUse->registered &= ~REG_NICK;
88 user->WriteServ("433 %s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick : "*", parameters[0]);
93 if ((!ServerInstance->IsNick(parameters[0])) && (IS_LOCAL(user)))
95 user->WriteServ("432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
99 if (user->registered == REG_ALL)
102 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
104 // if a module returns true, the nick change is silently forbidden.
108 user->WriteCommon("NICK %s",parameters[0]);
112 strlcpy(oldnick, user->nick, NICKMAX - 1);
114 /* change the nick of the user in the users_hash */
115 user = user->UpdateNickHash(parameters[0]);
117 /* actually change the nick within the record */
118 if (!user) return CMD_FAILURE;
119 if (!*user->nick) return CMD_FAILURE;
121 strlcpy(user->nick, parameters[0], NICKMAX - 1);
123 user->InvalidateCache();
125 if (user->registered < REG_NICKUSER)
127 user->registered = (user->registered | REG_NICK);
129 if (ServerInstance->Config->NoUserDns)
131 user->dns_done = true;
132 ServerInstance->next_call = ServerInstance->Time();
136 user->StartDNSLookup();
139 /* Cached result or instant failure - fall right through if possible */
140 ServerInstance->next_call = ServerInstance->Time();
144 if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
145 ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
149 if (user->registered == REG_NICKUSER)
151 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
152 FOREACH_MOD(I_OnUserRegister,OnUserRegister(user));
153 //ConnectUser(user,NULL);
155 if (user->registered == REG_ALL)
157 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));