]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/nick.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / nick.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2013-2015 Attila Molnar <attilamolnar@hush.com>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #include "inspircd.h"
22
23 #include "main.h"
24 #include "utils.h"
25 #include "commands.h"
26 #include "treeserver.h"
27
28 CmdResult CommandNick::HandleRemote(::RemoteUser* user, Params& params)
29 {
30         if ((isdigit(params[0][0])) && (params[0] != user->uuid))
31                 throw ProtocolException("Attempted to change nick to an invalid or non-matching UUID");
32
33         // Timestamp of the new nick
34         time_t newts = ServerCommand::ExtractTS(params[1]);
35
36         /*
37          * On nick messages, check that the nick doesn't already exist here.
38          * If it does, perform collision logic.
39          */
40         User* x = ServerInstance->FindNickOnly(params[0]);
41         if ((x) && (x != user) && (x->registered == REG_ALL))
42         {
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");
46                 if (they_change)
47                 {
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;
53                 }
54         }
55
56         user->ChangeNick(params[0], newts);
57
58         return CMD_SUCCESS;
59 }