2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013-2015 Attila Molnar <attilamolnar@hush.com>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "treeserver.h"
28 CmdResult CommandNick::HandleRemote(::RemoteUser* user, Params& params)
30 if ((isdigit(params[0][0])) && (params[0] != user->uuid))
31 throw ProtocolException("Attempted to change nick to an invalid or non-matching UUID");
33 // Timestamp of the new nick
34 time_t newts = ServerCommand::ExtractTS(params[1]);
37 * On nick messages, check that the nick doesn't already exist here.
38 * If it does, perform collision logic.
40 User* x = ServerInstance->FindNickOnly(params[0]);
41 if ((x) && (x != user) && (x->registered == REG_ALL))
43 // 'x' is the already existing user using the same nick as params[0]
44 // 'user' is the user trying to change nick to the in use nick
45 bool they_change = Utils->DoCollision(x, TreeServer::Get(user), newts, user->ident, user->GetIPString(), user->uuid, "NICK");
48 // Remote client lost, or both lost, rewrite this nick change as a change to uuid before
49 // calling ChangeNick() and forwarding the message
50 params[0] = user->uuid;
51 params[1] = ConvToStr(CommandSave::SavedTimestamp);
52 newts = CommandSave::SavedTimestamp;
56 user->ChangeNick(params[0], newts);