X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Fsvsnick.cpp;h=8d1bc80ba20cb2dd4a04c6ba7c0024c20fab4b4d;hb=96befc58f073b4f96771b57d728b16742294c2fe;hp=14e078710e82a56ee3a9f8fb33d4d416648196b2;hpb=b6dbd6caab62bc2c0d11ce5a45d511611eb9c2ef;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/svsnick.cpp b/src/modules/m_spanningtree/svsnick.cpp index 14e078710..8d1bc80ba 100644 --- a/src/modules/m_spanningtree/svsnick.cpp +++ b/src/modules/m_spanningtree/svsnick.cpp @@ -1,64 +1,81 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2018-2019 Sadie Powell + * Copyright (C) 2013-2016 Attila Molnar + * Copyright (C) 2012 Robby + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2009 Uli Schlachter + * Copyright (C) 2008 Robin Burchell * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -#include "inspircd.h" -#include "commands/cmd_whois.h" -#include "commands/cmd_stats.h" -#include "socket.h" -#include "xline.h" -#include "transport.h" -#include "socketengine.h" -#include "m_spanningtree/main.h" -#include "m_spanningtree/utils.h" -#include "m_spanningtree/treeserver.h" -#include "m_spanningtree/treesocket.h" +#include "inspircd.h" -/* $ModDep: m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */ +#include "main.h" +#include "commands.h" -/** Because Andy insists that services-compatible servers must - * implement SVSNICK and SVSJOIN, that's exactly what we do :p - */ -bool TreeSocket::ForceNick(const std::string &prefix, std::deque ¶ms) +CmdResult CommandSVSNick::Handle(User* user, Params& parameters) { - if (params.size() < 3) - return true; - - User* u = this->ServerInstance->FindNick(params[0]); + User* u = ServerInstance->FindNick(parameters[0]); - if (u) + if (u && IS_LOCAL(u)) { - Utils->DoOneToAllButSender(prefix,"SVSNICK",params,prefix); - - if (IS_LOCAL(u)) + // The 4th parameter is optional and it is the expected nick TS of the target user. If this parameter is + // present and it doesn't match the user's nick TS, the SVSNICK is not acted upon. + // This makes it possible to detect the case when services wants to change the nick of a user, but the + // user changes their nick before the SVSNICK arrives, making the SVSNICK nick change (usually to a guest nick) + // unnecessary. Consider the following for example: + // + // 1. test changes nick to Attila which is protected by services + // 2. Services SVSNICKs the user to Guest12345 + // 3. Attila changes nick to Attila_ which isn't protected by services + // 4. SVSNICK arrives + // 5. Attila_ gets his nick changed to Guest12345 unnecessarily + // + // In this case when the SVSNICK is processed the target has already changed their nick to something + // which isn't protected, so changing the nick again to a Guest nick is not desired. + // However, if the expected nick TS parameter is present in the SVSNICK then the nick change in step 5 + // won't happen because the timestamps won't match. + if (parameters.size() > 3) { - std::deque par; - par.push_back(params[1]); + time_t ExpectedTS = ConvToNum(parameters[3]); + if (u->age != ExpectedTS) + return CMD_FAILURE; // Ignore SVSNICK + } + + std::string nick = parameters[1]; + if (isdigit(nick[0])) + nick = u->uuid; - if (!u->ForceNickChange(params[1].c_str())) - { - /* buh. UID them */ - if (!u->ForceNickChange(u->uuid.c_str())) - { - this->ServerInstance->Users->QuitUser(u, "Nickname collision"); - return true; - } - } + time_t NickTS = ConvToNum(parameters[2]); + if (NickTS <= 0) + return CMD_FAILURE; - u->age = atoi(params[2].c_str()); + if (!u->ChangeNick(nick, NickTS)) + { + // Changing to 'nick' failed (it may already be in use), change to the uuid + u->WriteNumeric(RPL_SAVENICK, u->uuid, "Your nickname is in use by an older user on a new server."); + u->ChangeNick(u->uuid); } } - return true; + return CMD_SUCCESS; } +RouteDescriptor CommandSVSNick::GetRouting(User* user, const Params& parameters) +{ + return ROUTE_OPT_UCAST(parameters[0]); +}