]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/ijoin.cpp
637321bcb9f81cfa8af7cab4dcbb2802fe8bd256
[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(RemoteUser* 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                 CmdBuilder("RESYNC").push(params[0]).Unicast(user);
36
37                 return CMD_FAILURE;
38         }
39
40         bool apply_modes;
41         if (params.size() > 1)
42         {
43                 time_t RemoteTS = ConvToInt(params[1]);
44                 if (!RemoteTS)
45                 {
46                         ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]);
47                         return CMD_INVALID;
48                 }
49
50                 if (RemoteTS < chan->age)
51                         throw ProtocolException("Attempted to lower TS via IJOIN. LocalTS=" + ConvToStr(chan->age));
52                 apply_modes = ((params.size() > 2) && (RemoteTS == chan->age));
53         }
54         else
55                 apply_modes = false;
56
57         chan->ForceJoin(user, apply_modes ? &params[2] : NULL);
58         return CMD_SUCCESS;
59 }
60
61 CmdResult CommandResync::HandleServer(TreeServer* server, std::vector<std::string>& params)
62 {
63         ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Resyncing " + params[0]);
64         Channel* chan = ServerInstance->FindChan(params[0]);
65         if (!chan)
66         {
67                 // This can happen for a number of reasons, safe to ignore
68                 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Channel does not exist");
69                 return CMD_FAILURE;
70         }
71
72         if (!server->IsLocal())
73                 throw ProtocolException("RESYNC from a server that is not directly connected");
74
75         // Send all known information about the channel
76         server->GetSocket()->SyncChannel(chan);
77         return CMD_SUCCESS;
78 }