Contents
- Description
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- getChannel()
- getChannel(StreamType)
- getIdentifier()
- getProtocolVersion()
- registered(ConnectionHandler)
- unregistered(ConnectionHandler)
- handle(ToServerPacket)
- accept(ToServerPacket)
- logCloseMessage()
- closed(NetworkChannel)
- setQueuePackets(boolean)
- tryFlush()
- write(ToClientPacket...)
- write(ToClientPacket[], ToClientPacket)
- write(ToClientPacket)
- writeNoCache(ToClientPacket)
- writePacket(ToClientPacket, boolean)
- disconnect(Message)
- disconnect(FormattedMessage)
- getPacketStatsRecorder()
- getPingInfo(PongType)
- getOperationTimeoutThreshold()
- tickPing(float)
- sendPing()
- handlePong(Pong)
- getAuth()
- getAccountProfile()
- stillActive()
- getQueuedPacketsCount()
- isLocalConnection()
- isLANConnection()
- getSniHostname()
- checkStreamOpenRateLimit()
- getDisconnectReason()
- setClientReadyForChunksFuture(CompletableFuture)
- getClientReadyForChunksFuture()
- getChannel(NetworkChannel)
- setChannel(NetworkChannel, ChannelConnection)
- setChannel(StreamType, ChannelConnection)
- compareAndSetChannel(StreamType, ChannelConnection, ChannelConnection)
- getAuxiliaryChannelCount()
- logConnectionTimings(ChannelConnection, String, Level)
Class PacketHandler
java.lang.Object
com.hypixel.hytale.server.core.io.PacketHandler
- All Implemented Interfaces:
ConnectionHandler, IPacketReceiver
- Direct Known Subclasses:
GenericConnectionPacketHandler, GenericPacketHandler, InitialPacketHandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Map<NetworkChannel, io.netty.handler.codec.quic.QuicStreamPriority> Default QUIC stream priorities per network channel.static final intMaximum packet ID for sizing arrays. -
Constructor Summary
ConstructorsConstructorDescriptionPacketHandler(ChannelConnection channel, ProtocolVersion protocolVersion) Default Constructor for aPacketHandlerinstance -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaccept(ToServerPacket packet) Called to accept the given incoming packetbooleanChecks if a stream open request is rate limited.voidclosed(NetworkChannel networkChannel) Called when the affiliated network channel has been closed.booleancompareAndSetChannel(StreamType type, ChannelConnection expected, ChannelConnection newValue) Atomically replaces a channel only if it currently matches the expected value.voiddisconnect(FormattedMessage message) Called to disconnect this connection for the given reason.voiddisconnect(Message message) Called to disconnect this connection for the given reason.Returns the account to track for lookups, bans, and kicks.getAuth()intgetChannel(NetworkChannel networkChannel) getChannel(StreamType type) Returns the channel for the given stream type, or null if not set.abstract StringlongThe threshold (in milliseconds) used when timing out a client operation.getPingInfo(PongType pongType) Returns the ping info from the provided pong typeintvoidhandle(ToServerPacket packet) Called to handle the given incoming packet.voidhandlePong(Pong packet) Called to handle the provided pong packetbooleanbooleanvoidCalled to log that this handler's connection has been closed.static voidlogConnectionTimings(ChannelConnection connection, String message, Level level) Called to log connection timings for a specific network event.final voidregistered(ConnectionHandler oldHandler) Called when this handler is registered on a connection, potentially replacing an old handler.voidsendPing()Called to send a ping packet to the associated clientvoidsetChannel(NetworkChannel networkChannel, ChannelConnection channel) voidsetChannel(StreamType type, ChannelConnection channel) Sets or removes a channel for the given auxiliary stream type.voidsetClientReadyForChunksFuture(CompletableFuture<Void> clientReadyFuture) Called to set the ready for chunks completable future, for when the client player is ready for chunksvoidsetQueuePackets(boolean queuePackets) Sets whether to queue packets, or send them immediatelybooleanvoidtickPing(float dt) Called to tick the ping packet timer, sending a ping packet if the timer has finishedvoidtryFlush()Called to attempt to flush the outbound packets for this handlerfinal voidunregistered(ConnectionHandler newHandler) Called when this handler is unregistered from a connection, potentially being replaced by a new handler.voidwrite(ToClientPacket packet) Writes the packet, caching it first to prevent race conditions between the world thread and netty writing the packet.voidwrite(ToClientPacket... packets) Writes the given packets outbound to the clientvoidwrite(ToClientPacket[] packets, ToClientPacket finalPacket) This is a helper method, useful when something being sent over the network is split into multiple data packets and then a final packet that constructs that data.voidwriteNoCache(ToClientPacket packet) Writes the packet without first caching the packet.booleanwritePacket(ToClientPacket packet, boolean cache) Writes a packet to the player.
-
Field Details
-
MAX_PACKET_ID
public static final int MAX_PACKET_IDMaximum packet ID for sizing arrays. Should be > max packet ID in the protocol.- See Also:
-
DEFAULT_STREAM_PRIORITIES
@Nonnull public static final Map<NetworkChannel, io.netty.handler.codec.quic.QuicStreamPriority> DEFAULT_STREAM_PRIORITIESDefault QUIC stream priorities per network channel.
-
-
Constructor Details
-
PacketHandler
Default Constructor for aPacketHandlerinstance- Parameters:
channel- The channel affiliated with this packet handlerprotocolVersion- The network protocol version
-
-
Method Details
-
getChannel
- Returns:
- the base channel (channel 0)
-
getChannel
Returns the channel for the given stream type, or null if not set.- Parameters:
type- The stream type- Returns:
- the channel for the stream type, or null if not set
-
getIdentifier
- Returns:
- the unique identifier for this handler
-
getProtocolVersion
- Returns:
- the network protocol version for the associated channel
-
registered
Description copied from interface:ConnectionHandlerCalled when this handler is registered on a connection, potentially replacing an old handler.- Specified by:
registeredin interfaceConnectionHandler- Parameters:
oldHandler- The previous handler, or null if this is the first handler
-
unregistered
Description copied from interface:ConnectionHandlerCalled when this handler is unregistered from a connection, potentially being replaced by a new handler.- Specified by:
unregisteredin interfaceConnectionHandler- Parameters:
newHandler- The new handler replacing this one, or null
-
handle
Description copied from interface:ConnectionHandlerCalled to handle the given incoming packet.- Specified by:
handlein interfaceConnectionHandler- Parameters:
packet- The packet to be handled
-
accept
Called to accept the given incoming packet- Parameters:
packet- The packet instance to accept
-
logCloseMessage
public void logCloseMessage()Description copied from interface:ConnectionHandlerCalled to log that this handler's connection has been closed.- Specified by:
logCloseMessagein interfaceConnectionHandler
-
closed
Description copied from interface:ConnectionHandlerCalled when the affiliated network channel has been closed.- Specified by:
closedin interfaceConnectionHandler- Parameters:
networkChannel- The network channel that was closed, or null if unknown
-
setQueuePackets
public void setQueuePackets(boolean queuePackets) Sets whether to queue packets, or send them immediately- Parameters:
queuePackets-trueif packets should be queued,falseotherwise
-
tryFlush
public void tryFlush()Called to attempt to flush the outbound packets for this handler -
write
Writes the given packets outbound to the client- Parameters:
packets- The packets that are to be written
-
write
This is a helper method, useful when something being sent over the network is split into multiple data packets and then a final packet that constructs that data.- Parameters:
packets- The collection of data for the given packetfinalPacket- The final packet that constructs the data
-
write
Description copied from interface:IPacketReceiverWrites the packet, caching it first to prevent race conditions between the world thread and netty writing the packet.- Specified by:
writein interfaceIPacketReceiver- Parameters:
packet- the packet to send.
-
writeNoCache
Description copied from interface:IPacketReceiverWrites the packet without first caching the packet. This method should only be used if you don't store the sent packet to be reused. eg.packetHandler.writeNoCache(new Ping(...))- Specified by:
writeNoCachein interfaceIPacketReceiver- Parameters:
packet- the packet to send.
-
writePacket
Writes a packet to the player.- Parameters:
packet- The packet that is to be writtencache- Determines whether to generate a cached copy of the packet before writing, ensuring that if the packet is modified after being written it can't race with the data actually being written via netty.- Returns:
trueif the packet was written,falseif a packet filter swallowed it.
-
disconnect
Called to disconnect this connection for the given reason.- Parameters:
message- The formatted reason in which the connection is being disconnected
-
disconnect
Called to disconnect this connection for the given reason.- Parameters:
message- The formatted reason in which the connection is being disconnected
-
getPacketStatsRecorder
- Returns:
- the packet stats recorder for this connection, or null if not set
-
getPingInfo
Returns the ping info from the provided pong type- Parameters:
pongType- The given pong type- Returns:
- the cached ping info instance
-
getOperationTimeoutThreshold
public long getOperationTimeoutThreshold()The threshold (in milliseconds) used when timing out a client operation. -
tickPing
public void tickPing(float dt) Called to tick the ping packet timer, sending a ping packet if the timer has finished- Parameters:
dt- The delta time of the current tick
-
sendPing
public void sendPing()Called to send a ping packet to the associated client -
handlePong
Called to handle the provided pong packet- Parameters:
packet- The pong packet to be handled
-
getAuth
- Returns:
- the authentication instance for the associated player
-
getAccountProfile
Returns the account to track for lookups, bans, and kicks.Override this method for authenticated handlers. The profile must be available before registration and remain available through cleanup. The account UUID and whether this method returns
nullmust remain stable for this handler's lifetime. Keep this method nonblocking and free of side effects. Registry membership does not perform access checks.- Returns:
- the account to track, or
nullto exclude this handler
-
stillActive
public boolean stillActive()- Returns:
trueif the channel is still active,falseotherwise
-
getQueuedPacketsCount
public int getQueuedPacketsCount()- Returns:
- the count of packets that are currently queued
-
isLocalConnection
public boolean isLocalConnection()- Returns:
trueif the connection is local,falseotherwise
-
isLANConnection
public boolean isLANConnection()- Returns:
trueif the connection is LAN,falseotherwise
-
getSniHostname
-
checkStreamOpenRateLimit
public boolean checkStreamOpenRateLimit()Checks if a stream open request is rate limited. Returns true if the request should be rejected due to rate limiting. Uses atomic compare-and-swap to prevent TOCTOU races.- Returns:
- true if rate limited (reject), false if allowed
-
getDisconnectReason
- Returns:
- the current disconnect reason for the associated player
-
setClientReadyForChunksFuture
Called to set the ready for chunks completable future, for when the client player is ready for chunks- Parameters:
clientReadyFuture- The completable future to be set
-
getClientReadyForChunksFuture
- Returns:
- the completable future to execute when the client player is ready for chunks
-
getChannel
-
setChannel
-
setChannel
Sets or removes a channel for the given auxiliary stream type.- Parameters:
type- The stream typechannel- The channel, or null to remove
-
compareAndSetChannel
public boolean compareAndSetChannel(@Nonnull StreamType type, @Nullable ChannelConnection expected, @Nullable ChannelConnection newValue) Atomically replaces a channel only if it currently matches the expected value. Prevents a closing old stream from clobbering a newly-registered replacement.- Parameters:
type- The stream typeexpected- The expected current channel (or null)newValue- The new channel to set (or null to remove)- Returns:
- true if the swap succeeded, false if the current value didn't match expected
-
getAuxiliaryChannelCount
public int getAuxiliaryChannelCount()- Returns:
- the number of currently open auxiliary streams
-
logConnectionTimings
public static void logConnectionTimings(@Nonnull ChannelConnection connection, @Nonnull String message, @Nonnull Level level) Called to log connection timings for a specific network event. Delegates toChannelConnection.logConnectionTimings(String, Level).- Parameters:
connection- The associated connection to log timings formessage- The readable message of the network eventlevel- Determines the log level of the trace
-