Record Class NettyUtil.NettyChannelConnection

java.lang.Object
java.lang.Record
com.hypixel.hytale.server.core.io.netty.NettyUtil.NettyChannelConnection
All Implemented Interfaces:
ChannelConnection
Enclosing class:
NettyUtil

public static record NettyUtil.NettyChannelConnection(io.netty.channel.Channel channel) extends Record implements ChannelConnection
  • Constructor Details

    • NettyChannelConnection

      public NettyChannelConnection(io.netty.channel.Channel channel)
      Creates an instance of a NettyChannelConnection record class.
      Parameters:
      channel - the value for the channel record component
  • Method Details

    • flush

      public void flush()
      Specified by:
      flush in interface ChannelConnection
    • write

      public void write(ToClientPacket packet)
      Specified by:
      write in interface ChannelConnection
    • writeAndFlush

      public void writeAndFlush(ToClientPacket packet)
      Specified by:
      writeAndFlush in interface ChannelConnection
    • write

      public void write(ToClientPacket[] packets)
      Specified by:
      write in interface ChannelConnection
    • writeAndFlush

      public void writeAndFlush(ToClientPacket[] packets)
      Specified by:
      writeAndFlush in interface ChannelConnection
    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface ChannelConnection
    • isWritable

      public boolean isWritable()
      Specified by:
      isWritable in interface ChannelConnection
    • remoteAddress

      public SocketAddress remoteAddress()
      Specified by:
      remoteAddress in interface ChannelConnection
    • formatRemoteAddress

      public String formatRemoteAddress()
      Specified by:
      formatRemoteAddress in interface ChannelConnection
    • disconnect

      public void disconnect(@Nonnull FormattedMessage message)
      Specified by:
      disconnect in interface ChannelConnection
    • getPacketStatsRecorder

      @Nullable public PacketStatsRecorder getPacketStatsRecorder()
      Specified by:
      getPacketStatsRecorder in interface ChannelConnection
    • getSniHostname

      @Nullable public String getSniHostname()
      Specified by:
      getSniHostname in interface ChannelConnection
    • isFromSameOrigin

      public boolean isFromSameOrigin(ChannelConnection other)
      Description copied from interface: ChannelConnection
      Tests if this connection and other come from the same remote origin. A reconnecting player opens a new connection, so this must compare remote addresses. It must not compare connection identity, which is never equal across two connections. Implementations delegate to ConnectionOrigin.isFromSameOrigin(SocketAddress, SocketAddress).
      Specified by:
      isFromSameOrigin in interface ChannelConnection
      Parameters:
      other - the connection to compare against
      Returns:
      true if both connections are from the same origin
    • execute

      public void execute(Runnable runnable)
      Specified by:
      execute in interface ChannelConnection
    • setupAuxiliaryChannels

      @Nonnull public CompletableFuture<Void> setupAuxiliaryChannels(@Nonnull ConnectionHandler handler, @Nonnull BiConsumer<NetworkChannel, ChannelConnection> onChannelReady)
      Description copied from interface: ChannelConnection
      Creates auxiliary network channels (e.g., Chunks, WorldMap) for this connection. For multiplexed transports (QUIC), creates separate unidirectional streams.
      Specified by:
      setupAuxiliaryChannels in interface ChannelConnection
      Parameters:
      handler - The connection handler for pipeline setup on new streams.
      onChannelReady - Called for each auxiliary channel when it is ready, with the NetworkChannel and the corresponding ChannelConnection.
      Returns:
      a future that completes when all auxiliary channels are set up.
    • setChannelHandler

      public void setChannelHandler(@Nonnull ConnectionHandler handler)
      Description copied from interface: ChannelConnection
      Replaces the current packet handler on this connection. Manages lifecycle callbacks (unregistered/registered) on old and new handlers.
      Specified by:
      setChannelHandler in interface ChannelConnection
      Parameters:
      handler - The new handler to set
    • getClientCertificate

      public X509Certificate getClientCertificate()
      Specified by:
      getClientCertificate in interface ChannelConnection
    • updateStreamPriority

      public void updateStreamPriority(int urgency, boolean incremental)
      Description copied from interface: ChannelConnection
      Updates the QUIC stream priority for this connection's stream. Lower urgency values indicate higher priority. Incremental streams may be interleaved with other streams at the same urgency level.
      Specified by:
      updateStreamPriority in interface ChannelConnection
      Parameters:
      urgency - The urgency level (0 = highest priority)
      incremental - Whether this stream's data can be interleaved with other streams
    • initTimeoutContext

      public void initTimeoutContext(@Nonnull String stage, @Nonnull String identifier)
      Description copied from interface: ChannelConnection
      Initializes the timeout context for a new connection. Call this once when the first handler is registered.
      Specified by:
      initTimeoutContext in interface ChannelConnection
      Parameters:
      stage - The initial stage name.
      identifier - The player identifier (typically remote address at this point).
    • updateTimeoutContext

      public void updateTimeoutContext(@Nonnull String stage, @Nonnull String identifier)
      Description copied from interface: ChannelConnection
      Updates the timeout context with a new stage and identifier.
      Specified by:
      updateTimeoutContext in interface ChannelConnection
      Parameters:
      stage - The new stage name.
      identifier - The new player identifier.
    • updateTimeoutContext

      public void updateTimeoutContext(@Nonnull String stage)
      Description copied from interface: ChannelConnection
      Updates the timeout context with a new stage, keeping the existing identifier.
      Specified by:
      updateTimeoutContext in interface ChannelConnection
      Parameters:
      stage - The new stage name.
    • setPacketTimeout

      public void setPacketTimeout(@Nonnull Duration timeout)
      Description copied from interface: ChannelConnection
      Sets the packet read timeout for the decoder.
      Specified by:
      setPacketTimeout in interface ChannelConnection
      Parameters:
      timeout - The timeout duration.
    • clearPacketTimeout

      public void clearPacketTimeout()
      Description copied from interface: ChannelConnection
      Cancels any currently scheduled packet read timeout.
      Specified by:
      clearPacketTimeout in interface ChannelConnection
    • setStageTimeout

      public void setStageTimeout(@Nonnull String stage, @Nonnull Duration timeout, @Nonnull BooleanSupplier condition, @Nonnull Runnable onTimeout)
      Description copied from interface: ChannelConnection
      Schedules a stage timeout that fires the given callback if the condition is not met within the specified duration. Cancels any previously scheduled stage timeout.
      Specified by:
      setStageTimeout in interface ChannelConnection
      Parameters:
      stage - The stage name (for logging).
      timeout - The timeout duration.
      condition - Returns true if the stage completed successfully (timeout should not fire).
      onTimeout - Callback to run when the timeout fires and the condition is not met.
    • clearStageTimeout

      public void clearStageTimeout()
      Description copied from interface: ChannelConnection
      Cancels any currently scheduled stage timeout.
      Specified by:
      clearStageTimeout in interface ChannelConnection
    • logConnectionTimings

      public void logConnectionTimings(@Nonnull String message, @Nonnull Level level)
      Description copied from interface: ChannelConnection
      Logs connection timing information, tracking the time delta between consecutive calls.
      Specified by:
      logConnectionTimings in interface ChannelConnection
      Parameters:
      message - The message describing the event.
      level - The log level.
    • closeConnection

      public void closeConnection()
      Specified by:
      closeConnection in interface ChannelConnection
    • closeApplicationConnection

      public void closeApplicationConnection()
      Description copied from interface: ChannelConnection
      Closes the connection gracefully as an application-level close with no error. Use this after sending a Disconnect packet for clean shutdown.
      Specified by:
      closeApplicationConnection in interface ChannelConnection
    • closeApplicationConnection

      public void closeApplicationConnection(@Nonnull QuicApplicationErrorCode errorCode)
      Description copied from interface: ChannelConnection
      Closes the connection gracefully with a specific application error code. For QUIC, sends an APPLICATION_CLOSE frame to properly notify the client.
      Specified by:
      closeApplicationConnection in interface ChannelConnection
      Parameters:
      errorCode - Application-defined error code
    • closeApplicationConnection

      public void closeApplicationConnection(@Nonnull QuicApplicationErrorCode errorCode, @Nonnull FormattedMessage reason)
      Description copied from interface: ChannelConnection
      Closes the connection gracefully with an application error code and reason message. The reason is serialized as a FormattedMessage into the QUIC CONNECTION_CLOSE frame so the peer can render a localized disconnect reason.
      Specified by:
      closeApplicationConnection in interface ChannelConnection
      Parameters:
      errorCode - Application-defined error code
      reason - Reason message carried in the CONNECTION_CLOSE reason phrase
    • equals

      public boolean equals(Object obj)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      @Nonnull public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • channel

      public io.netty.channel.Channel channel()
      Returns the value of the channel record component.
      Returns:
      the value of the channel record component