2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
6 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
7 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /** Handle /NICK. These command handlers can be reloaded by the core,
27 * and handle basic RFC1459 commands. Commands within modules work
28 * the same way, however, they can be fully unloaded, where these
31 class CommandNick : public Command
34 /** Constructor for nick.
36 CommandNick ( Module* parent) : Command(parent,"NICK", 1, 1) { works_before_reg = true; syntax = "<newnick>"; Penalty = 0; }
38 * @param parameters The parameters to the comamnd
39 * @param pcnt The number of parameters passed to teh command
40 * @param user The user issuing the command
41 * @return A value from CmdResult to indicate command success or failure.
43 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
46 /** Handle nick changes from users.
47 * NOTE: If you are used to ircds based on ircd2.8, and are looking
48 * for the client introduction code in here, youre in the wrong place.
49 * You need to look in the spanningtree module for this!
51 CmdResult CommandNick::Handle (const std::vector<std::string>& parameters, User *user)
53 std::string oldnick = user->nick;
54 std::string newnick = parameters[0];
56 // anything except the initial NICK gets a flood penalty
57 if (user->registered == REG_ALL && IS_LOCAL(user))
58 IS_LOCAL(user)->CommandFloodPenalty += 4000;
62 user->WriteNumeric(432, "%s * :Erroneous Nickname", oldnick.c_str());
70 else if (!ServerInstance->IsNick(newnick.c_str(), ServerInstance->Config->Limits.NickMax))
72 user->WriteNumeric(432, "%s %s :Erroneous Nickname", user->nick.c_str(),newnick.c_str());
76 if (!user->ChangeNick(newnick, false))
79 if (user->registered < REG_NICKUSER)
81 user->registered = (user->registered | REG_NICK);
82 if (user->registered == REG_NICKUSER)
84 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
86 FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (IS_LOCAL(user)));
87 if (MOD_RESULT == MOD_RES_DENY)
90 // return early to not penalize new users
99 COMMAND_INIT(CommandNick)