2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
11 * This file is part of InspIRCd. InspIRCd is free software: you can
12 * redistribute it and/or modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation, version 2.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 CmdResult CommandSVSNick::Handle(User* user, Params& parameters)
32 User* u = ServerInstance->FindNick(parameters[0]);
36 // The 4th parameter is optional and it is the expected nick TS of the target user. If this parameter is
37 // present and it doesn't match the user's nick TS, the SVSNICK is not acted upon.
38 // This makes it possible to detect the case when services wants to change the nick of a user, but the
39 // user changes their nick before the SVSNICK arrives, making the SVSNICK nick change (usually to a guest nick)
40 // unnecessary. Consider the following for example:
42 // 1. test changes nick to Attila which is protected by services
43 // 2. Services SVSNICKs the user to Guest12345
44 // 3. Attila changes nick to Attila_ which isn't protected by services
46 // 5. Attila_ gets his nick changed to Guest12345 unnecessarily
48 // In this case when the SVSNICK is processed the target has already changed their nick to something
49 // which isn't protected, so changing the nick again to a Guest nick is not desired.
50 // However, if the expected nick TS parameter is present in the SVSNICK then the nick change in step 5
51 // won't happen because the timestamps won't match.
52 if (parameters.size() > 3)
54 time_t ExpectedTS = ConvToNum<time_t>(parameters[3]);
55 if (u->age != ExpectedTS)
56 return CMD_FAILURE; // Ignore SVSNICK
59 std::string nick = parameters[1];
63 time_t NickTS = ConvToNum<time_t>(parameters[2]);
67 if (!u->ChangeNick(nick, NickTS))
69 // Changing to 'nick' failed (it may already be in use), change to the uuid
70 u->ChangeNick(u->uuid);
77 RouteDescriptor CommandSVSNick::GetRouting(User* user, const Params& parameters)
79 return ROUTE_OPT_UCAST(parameters[0]);