]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/ijoin.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / ijoin.cpp
index 8342e9d2404c870d2a2886ff457e718bcfff65bf..3d83a61de60d49e67dc8967b192892a9574e004d 100644 (file)
@@ -1,7 +1,9 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2013-2014, 2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
 #include "treeserver.h"
 #include "treesocket.h"
 
-CmdResult CommandIJoin::Handle(User* user, std::vector<std::string>& params)
+CmdResult CommandIJoin::HandleRemote(RemoteUser* user, Params& params)
 {
        Channel* chan = ServerInstance->FindChan(params[0]);
        if (!chan)
        {
                // Desync detected, recover
                // 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]);
+               ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Received IJOIN for nonexistent channel: " + params[0]);
 
-               parameterlist p;
-               p.push_back(params[0]);
-               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() > 3)
        {
-               time_t RemoteTS = ConvToInt(params[1]);
-               if (!RemoteTS)
-               {
-                       ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]);
-                       return CMD_INVALID;
-               }
-
-               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));
+               time_t RemoteTS = ServerCommand::ExtractTS(params[2]);
+               apply_modes = (RemoteTS <= chan->age);
        }
        else
                apply_modes = false;
 
-       chan->ForceJoin(user, apply_modes ? &params[2] : NULL);
+       // Join the user and set the membership id to what they sent
+       Membership* memb = chan->ForceJoin(user, apply_modes ? &params[3] : NULL);
+       if (!memb)
+               return CMD_FAILURE;
+
+       memb->id = Membership::IdFromString(params[1]);
        return CMD_SUCCESS;
 }
 
-CmdResult CommandResync::Handle(User* user, std::vector<std::string>& params)
+CmdResult CommandResync::HandleServer(TreeServer* server, CommandBase::Params& params)
 {
        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Resyncing " + params[0]);
        Channel* chan = ServerInstance->FindChan(params[0]);
@@ -74,18 +68,10 @@ CmdResult CommandResync::Handle(User* user, std::vector<std::string>& params)
                return CMD_FAILURE;
        }
 
-       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;
 }