]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/ijoin.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / ijoin.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
5  *   Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "commands.h"
24 #include "utils.h"
25 #include "treeserver.h"
26 #include "treesocket.h"
27
28 CmdResult CommandIJoin::HandleRemote(RemoteUser* user, Params& params)
29 {
30         Channel* chan = ServerInstance->FindChan(params[0]);
31         if (!chan)
32         {
33                 // Desync detected, recover
34                 // Ignore the join and send RESYNC, this will result in the remote server sending all channel data to us
35                 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received IJOIN for nonexistent channel: " + params[0]);
36
37                 CmdBuilder("RESYNC").push(params[0]).Unicast(user);
38
39                 return CMD_FAILURE;
40         }
41
42         bool apply_modes;
43         if (params.size() > 3)
44         {
45                 time_t RemoteTS = ServerCommand::ExtractTS(params[2]);
46                 apply_modes = (RemoteTS <= chan->age);
47         }
48         else
49                 apply_modes = false;
50
51         // Join the user and set the membership id to what they sent
52         Membership* memb = chan->ForceJoin(user, apply_modes ? &params[3] : NULL);
53         if (!memb)
54                 return CMD_FAILURE;
55
56         memb->id = Membership::IdFromString(params[1]);
57         return CMD_SUCCESS;
58 }
59
60 CmdResult CommandResync::HandleServer(TreeServer* server, CommandBase::Params& params)
61 {
62         ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Resyncing " + params[0]);
63         Channel* chan = ServerInstance->FindChan(params[0]);
64         if (!chan)
65         {
66                 // This can happen for a number of reasons, safe to ignore
67                 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Channel does not exist");
68                 return CMD_FAILURE;
69         }
70
71         if (!server->IsLocal())
72                 throw ProtocolException("RESYNC from a server that is not directly connected");
73
74         // Send all known information about the channel
75         server->GetSocket()->SyncChannel(chan);
76         return CMD_SUCCESS;
77 }