]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/ijoin.cpp
m_spanningtree Remove duplicate code for sending channel messages from RouteCommand()
[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::Handle(User* user, std::vector<std::string>& params)
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(MODNAME, LOG_DEBUG, "Received IJOIN for non-existant channel: " + params[0]);
34
35                 parameterlist p;
36                 p.push_back(params[0]);
37                 Utils->DoOneToOne(ServerInstance->Config->GetSID(), "RESYNC", p, user->server);
38
39                 return CMD_FAILURE;
40         }
41
42         bool apply_modes;
43         if (params.size() > 1)
44         {
45                 time_t RemoteTS = ConvToInt(params[1]);
46                 if (!RemoteTS)
47                 {
48                         ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]);
49                         return CMD_INVALID;
50                 }
51
52                 if (RemoteTS < chan->age)
53                 {
54                         ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Attempted to lower TS via IJOIN. Channel=" + params[0] + " RemoteTS=" + params[1] + " LocalTS=" + ConvToStr(chan->age));
55                         return CMD_INVALID;
56                 }
57                 apply_modes = ((params.size() > 2) && (RemoteTS == chan->age));
58         }
59         else
60                 apply_modes = false;
61
62         chan->ForceJoin(user, apply_modes ? &params[2] : NULL);
63         return CMD_SUCCESS;
64 }
65
66 CmdResult CommandResync::Handle(User* user, std::vector<std::string>& params)
67 {
68         ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Resyncing " + params[0]);
69         Channel* chan = ServerInstance->FindChan(params[0]);
70         if (!chan)
71         {
72                 // This can happen for a number of reasons, safe to ignore
73                 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Channel does not exist");
74                 return CMD_FAILURE;
75         }
76
77         TreeServer* server = Utils->FindServer(user->server);
78         if (!server)
79                 return CMD_FAILURE;
80
81         TreeSocket* socket = server->GetSocket();
82         if (!socket)
83         {
84                 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Received RESYNC with a source that is not directly connected: " + user->uuid);
85                 return CMD_INVALID;
86         }
87
88         // Send all known information about the channel
89         socket->SyncChannel(chan);
90         return CMD_SUCCESS;
91 }