1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
16 #include "commands/cmd_nick.h"
18 extern "C" DllExport Command* init_command(InspIRCd* Instance)
20 return new CommandNick(Instance);
23 /** Handle nick changes from users.
24 * NOTE: If you are used to ircds based on ircd2.8, and are looking
25 * for the client introduction code in here, youre in the wrong place.
26 * You need to look in the spanningtree module for this!
28 CmdResult CommandNick::Handle (const char* const* parameters, int, User *user)
30 char oldnick[NICKMAX];
32 if (!*parameters[0] || !*user->nick)
34 /* We cant put blanks in the parameters, so for this (extremely rare) issue we just put '*' here. */
35 user->WriteNumeric(432, "%s * :Erroneous Nickname", *user->nick ? user->nick : "*");
39 if (irc::string(user->nick) == irc::string(parameters[0]))
41 /* If its exactly the same, even case, dont do anything. */
42 if (!strcmp(user->nick,parameters[0]))
45 /* Its a change of case. People insisted that they should be
46 * able to do silly things like this even though the RFC says
47 * the nick AAA is the same as the nick aaa.
49 strlcpy(oldnick, user->nick, NICKMAX - 1);
51 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
54 if (user->registered == REG_ALL)
55 user->WriteCommon("NICK %s",parameters[0]);
56 strlcpy(user->nick, parameters[0], NICKMAX - 1);
57 user->InvalidateCache();
58 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
63 XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]);
66 ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0], user->nick, user->ident, user->host, mq->reason);
67 user->WriteNumeric(432, "%s %s :Invalid nickname: %s",user->nick,parameters[0], mq->reason);
72 * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
73 * then we have a potential collide. Check whether someone else is camping on the nick
74 * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
75 * camper to their UID, and allow the incoming nick change.
77 * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
78 * because the nick is already (rightfully) in use. -- w00t
80 User* InUse = ServerInstance->FindNickOnly(parameters[0]);
81 if (InUse && (InUse != user) && ((ServerInstance->IsNick(parameters[0]) || allowinvalid)))
83 if (InUse->registered != REG_ALL)
85 /* force the camper to their UUID, and ask them to re-send a NICK. */
86 InUse->WriteTo(InUse, "NICK %s", InUse->uuid);
87 InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick, InUse->nick);
88 InUse->UpdateNickHash(InUse->uuid);
89 strlcpy(InUse->nick, InUse->uuid, NICKMAX - 1);
90 InUse->InvalidateCache();
91 InUse->registered &= ~REG_NICK;
95 /* No camping, tell the incoming user to stop trying to change nick ;p */
96 user->WriteNumeric(433, "%s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick : "*", parameters[0]);
101 if (((!ServerInstance->IsNick(parameters[0]))) && (IS_LOCAL(user)))
105 user->WriteNumeric(432, "%s %s :Erroneous Nickname",user->nick,parameters[0]);
111 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
113 // if a module returns true, the nick change is silently forbidden.
116 if (user->registered == REG_ALL)
117 user->WriteCommon("NICK %s",parameters[0]);
119 strlcpy(oldnick, user->nick, NICKMAX - 1);
121 /* change the nick of the user in the users_hash */
122 user = user->UpdateNickHash(parameters[0]);
124 /* actually change the nick within the record */
130 strlcpy(user->nick, parameters[0], NICKMAX - 1);
132 user->InvalidateCache();
134 /* Update display nicks */
135 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
137 CUList* ulist = v->first->GetUsers();
138 CUList::iterator i = ulist->find(user);
139 if (i != ulist->end())
140 i->second = user->nick;
143 if (user->registered < REG_NICKUSER)
145 user->registered = (user->registered | REG_NICK);
147 if (user->registered == REG_NICKUSER)
149 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
151 FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
155 if (user->registered == REG_ALL)
157 user->IncreasePenalty(10);
158 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
165 CmdResult CommandNick::HandleInternal(const unsigned int id, const std::deque<classbase*>&)
167 allowinvalid = (id != 0);