Class FMLHandshakeHandler
- java.lang.Object
-
- net.minecraftforge.fml.network.FMLHandshakeHandler
-
public class FMLHandshakeHandler extends java.lang.Object
Instance responsible for handling the overall FML network handshake.An instance is created during
CHandshakePacket
handling, and attached to theNetworkManager.channel
viaFMLNetworkConstants.FML_HANDSHAKE_HANDLER
.The
FMLNetworkConstants.handshakeChannel
is aSimpleChannel
with standard messages flowing in both directions.The
loginWrapper
transforms these messages intoCCustomPayloadLoginPacket
andSCustomPayloadLoginPacket
compatible messages, by means of wrapping.The handshake is ticked
tickLogin(NetworkManager)
from theServerLoginNetHandler#update()
method, utilizing theServerLoginNetHandler.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 theNetworkRegistry
for anyNetworkRegistry.LoginPayload
they wish to supply.The collected
NetworkRegistry.LoginPayload
are sent, one per tick, via theFMLLoginWrapper.wrapPacket(ResourceLocation, PacketBuffer)
mechanism to the incoming client connection. Each packet is indexed vianet.minecraft.network.login.client.CCustomPayloadLoginPacket#transaction
, 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.
-
-
Field Summary
Fields Modifier and Type Field Description private NetworkDirection
direction
(package private) static org.apache.logging.log4j.Marker
FMLHSMARKER
private static org.apache.logging.log4j.Logger
LOGGER
private static FMLLoginWrapper
loginWrapper
private NetworkManager
manager
private java.util.List<NetworkRegistry.LoginPayload>
messageList
private int
packetPosition
private java.util.Set<ResourceLocation>
registriesToReceive
private java.util.Map<ResourceLocation,java.lang.String>
registryHashes
private java.util.Map<ResourceLocation,ForgeRegistry.Snapshot>
registrySnapshots
private java.util.List<java.lang.Integer>
sentMessages
-
Constructor Summary
Constructors Modifier Constructor Description private
FMLHandshakeHandler(NetworkManager networkManager, NetworkDirection side)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <MSG extends java.util.function.IntSupplier>
java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>>biConsumerFor(ThreeConsumer<FMLHandshakeHandler,? super MSG,? super java.util.function.Supplier<NetworkEvent.Context>> consumer)
Transforms a two-argument instance method reference into aBiConsumer
based on thegetHandshake(Supplier)
function.private static FMLHandshakeHandler
getHandshake(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
Retrieve the handshake from theNetworkEvent.Context
(package private) void
handleClientAck(FMLHandshakeMessages.C2SAcknowledge msg, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
(package private) void
handleClientModListOnServer(FMLHandshakeMessages.C2SModListReply clientModList, java.util.function.Supplier<NetworkEvent.Context> c)
(package private) void
handleConfigSync(FMLHandshakeMessages.S2CConfigData msg, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
(package private) <MSG extends java.util.function.IntSupplier>
voidhandleIndexedMessage(MSG message, java.util.function.Supplier<NetworkEvent.Context> c)
private boolean
handleRegistryLoading(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
(package private) void
handleRegistryMessage(FMLHandshakeMessages.S2CRegistry registryPacket, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
(package private) void
handleServerModListOnClient(FMLHandshakeMessages.S2CModList serverModList, java.util.function.Supplier<NetworkEvent.Context> c)
static <MSG extends java.util.function.IntSupplier>
java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>>indexFirst(ThreeConsumer<FMLHandshakeHandler,MSG,java.util.function.Supplier<NetworkEvent.Context>> next)
Transforms a two-argument instance method reference into aBiConsumer
biConsumerFor(ThreeConsumer)
, first calling the#handleIndexedMessage(FMLHandshakeMessages.LoginIndexedMessage, Supplier)
method to handle index tracking.(package private) static void
registerHandshake(NetworkManager manager, NetworkDirection direction)
Create a new handshake instance.(package private) static boolean
tickLogin(NetworkManager networkManager)
boolean
tickServer()
FML will send packets, from Server to Client, from the messages queue until the queue is drained.
-
-
-
Field Detail
-
FMLHSMARKER
static final org.apache.logging.log4j.Marker FMLHSMARKER
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
loginWrapper
private static final FMLLoginWrapper loginWrapper
-
messageList
private java.util.List<NetworkRegistry.LoginPayload> messageList
-
sentMessages
private java.util.List<java.lang.Integer> sentMessages
-
direction
private final NetworkDirection direction
-
manager
private final NetworkManager manager
-
packetPosition
private int packetPosition
-
registrySnapshots
private java.util.Map<ResourceLocation,ForgeRegistry.Snapshot> registrySnapshots
-
registriesToReceive
private java.util.Set<ResourceLocation> registriesToReceive
-
registryHashes
private java.util.Map<ResourceLocation,java.lang.String> registryHashes
-
-
Constructor Detail
-
FMLHandshakeHandler
private FMLHandshakeHandler(NetworkManager networkManager, NetworkDirection side)
-
-
Method Detail
-
registerHandshake
static void registerHandshake(NetworkManager manager, NetworkDirection direction)
Create a new handshake instance. Called when connection is first created during theCHandshakePacket
handling.- Parameters:
manager
- The network manager for this connectiondirection
- TheNetworkDirection
for this connection:NetworkDirection.LOGIN_TO_SERVER
orNetworkDirection.LOGIN_TO_CLIENT
-
tickLogin
static boolean tickLogin(NetworkManager networkManager)
-
biConsumerFor
public static <MSG extends java.util.function.IntSupplier> java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> biConsumerFor(ThreeConsumer<FMLHandshakeHandler,? super MSG,? super java.util.function.Supplier<NetworkEvent.Context>> consumer)
Transforms a two-argument instance method reference into aBiConsumer
based on thegetHandshake(Supplier)
function. This should only be used for login message types.- Type Parameters:
MSG
- message type- Parameters:
consumer
- A two argument instance method reference- Returns:
- A
BiConsumer
for use in message handling
-
indexFirst
public static <MSG extends java.util.function.IntSupplier> java.util.function.BiConsumer<MSG,java.util.function.Supplier<NetworkEvent.Context>> indexFirst(ThreeConsumer<FMLHandshakeHandler,MSG,java.util.function.Supplier<NetworkEvent.Context>> next)
Transforms a two-argument instance method reference into aBiConsumer
biConsumerFor(ThreeConsumer)
, first calling the#handleIndexedMessage(FMLHandshakeMessages.LoginIndexedMessage, Supplier)
method to handle index tracking. Used for client to server replies. This should only be used for login messages.- Type Parameters:
MSG
- message type- Parameters:
next
- The method reference to call after index handling- Returns:
- A
BiConsumer
for use in message handling
-
getHandshake
private static FMLHandshakeHandler getHandshake(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
Retrieve the handshake from theNetworkEvent.Context
- Parameters:
contextSupplier
- theNetworkEvent.Context
- Returns:
- The handshake handler for the connection
-
handleServerModListOnClient
void handleServerModListOnClient(FMLHandshakeMessages.S2CModList serverModList, java.util.function.Supplier<NetworkEvent.Context> c)
-
handleIndexedMessage
<MSG extends java.util.function.IntSupplier> void handleIndexedMessage(MSG message, java.util.function.Supplier<NetworkEvent.Context> c)
-
handleClientModListOnServer
void handleClientModListOnServer(FMLHandshakeMessages.C2SModListReply clientModList, java.util.function.Supplier<NetworkEvent.Context> c)
-
handleRegistryMessage
void handleRegistryMessage(FMLHandshakeMessages.S2CRegistry registryPacket, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
-
handleRegistryLoading
private boolean handleRegistryLoading(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
-
handleClientAck
void handleClientAck(FMLHandshakeMessages.C2SAcknowledge msg, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
-
handleConfigSync
void handleConfigSync(FMLHandshakeMessages.S2CConfigData msg, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
-
tickServer
public boolean tickServer()
FML will send packets, from Server to Client, from the messages queue until the queue is drained. Each message will be indexed, and placed into the "pending acknowledgement" queue. As indexed packets are received at the server, they will be removed from the "pending acknowledgement" queue. Once the pending queue is drained, this method returns true - indicating that login processing can proceed to the next step.- Returns:
- true if there is no more need to tick this login connection.
-
-