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 * ---------------------------------------------------
16 /* +------------------------------------+
17 * | Inspire Internet Relay Chat Daemon |
18 * +------------------------------------+
20 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
21 * See: http://wiki.inspircd.org/Credits
23 * This program is free but copyrighted software; see
24 * the file COPYING for details.
26 * ---------------------------------------------------
29 #ifndef __CMD_NICK_H__
30 #define __CMD_NICK_H__
32 // include the common header files
37 /** Handle /NICK. These command handlers can be reloaded by the core,
38 * and handle basic RFC1459 commands. Commands within modules work
39 * the same way, however, they can be fully unloaded, where these
42 class CommandNick : public Command
45 /** Constructor for nick.
47 CommandNick (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"NICK", 0, 1, true, 3) { syntax = "<newnick>"; }
49 * @param parameters The parameters to the comamnd
50 * @param pcnt The number of parameters passed to teh command
51 * @param user The user issuing the command
52 * @return A value from CmdResult to indicate command success or failure.
54 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
60 /** Handle nick changes from users.
61 * NOTE: If you are used to ircds based on ircd2.8, and are looking
62 * for the client introduction code in here, youre in the wrong place.
63 * You need to look in the spanningtree module for this!
65 CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User *user)
69 if (parameters[0].empty())
71 /* We cant put blanks in the parameters, so for this (extremely rare) issue we just put '*' here. */
72 user->WriteNumeric(432, "%s * :Erroneous Nickname", user->nick.empty() ? user->nick.c_str() : "*");
76 if (((!ServerInstance->IsNick(parameters[0].c_str(), ServerInstance->Config->Limits.NickMax))) && (IS_LOCAL(user)))
78 if (!User::NICKForced.get(user))
80 if (parameters[0] == "0")
82 // Special case, Fake a /nick UIDHERE. Useful for evading "ERR: NICK IN USE" on connect etc.
83 std::vector<std::string> p2;
84 p2.push_back(user->uuid);
85 User::NICKForced.set(user, 1);
86 this->Handle(p2, user);
87 User::NICKForced.set(user, 0);
91 user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),parameters[0].c_str());
96 if (assign(user->nick) == parameters[0])
98 /* If its exactly the same, even case, dont do anything. */
99 if (parameters[0] == user->nick)
104 /* Its a change of case. People insisted that they should be
105 * able to do silly things like this even though the RFC says
106 * the nick AAA is the same as the nick aaa.
108 oldnick.assign(user->nick, 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
109 ModResult MOD_RESULT;
110 FIRST_MOD_RESULT(ServerInstance, OnUserPreNick, MOD_RESULT, (user,parameters[0]));
111 if (MOD_RESULT == MOD_RES_DENY)
113 if (user->registered == REG_ALL)
114 user->WriteCommon("NICK %s",parameters[0].c_str());
115 user->nick.assign(parameters[0], 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
116 user->InvalidateCache();
117 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
123 * Don't check Q:Lines if it's a server-enforced change, just on the off-chance some fucking *moron*
124 * tries to Q:Line SIDs, also, this means we just get our way period, as it really should be.
125 * Thanks Kein for finding this. -- w00t
127 * Also don't check Q:Lines for remote nickchanges, they should have our Q:Lines anyway to enforce themselves.
132 XLine* mq = ServerInstance->XLines->MatchesLine("Q",parameters[0]);
135 if (user->registered == REG_ALL)
137 ServerInstance->SNO->WriteToSnoMask('x', "Q-Lined nickname %s from %s!%s@%s: %s",
138 parameters[0].c_str(), user->nick.c_str(), user->ident.c_str(), user->host.c_str(), mq->reason.c_str());
140 user->WriteNumeric(432, "%s %s :Invalid nickname: %s",user->nick.c_str(), parameters[0].c_str(), mq->reason.c_str());
144 if (ServerInstance->Config->RestrictBannedUsers)
146 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
148 Channel *chan = i->first;
149 if (chan->GetStatus(user) < STATUS_VOICE && chan->IsBanned(user))
151 user->WriteNumeric(404, "%s %s :Cannot send to channel (you're banned)", user->nick.c_str(), chan->name.c_str());
159 * Uh oh.. if the nickname is in use, and it's not in use by the person using it (doh) --
160 * then we have a potential collide. Check whether someone else is camping on the nick
161 * (i.e. connect -> send NICK, don't send USER.) If they are camping, force-change the
162 * camper to their UID, and allow the incoming nick change.
164 * If the guy using the nick is already using it, tell the incoming nick change to gtfo,
165 * because the nick is already (rightfully) in use. -- w00t
167 User* InUse = ServerInstance->FindNickOnly(parameters[0]);
168 if (InUse && (InUse != user))
170 if (InUse->registered != REG_ALL)
172 /* force the camper to their UUID, and ask them to re-send a NICK. */
173 InUse->WriteTo(InUse, "NICK %s", InUse->uuid.c_str());
174 InUse->WriteNumeric(433, "%s %s :Nickname overruled.", InUse->nick.c_str(), InUse->nick.c_str());
175 InUse->UpdateNickHash(InUse->uuid.c_str());
176 InUse->nick.assign(InUse->uuid, 0, IS_LOCAL(InUse) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
177 InUse->InvalidateCache();
178 InUse->registered &= ~REG_NICK;
182 /* No camping, tell the incoming user to stop trying to change nick ;p */
183 user->WriteNumeric(433, "%s %s :Nickname is already in use.", user->registered >= REG_NICK ? user->nick.c_str() : "*", parameters[0].c_str());
190 ModResult MOD_RESULT;
191 FIRST_MOD_RESULT(ServerInstance, OnUserPreNick, MOD_RESULT, (user, parameters[0]));
192 if (MOD_RESULT == MOD_RES_DENY)
193 // if a module returns true, the nick change is silently forbidden.
196 if (user->registered == REG_ALL)
197 user->WriteCommon("NICK %s", parameters[0].c_str());
199 oldnick.assign(user->nick, 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
201 /* change the nick of the user in the users_hash */
202 user = user->UpdateNickHash(parameters[0].c_str());
204 /* actually change the nick within the record */
208 user->nick.assign(parameters[0], 0, IS_LOCAL(user) ? ServerInstance->Config->Limits.NickMax : MAXBUF);
209 user->InvalidateCache();
211 /* Update display nicks */
212 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
214 CUList* ulist = v->first->GetUsers();
215 CUList::iterator i = ulist->find(user);
216 if (i != ulist->end())
217 i->second = user->nick;
220 if (user->registered < REG_NICKUSER)
222 user->registered = (user->registered | REG_NICK);
223 if (user->registered == REG_NICKUSER)
225 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
226 FIRST_MOD_RESULT(ServerInstance, OnUserRegister, MOD_RESULT, (user));
227 if (MOD_RESULT == MOD_RES_DENY)
230 // return early to not penalize new users
235 if (user->registered == REG_ALL)
237 user->IncreasePenalty(10);
238 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user, oldnick));
246 COMMAND_INIT(CommandNick)