#include "treeserver.h"
#include "treesocket.h"
-CmdResult CommandIJoin::HandleRemote(const std::vector<std::string>& params, RemoteUser* user)
+CmdResult CommandIJoin::HandleRemote(RemoteUser* user, std::vector<std::string>& params)
{
Channel* chan = ServerInstance->FindChan(params[0]);
if (!chan)
// Ignore the join and send RESYNC, this will result in the remote server sending all channel data to us
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received IJOIN for non-existant channel: " + params[0]);
- parameterlist p;
- p.push_back(params[0]);
- SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
- Utils->DoOneToOne(ServerInstance->Config->GetSID(), "RESYNC", p, user->server);
+ CmdBuilder("RESYNC").push(params[0]).Unicast(user);
return CMD_FAILURE;
}
bool apply_modes;
- if (params.size() > 1)
+ if (params.size() > 2)
{
- time_t RemoteTS = ConvToInt(params[1]);
- if (!RemoteTS)
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]);
- return CMD_INVALID;
- }
-
+ time_t RemoteTS = ServerCommand::ExtractTS(params[2]);
if (RemoteTS < chan->age)
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Attempted to lower TS via IJOIN. Channel=" + params[0] + " RemoteTS=" + params[1] + " LocalTS=" + ConvToStr(chan->age));
- return CMD_INVALID;
- }
- apply_modes = ((params.size() > 2) && (RemoteTS == chan->age));
+ throw ProtocolException("Attempted to lower TS via IJOIN. LocalTS=" + ConvToStr(chan->age));
+ apply_modes = ((params.size() > 3) && (RemoteTS == chan->age));
}
else
apply_modes = false;
- chan->ForceJoin(user, apply_modes ? ¶ms[2] : NULL);
+ // Join the user and set the membership id to what they sent
+ Membership* memb = chan->ForceJoin(user, apply_modes ? ¶ms[3] : NULL);
+ if (!memb)
+ return CMD_FAILURE;
+
+ memb->id = Membership::IdFromString(params[1]);
return CMD_SUCCESS;
}
-CmdResult CommandResync::HandleServer(const std::vector<std::string>& params, FakeUser* user)
+CmdResult CommandResync::HandleServer(TreeServer* server, std::vector<std::string>& params)
{
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Resyncing " + params[0]);
Channel* chan = ServerInstance->FindChan(params[0]);
return CMD_FAILURE;
}
- SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
- TreeServer* server = Utils->FindServer(user->server);
- if (!server)
- return CMD_FAILURE;
-
- TreeSocket* socket = server->GetSocket();
- if (!socket)
- {
- ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Received RESYNC with a source that is not directly connected: " + user->uuid);
- return CMD_INVALID;
- }
+ if (!server->IsLocal())
+ throw ProtocolException("RESYNC from a server that is not directly connected");
// Send all known information about the channel
- socket->SyncChannel(chan);
+ server->GetSocket()->SyncChannel(chan);
return CMD_SUCCESS;
}