Class FMLHandshakeHandler

java.lang.Object
net.minecraftforge.fmllegacy.network.FMLHandshakeHandler

public class FMLHandshakeHandler extends Object
Instance responsible for handling the overall FML network handshake.

An instance is created during ClientIntentionPacket handling, and attached to the Connection.channel() via FMLNetworkConstants.FML_HANDSHAKE_HANDLER.

The FMLNetworkConstants.handshakeChannel is a SimpleChannel with standard messages flowing in both directions.

The loginWrapper transforms these messages into ServerboundCustomQueryPacket and ClientboundCustomQueryPacket compatible messages, by means of wrapping.

The handshake is ticked #tickLogin(NetworkManager) from the ServerLoginPacketListenerImpl.tick() method, utilizing the ServerLoginPacketListenerImpl.State#NEGOTIATING state, which is otherwise unused in vanilla code.

During client to server initiation, on the server, the NetworkEvent.GatherLoginPayloadsEvent is fired, which solicits all registered channels at the NetworkRegistry for any NetworkRegistry.LoginPayload they wish to supply.

The collected NetworkRegistry.LoginPayload are sent, one per tick, via the FMLLoginWrapper#wrapPacket(ResourceLocation, net.minecraft.network.FriendlyByteBuf) mechanism to the incoming client connection. Each packet is indexed via ServerboundCustomQueryPacket.getTransactionId(), which is the only mechanism available for tracking request/response pairs.

Each packet sent from the server should be replied by the client, though not necessarily in sent order. The reply should contain the index of the server's packet it is replying to. The FMLLoginWrapper class handles indexing replies correctly automatically.

Once all packets have been dispatched, we wait for all replies to be received. Once all replies are received, the final login phase will commence.