Class HandshakeHandler

java.lang.Object
net.minecraftforge.network.HandshakeHandler

public class HandshakeHandler extends Object
Instance responsible for handling the overall FML impl handshake.

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

The NetworkConstants.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.impl.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 LoginWrapper 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.