Class Connection

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<Packet<?>>
net.minecraft.network.Connection
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
Direct Known Subclasses:
FakePlayer.FakeConnection, RateKickingConnection

public class Connection extends io.netty.channel.SimpleChannelInboundHandler<Packet<?>>
  • Field Details

    • AVERAGE_PACKETS_SMOOTHING

      private static final float AVERAGE_PACKETS_SMOOTHING
      See Also:
    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • ROOT_MARKER

      public static final org.slf4j.Marker ROOT_MARKER
    • PACKET_MARKER

      public static final org.slf4j.Marker PACKET_MARKER
    • PACKET_RECEIVED_MARKER

      public static final org.slf4j.Marker PACKET_RECEIVED_MARKER
    • PACKET_SENT_MARKER

      public static final org.slf4j.Marker PACKET_SENT_MARKER
    • NETWORK_WORKER_GROUP

      public static final Supplier<io.netty.channel.nio.NioEventLoopGroup> NETWORK_WORKER_GROUP
    • NETWORK_EPOLL_WORKER_GROUP

      public static final Supplier<io.netty.channel.epoll.EpollEventLoopGroup> NETWORK_EPOLL_WORKER_GROUP
    • LOCAL_WORKER_GROUP

      public static final Supplier<io.netty.channel.DefaultEventLoopGroup> LOCAL_WORKER_GROUP
    • INITIAL_PROTOCOL

      private static final ProtocolInfo<ServerHandshakePacketListener> INITIAL_PROTOCOL
    • receiving

      private final PacketFlow receiving
    • sendLoginDisconnect

      private volatile boolean sendLoginDisconnect
    • pendingActions

      private final Queue<Consumer<Connection>> pendingActions
    • channel

      private io.netty.channel.Channel channel
      The active channel
    • address

      private SocketAddress address
      The address of the remote party
    • disconnectListener

      @Nullable private volatile PacketListener disconnectListener
    • packetListener

      @Nullable private volatile PacketListener packetListener
      The PacketListener instance responsible for processing received packets
    • disconnectionDetails

      @Nullable private DisconnectionDetails disconnectionDetails
    • encrypted

      private boolean encrypted
    • disconnectionHandled

      private boolean disconnectionHandled
    • receivedPackets

      private int receivedPackets
    • sentPackets

      private int sentPackets
    • averageReceivedPackets

      private float averageReceivedPackets
    • averageSentPackets

      private float averageSentPackets
    • tickCount

      private int tickCount
    • handlingFault

      private boolean handlingFault
    • delayedDisconnect

      @Nullable private volatile DisconnectionDetails delayedDisconnect
    • bandwidthDebugMonitor

      @Nullable BandwidthDebugMonitor bandwidthDebugMonitor
    • inboundProtocol

      @Nullable private ProtocolInfo<?> inboundProtocol
  • Constructor Details

    • Connection

      public Connection(PacketFlow pReceiving)
  • Method Details

    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext p_129525_) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext p_129527_)
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext p_129533_, Throwable p_129534_)
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
    • channelRead0

      protected void channelRead0(io.netty.channel.ChannelHandlerContext p_129487_, Packet<?> p_129488_)
      Specified by:
      channelRead0 in class io.netty.channel.SimpleChannelInboundHandler<Packet<?>>
    • genericsFtw

      private static <T extends PacketListener> void genericsFtw(Packet<T> pPacket, PacketListener pListener)
    • validateListener

      private void validateListener(ProtocolInfo<?> pProtocolInfo, PacketListener pPacketListener)
    • syncAfterConfigurationChange

      private static void syncAfterConfigurationChange(io.netty.channel.ChannelFuture p_341671_)
    • setupInboundProtocol

      public <T extends PacketListener> void setupInboundProtocol(ProtocolInfo<T> pProtocolInfo, T pPacketInfo)
    • setupOutboundProtocol

      public void setupOutboundProtocol(ProtocolInfo<?> pProtocolInfo)
    • setListenerForServerboundHandshake

      public void setListenerForServerboundHandshake(PacketListener pPacketListener)
    • initiateServerboundStatusConnection

      public void initiateServerboundStatusConnection(String pHostName, int pPort, ClientStatusPacketListener pPacketListener)
    • initiateServerboundPlayConnection

      public void initiateServerboundPlayConnection(String pHostName, int pPort, ClientLoginPacketListener pPacketListener)
    • initiateServerboundPlayConnection

      public <S extends ServerboundPacketListener, C extends ClientboundPacketListener> void initiateServerboundPlayConnection(String pHostName, int pPort, ProtocolInfo<S> pServerboundProtocol, ProtocolInfo<C> pClientbountProtocol, C pPacketListener, boolean pIsTransfer)
    • initiateServerboundConnection

      private <S extends ServerboundPacketListener, C extends ClientboundPacketListener> void initiateServerboundConnection(String pHostName, int pPort, ProtocolInfo<S> pServerboundProtocol, ProtocolInfo<C> pClientboundProtocol, C pPacketListener, ClientIntent pIntention)
    • send

      public void send(Packet<?> pPacket)
    • send

      public void send(Packet<?> pPacket, @Nullable PacketSendListener pSendListener)
    • send

      public void send(Packet<?> pPacket, @Nullable PacketSendListener pListener, boolean pFlush)
    • runOnceConnected

      public void runOnceConnected(Consumer<Connection> pAction)
    • sendPacket

      private void sendPacket(Packet<?> pPacket, @Nullable PacketSendListener pSendListener, boolean pFlush)
    • doSendPacket

      private void doSendPacket(Packet<?> pPacket, @Nullable PacketSendListener pSendListener, boolean pFlush)
    • flushChannel

      public void flushChannel()
    • flush

      private void flush()
    • flushQueue

      private void flushQueue()
    • tick

      public void tick()
    • tickSecond

      protected void tickSecond()
    • getRemoteAddress

      public SocketAddress getRemoteAddress()
    • getLoggableAddress

      public String getLoggableAddress(boolean pLogIps)
    • disconnect

      public void disconnect(Component pMessage)
      Closes the channel with a given reason. The reason is stored for later and will be used for informational purposes (info log on server, disconnection screen on the client). This method is also called on the client when the server requests disconnection via ClientboundDisconnectPacket. Closing the channel this way does not send any disconnection packets, it simply terminates the underlying netty channel.
    • disconnect

      public void disconnect(DisconnectionDetails pDisconnectionDetails)
    • isMemoryConnection

      public boolean isMemoryConnection()
    • getReceiving

      public PacketFlow getReceiving()
    • getSending

      public PacketFlow getSending()
    • connectToServer

      public static Connection connectToServer(InetSocketAddress pAddress, boolean pUseEpollIfAvailable, @Nullable LocalSampleLogger pSampleLogger)
    • connect

      public static io.netty.channel.ChannelFuture connect(InetSocketAddress p_290034_, boolean p_290035_, Connection p_290031_)
    • outboundHandlerName

      private static String outboundHandlerName(boolean pClientbound)
    • inboundHandlerName

      private static String inboundHandlerName(boolean pServerbound)
    • configurePacketHandler

      public void configurePacketHandler(io.netty.channel.ChannelPipeline p_302007_)
    • configureSerialization

      public static void configureSerialization(io.netty.channel.ChannelPipeline p_265436_, PacketFlow p_265104_, boolean p_341592_, @Nullable BandwidthDebugMonitor p_299246_)
    • createFrameEncoder

      private static io.netty.channel.ChannelOutboundHandler createFrameEncoder(boolean p_341616_)
    • createFrameDecoder

      private static io.netty.channel.ChannelInboundHandler createFrameDecoder(@Nullable BandwidthDebugMonitor p_341605_, boolean p_341702_)
    • configureInMemoryPipeline

      public static void configureInMemoryPipeline(io.netty.channel.ChannelPipeline p_295541_, PacketFlow p_294540_)
    • connectToLocalServer

      public static Connection connectToLocalServer(SocketAddress pAddress)
      Prepares a clientside Connection for a local in-memory connection ("single player"). Establishes a connection to the socket supplied and configures the channel pipeline (only the packet handler is necessary, since this is for an in-memory connection). Returns the newly created instance.
    • setEncryptionKey

      public void setEncryptionKey(Cipher pDecryptingCipher, Cipher pEncryptingCipher)
      Enables encryption for this connection using the given decrypting and encrypting ciphers. This adds new handlers to this connection's pipeline which handle the decrypting and encrypting. This happens as part of the normal network handshake.
      See Also:
    • isEncrypted

      public boolean isEncrypted()
    • isConnected

      public boolean isConnected()
    • isConnecting

      public boolean isConnecting()
    • getPacketListener

      @Nullable public PacketListener getPacketListener()
    • getDisconnectionDetails

      @Nullable public DisconnectionDetails getDisconnectionDetails()
    • setReadOnly

      public void setReadOnly()
    • setupCompression

      public void setupCompression(int pThreshold, boolean pValidateDecompressed)
      Enables or disables compression for this connection. If threshold is >= 0 then a CompressionDecoder and CompressionEncoder are installed in the pipeline or updated if they already exist. If threshold is invalid input: '<' 0 then any such codec are removed. Compression is enabled as part of the connection handshake when the server sends ClientboundLoginCompressionPacket.
    • handleDisconnection

      public void handleDisconnection()
    • getAverageReceivedPackets

      public float getAverageReceivedPackets()
    • getAverageSentPackets

      public float getAverageSentPackets()
    • setBandwidthLogger

      public void setBandwidthLogger(LocalSampleLogger pBandwithLogger)
    • channel

      public io.netty.channel.Channel channel()
    • getDirection

      public PacketFlow getDirection()
    • getInboundProtocol

      public ProtocolInfo<?> getInboundProtocol()