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 std::vector<std::string>& parameters, User *user)
30 char oldnick[NICKMAX];
32 if (parameters[0].empty())
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.empty() ? user->nick.c_str() : "*");
39 if (((!ServerInstance->IsNick(parameters[0].c_str()))) && (IS_LOCAL(user)))
43 if (parameters[0] == "0")
45 // Special case, Fake a /nick UIDHERE. Useful for evading "ERR: NICK IN USE" on connect etc.
46 std::vector<std::string> p2;
47 std::deque<classbase*> dummy;
48 p2.push_back(user->uuid);
49 this->HandleInternal(1, dummy);
50 this->Handle(p2, user);
51 this->HandleInternal(0, dummy);
55 user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),parameters[0].c_str());
60 if (irc::string(user->nick.c_str()) == assign(parameters[0]))
62 /* If its exactly the same, even case, dont do anything. */
63 if (parameters[0] == user->nick)
66 /* Its a change of case. People insisted that they should be
67 * able to do silly things like this even though the RFC says
68 * the nick AAA is the same as the nick aaa.
70 strlcpy(oldnick, user->nick.c_str(), NICKMAX - 1);
72 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0].c_str()));
75 if (user->registered == REG_ALL)
76 user->WriteCommon("NICK %s",parameters[0].c_str());
77 user->nick.assign(parameters[0], 0, NICKMAX - 1);
78 user->InvalidateCache();
79 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
85 * Don't check Q:Lines if it's a server-enforced change, just on the off-chance some fucking *moron*
86 * tries to Q:Line SIDs, also, this means we just get our way period, as it really should be.
87 * Thanks Kein for finding this. -- w00t
89 * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves.
92 if (!allowinvalid || !IS_LOCAL(user))
94 XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]);
97 ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s", parameters[0].c_str(), user->nick.c_str(), user->ident.c_str(), user->host, mq->reason);
98 user->WriteNumeric(432, "%s %s :Invalid nickname: %s",user->nick.c_str(), parameters[0].c_str(), mq->reason);
104 * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
105 * then we have a potential collide. Check whether someone else is camping on the nick
106 * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
107 * camper to their UID, and allow the incoming nick change.
109 * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
110 * because the nick is already (rightfully) in use. -- w00t
112 User* InUse = ServerInstance->FindNickOnly(parameters[0]);
113 if (InUse && (InUse != user))
115 if (InUse->registered != REG_ALL)
117 /* force the camper to their UUID, and ask them to re-send a NICK. */
118 InUse->WriteTo(InUse, "NICK %s", InUse->uuid.c_str());
119 InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick.c_str(), InUse->nick.c_str());
120 InUse->UpdateNickHash(InUse->uuid.c_str());
121 InUse->nick.assign(InUse->uuid, 0, NICKMAX - 1);
122 InUse->InvalidateCache();
123 InUse->registered &= ~REG_NICK;
127 /* No camping, tell the incoming user to stop trying to change nick ;p */
128 user->WriteNumeric(433, "%s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick.c_str() : "*", parameters[0].c_str());
136 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user, parameters[0]));
138 // if a module returns true, the nick change is silently forbidden.
141 if (user->registered == REG_ALL)
142 user->WriteCommon("NICK %s", parameters[0].c_str());
144 strlcpy(oldnick, user->nick.c_str(), NICKMAX - 1);
146 /* change the nick of the user in the users_hash */
147 user = user->UpdateNickHash(parameters[0].c_str());
149 /* actually change the nick within the record */
152 if (!user->nick.empty())
155 user->nick.assign(parameters[0], 0, NICKMAX - 1);
157 user->InvalidateCache();
159 /* Update display nicks */
160 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
162 CUList* ulist = v->first->GetUsers();
163 CUList::iterator i = ulist->find(user);
164 if (i != ulist->end())
165 i->second = user->nick;
168 if (user->registered < REG_NICKUSER)
170 user->registered = (user->registered | REG_NICK);
172 if (user->registered == REG_NICKUSER)
174 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
176 FOREACH_RESULT(I_OnUserRegister,OnUserRegister(user));
180 if (user->registered == REG_ALL)
182 user->IncreasePenalty(10);
183 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
190 CmdResult CommandNick::HandleInternal(const unsigned int id, const std::deque<classbase*>&)
192 allowinvalid = (id != 0);