]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/ijoin.cpp
Merge insp20
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / ijoin.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21 #include "commands.h"
22 #include "utils.h"
23 #include "treeserver.h"
24 #include "treesocket.h"
25
26 CmdResult CommandIJoin::HandleRemote(const std::vector<std::string>& params, RemoteUser* user)
27 {
28         Channel* chan = ServerInstance->FindChan(params[0]);
29         if (!chan)
30         {
31                 // Desync detected, recover
32                 // Ignore the join and send RESYNC, this will result in the remote server sending all channel data to us
33                 ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Received IJOIN for non-existant channel: " + params[0]);
34
35                 parameterlist p;
36                 p.push_back(params[0]);
37                 SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
38                 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "RESYNC", p, user->server);
39
40                 return CMD_FAILURE;
41         }
42
43         bool apply_modes;
44         if (params.size() > 1)
45         {
46                 time_t RemoteTS = ConvToInt(params[1]);
47                 if (!RemoteTS)
48                 {
49                         ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]);
50                         return CMD_INVALID;
51                 }
52
53                 if (RemoteTS < chan->age)
54                 {
55                         ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Attempted to lower TS via IJOIN. Channel=" + params[0] + " RemoteTS=" + params[1] + " LocalTS=" + ConvToStr(chan->age));
56                         return CMD_INVALID;
57                 }
58                 apply_modes = ((params.size() > 2) && (RemoteTS == chan->age));
59         }
60         else
61                 apply_modes = false;
62
63         chan->ForceJoin(user, apply_modes ? &params[2] : NULL);
64         return CMD_SUCCESS;
65 }
66
67 CmdResult CommandResync::HandleServer(const std::vector<std::string>& params, FakeUser* user)
68 {
69         ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Resyncing " + params[0]);
70         Channel* chan = ServerInstance->FindChan(params[0]);
71         if (!chan)
72         {
73                 // This can happen for a number of reasons, safe to ignore
74                 ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Channel does not exist");
75                 return CMD_FAILURE;
76         }
77
78         SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
79         TreeServer* server = Utils->FindServer(user->server);
80         if (!server)
81                 return CMD_FAILURE;
82
83         TreeSocket* socket = server->GetSocket();
84         if (!socket)
85         {
86                 ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Received RESYNC with a source that is not directly connected: " + user->uuid);
87                 return CMD_INVALID;
88         }
89
90         // Send all known information about the channel
91         socket->SyncChannel(chan);
92         return CMD_SUCCESS;
93 }