1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /** Handle /NICK. These command handlers can be reloaded by the core,
18 * and handle basic RFC1459 commands. Commands within modules work
19 * the same way, however, they can be fully unloaded, where these
22 class CommandNick : public Command
25 /** Constructor for nick.
27 CommandNick ( Module* parent) : Command(parent,"NICK", 1, 1) { works_before_reg = true; syntax = "<newnick>"; Penalty = 3; }
29 * @param parameters The parameters to the comamnd
30 * @param pcnt The number of parameters passed to teh command
31 * @param user The user issuing the command
32 * @return A value from CmdResult to indicate command success or failure.
34 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
37 /** Handle nick changes from users.
38 * NOTE: If you are used to ircds based on ircd2.8, and are looking
39 * for the client introduction code in here, youre in the wrong place.
40 * You need to look in the spanningtree module for this!
42 CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User *user)
46 if (parameters[0].empty())
48 /* We cant put blanks in the parameters, so for this (extremely rare) issue we just put '*' here. */
49 user->WriteNumeric(432, "%s * :Erroneous Nickname", user->nick.empty() ? user->nick.c_str() : "*");
53 if (((!ServerInstance->IsNick(parameters[0].c_str(), ServerInstance->Config->Limits.NickMax))) && (IS_LOCAL(user)))
55 if (!User::NICKForced.get(user))
57 if (parameters[0] == "0")
59 // Special case, Fake a /nick UIDHERE. Useful for evading "ERR: NICK IN USE" on connect etc.
60 std::vector<std::string> p2;
61 p2.push_back(user->uuid);
62 User::NICKForced.set(user, 1);
63 this->Handle(p2, user);
64 User::NICKForced.set(user, 0);
68 user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),parameters[0].c_str());
73 if (assign(user->nick) == parameters[0])
75 /* If its exactly the same, even case, dont do anything. */
76 if (parameters[0] == user->nick)
81 /* Its a change of case. People insisted that they should be
82 * able to do silly things like this even though the RFC says
83 * the nick AAA is the same as the nick aaa.
85 oldnick.assign(user->nick, 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
87 FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (user,parameters[0]));
88 if (MOD_RESULT == MOD_RES_DENY)
90 if (user->registered == REG_ALL)
91 user->WriteCommon("NICK %s",parameters[0].c_str());
92 user->nick.assign(parameters[0], 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
93 user->InvalidateCache();
94 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
100 * Don't check Q:Lines if it's a server-enforced change, just on the off-chance some fucking *moron*
101 * tries to Q:Line SIDs, also, this means we just get our way period, as it really should be.
102 * Thanks Kein for finding this. -- w00t
104 * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves.
109 XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]);
112 if (user->registered == REG_ALL)
114 ServerInstance->SNO->WriteGlobalSno('a', "Q-Lined nickname %s from %s!%s@%s: %s",
115 parameters[0].c_str(), user->nick.c_str(), user->ident.c_str(), user->host.c_str(), mq->reason.c_str());
117 user->WriteNumeric(432, "%s %s :Invalid nickname: %s",user->nick.c_str(), parameters[0].c_str(), mq->reason.c_str());
121 if (ServerInstance->Config->RestrictBannedUsers)
123 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
126 if (chan->GetPrefixValue(user) < VOICE_VALUE && chan->IsBanned(user))
128 user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
136 * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
137 * then we have a potential collide. Check whether someone else is camping on the nick
138 * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
139 * camper to their UID, and allow the incoming nick change.
141 * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
142 * because the nick is already (rightfully) in use. -- w00t
144 User* InUse = ServerInstance->FindNickOnly(parameters[0]);
145 if (InUse && (InUse != user))
147 if (InUse->registered != REG_ALL)
149 /* force the camper to their UUID, and ask them to re-send a NICK. */
150 InUse->WriteTo(InUse, "NICK %s", InUse->uuid.c_str());
151 InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick.c_str(), InUse->nick.c_str());
152 InUse->UpdateNickHash(InUse->uuid.c_str());
153 InUse->nick.assign(InUse->uuid, 0, IS_LOCAL(InUse) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
154 InUse->InvalidateCache();
155 InUse->registered &= ~REG_NICK;
159 /* No camping, tell the incoming user to stop trying to change nick ;p */
160 user->WriteNumeric(433, "%s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick.c_str() : "*", parameters[0].c_str());
167 ModResult MOD_RESULT;
168 FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (user, parameters[0]));
169 if (MOD_RESULT == MOD_RES_DENY)
170 // if a module returns true, the nick change is silently forbidden.
173 if (user->registered == REG_ALL)
174 user->WriteCommon("NICK %s", parameters[0].c_str());
176 oldnick.assign(user->nick, 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
178 /* change the nick of the user in the users_hash */
179 user = user->UpdateNickHash(parameters[0].c_str());
181 /* actually change the nick within the record */
185 user->nick.assign(parameters[0], 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
186 user->InvalidateCache();
188 if (user->registered < REG_NICKUSER)
190 user->registered = (user->registered | REG_NICK);
191 if (user->registered == REG_NICKUSER)
193 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
194 FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (user));
195 if (MOD_RESULT == MOD_RES_DENY)
198 // return early to not penalize new users
203 if (user->registered == REG_ALL)
205 user->IncreasePenalty(10);
206 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user, oldnick));
214 COMMAND_INIT(CommandNick)