2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
5 * Copyright (C) 2014, 2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2013, 2016, 2018 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006-2007, 2010 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "core_user.h"
31 CommandNick::CommandNick(Module* parent)
32 : SplitCommand(parent, "NICK", 1, 1)
34 works_before_reg = true;
39 /** Handle nick changes from users.
40 * NOTE: If you are used to ircds based on ircd2.8, and are looking
41 * for the client introduction code in here, youre in the wrong place.
42 * You need to look in the spanningtree module for this!
44 CmdResult CommandNick::HandleLocal(LocalUser* user, const Params& parameters)
46 std::string oldnick = user->nick;
47 std::string newnick = parameters[0];
49 // anything except the initial NICK gets a flood penalty
50 if (user->registered == REG_ALL)
51 user->CommandFloodPenalty += 4000;
55 user->WriteNumeric(ERR_NONICKNAMEGIVEN, "No nickname given");
63 else if (!ServerInstance->IsNick(newnick))
65 user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, "Erroneous Nickname");
70 FIRST_MOD_RESULT(OnUserPreNick, MOD_RESULT, (user, newnick));
72 // If a module denied the change, abort now
73 if (MOD_RESULT == MOD_RES_DENY)
76 // Disallow the nick change if <security:restrictbannedusers> is on and there is a ban matching this user in
77 // one of the channels they are on
78 if (ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL)
80 for (User::ChanList::iterator i = user->chans.begin(); i != user->chans.end(); ++i)
82 Channel* chan = (*i)->chan;
83 if (chan->GetPrefixValue(user) < VOICE_VALUE && chan->IsBanned(user))
85 if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
86 user->WriteNumeric(ERR_CANTCHANGENICK, InspIRCd::Format("Cannot change nickname while on %s (you're banned)",
93 if (!user->ChangeNick(newnick))
96 if (user->registered < REG_NICKUSER)
98 user->registered = (user->registered | REG_NICK);
99 return CommandUser::CheckRegister(user);