类 HandshakeHandler
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.
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明private final NetworkDirection
(专用程序包) static final org.apache.logging.log4j.Marker
private static final org.apache.logging.log4j.Logger
private static final LoginWrapper
private final Connection
private List<NetworkRegistry.LoginPayload>
private boolean
private int
private Set<ResourceLocation>
private Map<ResourceLocation,
String> private Map<ResourceLocation,
ForgeRegistry.Snapshot> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static <MSG extends IntSupplier>
BiConsumer<MSG,Supplier<NetworkEvent.Context>> biConsumerFor
(HandshakeHandler.HandshakeConsumer<MSG> consumer) Transforms a two-argument instance method reference into aBiConsumer
based on thegetHandshake(Supplier)
function.private static HandshakeHandler
getHandshake
(Supplier<NetworkEvent.Context> contextSupplier) Retrieve the handshake from theNetworkEvent.Context
(专用程序包) void
handleClientAck
(HandshakeMessages.C2SAcknowledge msg, Supplier<NetworkEvent.Context> contextSupplier) (专用程序包) void
handleClientModListOnServer
(HandshakeMessages.C2SModListReply clientModList, Supplier<NetworkEvent.Context> c) (专用程序包) void
handleConfigSync
(HandshakeMessages.S2CConfigData msg, Supplier<NetworkEvent.Context> contextSupplier) (专用程序包) <MSG extends IntSupplier>
voidhandleIndexedMessage
(MSG message, Supplier<NetworkEvent.Context> c) (专用程序包) void
handleModData
(HandshakeMessages.S2CModData serverModData, Supplier<NetworkEvent.Context> c) (专用程序包) void
handleModMismatchData
(HandshakeMessages.S2CChannelMismatchData modMismatchData, Supplier<NetworkEvent.Context> c) private boolean
handleRegistryLoading
(Supplier<NetworkEvent.Context> contextSupplier) (专用程序包) void
handleRegistryMessage
(HandshakeMessages.S2CRegistry registryPacket, Supplier<NetworkEvent.Context> contextSupplier) (专用程序包) void
handleServerModListOnClient
(HandshakeMessages.S2CModList serverModList, Supplier<NetworkEvent.Context> c) static <MSG extends IntSupplier>
BiConsumer<MSG,Supplier<NetworkEvent.Context>> indexFirst
(HandshakeHandler.HandshakeConsumer<MSG> next) Transforms a two-argument instance method reference into aBiConsumer
biConsumerFor(HandshakeConsumer)
, first calling thehandleIndexedMessage(IntSupplier, Supplier)
method to handle index tracking.static boolean
packetNeedsResponse
(Connection mgr, int packetPosition) Helper method to determine if the S2C packet at the given packet position needs a response in form of a packet handled inhandleIndexedMessage(MSG, java.util.function.Supplier<net.minecraftforge.network.NetworkEvent.Context>)
for the handshake to progress.(专用程序包) static void
registerHandshake
(Connection manager, NetworkDirection direction) Create a new handshake instance.(专用程序包) static boolean
tickLogin
(Connection networkManager) boolean
FML will send packets, from Server to Client, from the messages queue until the queue is drained.
-
字段详细资料
-
FMLHSMARKER
static final org.apache.logging.log4j.Marker FMLHSMARKER -
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
loginWrapper
-
messageList
-
sentMessages
-
direction
-
manager
-
packetPosition
private int packetPosition -
registrySnapshots
-
registriesToReceive
-
registryHashes
-
negotiationStarted
private boolean negotiationStarted -
pendingFutures
-
-
构造器详细资料
-
HandshakeHandler
-
-
方法详细资料
-
registerHandshake
Create a new handshake instance. Called when connection is first created during theClientIntentionPacket
handling.- 参数:
manager
- The impl manager for this connectiondirection
- TheNetworkDirection
for this connection:NetworkDirection.LOGIN_TO_SERVER
orNetworkDirection.LOGIN_TO_CLIENT
-
tickLogin
-
biConsumerFor
public static <MSG extends IntSupplier> BiConsumer<MSG,Supplier<NetworkEvent.Context>> biConsumerFor(HandshakeHandler.HandshakeConsumer<MSG> consumer) Transforms a two-argument instance method reference into aBiConsumer
based on thegetHandshake(Supplier)
function. This should only be used for login message types.- 类型参数:
MSG
- message type- 参数:
consumer
- A two argument instance method reference- 返回:
- A
BiConsumer
for use in message handling
-
indexFirst
public static <MSG extends IntSupplier> BiConsumer<MSG,Supplier<NetworkEvent.Context>> indexFirst(HandshakeHandler.HandshakeConsumer<MSG> next) Transforms a two-argument instance method reference into aBiConsumer
biConsumerFor(HandshakeConsumer)
, first calling thehandleIndexedMessage(IntSupplier, Supplier)
method to handle index tracking. Used for client to server replies. This should only be used for login messages.- 类型参数:
MSG
- message type- 参数:
next
- The method reference to call after index handling- 返回:
- A
BiConsumer
for use in message handling
-
getHandshake
Retrieve the handshake from theNetworkEvent.Context
- 参数:
contextSupplier
- theNetworkEvent.Context
- 返回:
- The handshake handler for the connection
-
handleServerModListOnClient
void handleServerModListOnClient(HandshakeMessages.S2CModList serverModList, Supplier<NetworkEvent.Context> c) -
handleModData
-
handleIndexedMessage
-
handleClientModListOnServer
void handleClientModListOnServer(HandshakeMessages.C2SModListReply clientModList, Supplier<NetworkEvent.Context> c) -
handleModMismatchData
void handleModMismatchData(HandshakeMessages.S2CChannelMismatchData modMismatchData, Supplier<NetworkEvent.Context> c) -
handleRegistryMessage
void handleRegistryMessage(HandshakeMessages.S2CRegistry registryPacket, Supplier<NetworkEvent.Context> contextSupplier) -
handleRegistryLoading
-
handleClientAck
void handleClientAck(HandshakeMessages.C2SAcknowledge msg, Supplier<NetworkEvent.Context> contextSupplier) -
handleConfigSync
void handleConfigSync(HandshakeMessages.S2CConfigData msg, 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.- 返回:
- true if there is no more need to tick this login connection.
-
packetNeedsResponse
Helper method to determine if the S2C packet at the given packet position needs a response in form of a packet handled inhandleIndexedMessage(MSG, java.util.function.Supplier<net.minecraftforge.network.NetworkEvent.Context>)
for the handshake to progress.- 参数:
mgr
- The impl manager for this connectionpacketPosition
- The packet position of the packet that the status is queried of- 返回:
- true if the packet at the given packet position needs a response and thus may stop the handshake from progressing
-