public class FMLHandshakeHandler
extends java.lang.Object
An instance is created during CHandshakePacket
handling, and attached
to the NetworkManager.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 CCustomPayloadLoginPacket
and SCustomPayloadLoginPacket
compatible messages, by means of wrapping.
The handshake is ticked tickLogin(NetworkManager)
from the ServerLoginNetHandler#update()
method,
utilizing the ServerLoginNetHandler.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, PacketBuffer)
mechanism to the incoming client connection. Each
packet is indexed via 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.
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
private |
FMLHandshakeHandler(NetworkManager networkManager,
NetworkDirection side) |
Modifier and Type | Method and Description |
---|---|
static <MSG extends java.util.function.IntSupplier> |
biConsumerFor(ThreeConsumer<FMLHandshakeHandler,? super MSG,? super java.util.function.Supplier<NetworkEvent.Context>> consumer)
Transforms a two-argument instance method reference into a
BiConsumer based on the getHandshake(Supplier) function. |
private static FMLHandshakeHandler |
getHandshake(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
Retrieve the handshake from the
NetworkEvent.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> |
handleIndexedMessage(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> |
indexFirst(ThreeConsumer<FMLHandshakeHandler,MSG,java.util.function.Supplier<NetworkEvent.Context>> next)
Transforms a two-argument instance method reference into a
BiConsumer 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.
|
static final org.apache.logging.log4j.Marker FMLHSMARKER
private static final org.apache.logging.log4j.Logger LOGGER
private static final FMLLoginWrapper loginWrapper
private java.util.List<NetworkRegistry.LoginPayload> messageList
private java.util.List<java.lang.Integer> sentMessages
private final NetworkDirection direction
private final NetworkManager manager
private int packetPosition
private java.util.Map<ResourceLocation,ForgeRegistry.Snapshot> registrySnapshots
private java.util.Set<ResourceLocation> registriesToReceive
private java.util.Map<ResourceLocation,java.lang.String> registryHashes
private FMLHandshakeHandler(NetworkManager networkManager, NetworkDirection side)
static void registerHandshake(NetworkManager manager, NetworkDirection direction)
CHandshakePacket
handling.manager
- The network manager for this connectiondirection
- The NetworkDirection
for this connection: NetworkDirection.LOGIN_TO_SERVER
or NetworkDirection.LOGIN_TO_CLIENT
static boolean tickLogin(NetworkManager networkManager)
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)
BiConsumer
based on the getHandshake(Supplier)
function.
This should only be used for login message types.MSG
- message typeconsumer
- A two argument instance method referenceBiConsumer
for use in message handlingpublic 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)
BiConsumer
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.MSG
- message typenext
- The method reference to call after index handlingBiConsumer
for use in message handlingprivate static FMLHandshakeHandler getHandshake(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
NetworkEvent.Context
contextSupplier
- the NetworkEvent.Context
void handleServerModListOnClient(FMLHandshakeMessages.S2CModList serverModList, java.util.function.Supplier<NetworkEvent.Context> c)
<MSG extends java.util.function.IntSupplier> void handleIndexedMessage(MSG message, java.util.function.Supplier<NetworkEvent.Context> c)
void handleClientModListOnServer(FMLHandshakeMessages.C2SModListReply clientModList, java.util.function.Supplier<NetworkEvent.Context> c)
void handleRegistryMessage(FMLHandshakeMessages.S2CRegistry registryPacket, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
private boolean handleRegistryLoading(java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
void handleClientAck(FMLHandshakeMessages.C2SAcknowledge msg, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
void handleConfigSync(FMLHandshakeMessages.S2CConfigData msg, java.util.function.Supplier<NetworkEvent.Context> contextSupplier)
public boolean tickServer()