Interface ChannelConnection

All Known Implementing Classes:
NettyUtil.NettyChannelConnection

public interface ChannelConnection
  • Method Details

    • flush

      void flush()
    • write

      void write(ToClientPacket packet)
    • writeAndFlush

      void writeAndFlush(ToClientPacket packet)
    • write

      void write(ToClientPacket[] packets)
    • writeAndFlush

      void writeAndFlush(ToClientPacket[] packets)
    • isActive

      boolean isActive()
    • isWritable

      boolean isWritable()
    • remoteAddress

      SocketAddress remoteAddress()
    • formatRemoteAddress

      String formatRemoteAddress()
    • disconnect

      void disconnect(@Nonnull FormattedMessage message)
    • getPacketStatsRecorder

      @Nullable PacketStatsRecorder getPacketStatsRecorder()
    • getSniHostname

      @Nullable String getSniHostname()
    • isFromSameOrigin

      boolean isFromSameOrigin(ChannelConnection other)
      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).
      Parameters:
      other - the connection to compare against
      Returns:
      true if both connections are from the same origin
    • execute

      void execute(Runnable runnable)
    • getClientCertificate

      X509Certificate getClientCertificate()
    • initTimeoutContext

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

      void updateTimeoutContext(@Nonnull String stage, @Nonnull String identifier)
      Updates the timeout context with a new stage and identifier.
      Parameters:
      stage - The new stage name.
      identifier - The new player identifier.
    • updateTimeoutContext

      void updateTimeoutContext(@Nonnull String stage)
      Updates the timeout context with a new stage, keeping the existing identifier.
      Parameters:
      stage - The new stage name.
    • setPacketTimeout

      void setPacketTimeout(@Nonnull Duration timeout)
      Sets the packet read timeout for the decoder.
      Parameters:
      timeout - The timeout duration.
    • clearPacketTimeout

      void clearPacketTimeout()
      Cancels any currently scheduled packet read timeout.
    • setStageTimeout

      void setStageTimeout(@Nonnull String stage, @Nonnull Duration timeout, @Nonnull BooleanSupplier condition, @Nonnull Runnable onTimeout)
      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.
      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

      void clearStageTimeout()
      Cancels any currently scheduled stage timeout.
    • logConnectionTimings

      void logConnectionTimings(@Nonnull String message, @Nonnull Level level)
      Logs connection timing information, tracking the time delta between consecutive calls.
      Parameters:
      message - The message describing the event.
      level - The log level.
    • setupAuxiliaryChannels

      @Nonnull CompletableFuture<Void> setupAuxiliaryChannels(@Nonnull ConnectionHandler handler, @Nonnull BiConsumer<NetworkChannel, ChannelConnection> onChannelReady)
      Creates auxiliary network channels (e.g., Chunks, WorldMap) for this connection. For multiplexed transports (QUIC), creates separate unidirectional streams.
      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

      void setChannelHandler(@Nonnull ConnectionHandler handler)
      Replaces the current packet handler on this connection. Manages lifecycle callbacks (unregistered/registered) on old and new handlers.
      Parameters:
      handler - The new handler to set
    • closeConnection

      void closeConnection()
    • closeApplicationConnection

      void closeApplicationConnection()
      Closes the connection gracefully as an application-level close with no error. Use this after sending a Disconnect packet for clean shutdown.
    • closeApplicationConnection

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

      void closeApplicationConnection(@Nonnull QuicApplicationErrorCode errorCode, @Nonnull FormattedMessage reason)
      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.
      Parameters:
      errorCode - Application-defined error code
      reason - Reason message carried in the CONNECTION_CLOSE reason phrase
    • updateStreamPriority

      void updateStreamPriority(int urgency, boolean incremental)
      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.
      Parameters:
      urgency - The urgency level (0 = highest priority)
      incremental - Whether this stream's data can be interleaved with other streams