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 * ---------------------------------------------------
15 #include "configreader.h"
19 #include "commands/cmd_nick.h"
21 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
23 return new cmd_nick(Instance);
26 /** Handle nick changes from users.
27 * NOTE: If you are used to ircds based on ircd2.8, and are looking
28 * for the client introduction code in here, youre in the wrong place.
29 * You need to look in the spanningtree module for this!
31 CmdResult cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
33 char oldnick[NICKMAX];
35 if (!*parameters[0] || !*user->nick)
37 /* We cant put blanks in the parameters, so for this (extremely rare) issue we just put '*' here. */
38 user->WriteServ("432 %s * :Erroneous Nickname", *user->nick ? user->nick : "*");
42 if (irc::string(user->nick) == irc::string(parameters[0]))
44 /* If its exactly the same, even case, dont do anything. */
45 if (!strcmp(user->nick,parameters[0]))
48 /* Its a change of case. People insisted that they should be
49 * able to do silly things like this even though the RFC says
50 * the nick AAA is the same as the nick aaa.
52 strlcpy(oldnick, user->nick, NICKMAX - 1);
54 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
57 if (user->registered == REG_ALL)
58 user->WriteCommon("NICK %s",parameters[0]);
59 strlcpy(user->nick, parameters[0], NICKMAX - 1);
60 user->InvalidateCache();
61 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
66 QLine* mq = ServerInstance->XLines->matches_qline(parameters[0]);
69 ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
70 user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason);
73 /* Check for nickname overruled -
74 * This happens when one user has connected and sent only NICK, and is essentially
75 * "camping" upon a nickname. To give the new user connecting a fair chance of having
76 * the nickname too, we force a nickchange on the older user (Simply the one who was
77 * here first, no TS checks need to take place here)
79 userrec* InUse = ServerInstance->FindNickOnly(parameters[0]);
80 ServerInstance->Log(DEBUG,"Nick in use");
81 if (InUse && (InUse != user) && ((ServerInstance->IsNick(parameters[0]) || allowinvalid)))
83 if (InUse->registered != REG_ALL)
85 /* change the nick of the older user to its UUID
87 InUse->WriteTo(InUse, "NICK %s", InUse->uuid);
88 InUse->WriteServ("433 %s %s :Nickname overruled.", InUse->nick, InUse->nick);
89 InUse->UpdateNickHash(InUse->uuid);
90 strlcpy(InUse->nick, InUse->uuid, NICKMAX - 1);
91 InUse->InvalidateCache();
92 /* Take away their nickname-sent state forcing them to send a nick again */
93 InUse->registered &= ~REG_NICK;
97 ServerInstance->Log(DEBUG,"Nick in use and user REG_ALL");
98 user->WriteServ("433 %s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick : "*", parameters[0]);
103 if (((!ServerInstance->IsNick(parameters[0]))) && (IS_LOCAL(user)))
107 user->WriteServ("432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
112 if (user->registered == REG_ALL)
115 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
117 // if a module returns true, the nick change is silently forbidden.
121 user->WriteCommon("NICK %s",parameters[0]);
125 strlcpy(oldnick, user->nick, NICKMAX - 1);
127 /* change the nick of the user in the users_hash */
128 user = user->UpdateNickHash(parameters[0]);
130 /* actually change the nick within the record */
131 if (!user) return CMD_FAILURE;
132 if (!*user->nick) return CMD_FAILURE;
134 strlcpy(user->nick, parameters[0], NICKMAX - 1);
136 user->InvalidateCache();
138 /* Update display nicks */
139 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
141 CUList* ulist = v->first->GetUsers();
142 CUList::iterator i = ulist->find(user);
143 if (i != ulist->end())
144 i->second = user->nick;
147 if (user->registered < REG_NICKUSER)
149 user->registered = (user->registered | REG_NICK);
151 if (ServerInstance->Config->NoUserDns)
153 user->dns_done = true;
154 ServerInstance->next_call = ServerInstance->Time();
158 user->StartDNSLookup();
161 /* Cached result or instant failure - fall right through if possible */
162 ServerInstance->next_call = ServerInstance->Time();
166 if (ServerInstance->next_call > ServerInstance->Time() + ServerInstance->Config->dns_timeout)
167 ServerInstance->next_call = ServerInstance->Time() + ServerInstance->Config->dns_timeout;
171 if (user->registered == REG_NICKUSER)
173 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
175 FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
179 if (user->registered == REG_ALL)
181 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
188 CmdResult cmd_nick::HandleInternal(const unsigned int id, const std::deque<classbase*> ¶meters)
190 allowinvalid = (id != 0);