Package net.minecraft.network
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
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SocketAddress
The address of the remote partyprivate static final float
private float
private float
(package private) BandwidthDebugMonitor
private io.netty.channel.Channel
The active channelprivate DisconnectionDetails
private DisconnectionDetails
private boolean
private PacketListener
private boolean
private boolean
private ProtocolInfo
<?> private static final ProtocolInfo
<ServerHandshakePacketListener> static final Supplier
<io.netty.channel.DefaultEventLoopGroup> private static final org.slf4j.Logger
static final Supplier
<io.netty.channel.epoll.EpollEventLoopGroup> static final Supplier
<io.netty.channel.nio.NioEventLoopGroup> static final org.slf4j.Marker
static final org.slf4j.Marker
static final org.slf4j.Marker
private PacketListener
The PacketListener instance responsible for processing received packetsprivate final Queue
<Consumer<Connection>> private int
private final PacketFlow
static final org.slf4j.Marker
private boolean
private int
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.netty.channel.Channel
channel()
void
channelActive
(io.netty.channel.ChannelHandlerContext context) void
channelInactive
(io.netty.channel.ChannelHandlerContext context) protected void
channelRead0
(io.netty.channel.ChannelHandlerContext context, Packet<?> packet) static void
configureInMemoryPipeline
(io.netty.channel.ChannelPipeline pipeline, PacketFlow flow) void
configurePacketHandler
(io.netty.channel.ChannelPipeline pipeline) static void
configureSerialization
(io.netty.channel.ChannelPipeline pipeline, PacketFlow flow, boolean memoryOnly, BandwidthDebugMonitor bandwithDebugMonitor) static io.netty.channel.ChannelFuture
connect
(InetSocketAddress address, boolean useEpollIfAvailable, Connection connection) static Connection
connectToLocalServer
(SocketAddress address) Prepares a clientside Connection for a local in-memory connection ("single player").static Connection
connectToServer
(InetSocketAddress address, boolean useEpollIfAvailable, LocalSampleLogger sampleLogger) private static io.netty.channel.ChannelInboundHandler
createFrameDecoder
(BandwidthDebugMonitor bandwithDebugMonitor, boolean memoryOnly) private static io.netty.channel.ChannelOutboundHandler
createFrameEncoder
(boolean memoryOnly) void
disconnect
(Component message) Closes the channel with a given reason.void
disconnect
(DisconnectionDetails disconnectionDetails) private void
doSendPacket
(Packet<?> p_packet, PacketSendListener sendListener, boolean flush) void
exceptionCaught
(io.netty.channel.ChannelHandlerContext context, Throwable exception) private void
flush()
void
private void
private static <T extends PacketListener>
voidgenericsFtw
(Packet<T> packet, PacketListener listener) float
float
ProtocolInfo
<?> getLoggableAddress
(boolean logIps) void
private static String
inboundHandlerName
(boolean serverbound) private <S extends ServerboundPacketListener,
C extends ClientboundPacketListener>
voidinitiateServerboundConnection
(String hostName, int port, ProtocolInfo<S> serverboundProtocol, ProtocolInfo<C> clientboundProtocol, C packetListener, ClientIntent intention) void
initiateServerboundPlayConnection
(String hostName, int port, ClientLoginPacketListener packetListener) <S extends ServerboundPacketListener,
C extends ClientboundPacketListener>
voidinitiateServerboundPlayConnection
(String hostName, int port, ProtocolInfo<S> serverboundProtocol, ProtocolInfo<C> clientbountProtocol, C packetListener, boolean isTransfer) void
initiateServerboundStatusConnection
(String hostName, int port, ClientStatusPacketListener packetListener) boolean
boolean
boolean
boolean
private static String
outboundHandlerName
(boolean clientbound) void
runOnceConnected
(Consumer<Connection> action) void
void
send
(Packet<?> packet, PacketSendListener sendListener) void
send
(Packet<?> packet, PacketSendListener listener, boolean flush) private void
sendPacket
(Packet<?> packet, PacketSendListener sendListener, boolean flush) void
setBandwidthLogger
(LocalSampleLogger bandwithLogger) void
setEncryptionKey
(Cipher decryptingCipher, Cipher encryptingCipher) Enables encryption for this connection using the given decrypting and encrypting ciphers.void
setListenerForServerboundHandshake
(PacketListener packetListener) void
void
setupCompression
(int threshold, boolean validateDecompressed) Enables or disables compression for this connection.<T extends PacketListener>
voidsetupInboundProtocol
(ProtocolInfo<T> protocolInfo, T packetInfo) void
setupOutboundProtocol
(ProtocolInfo<?> protocolInfo) private static void
syncAfterConfigurationChange
(io.netty.channel.ChannelFuture future) void
tick()
protected void
private void
validateListener
(ProtocolInfo<?> protocolInfo, PacketListener packetListener) Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelRead
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
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
-
NETWORK_EPOLL_WORKER_GROUP
-
LOCAL_WORKER_GROUP
-
INITIAL_PROTOCOL
-
receiving
-
sendLoginDisconnect
private volatile boolean sendLoginDisconnect -
pendingActions
-
channel
private io.netty.channel.Channel channelThe active channel -
address
The address of the remote party -
disconnectListener
-
packetListener
The PacketListener instance responsible for processing received packets -
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
-
bandwidthDebugMonitor
-
inboundProtocol
-
-
Constructor Details
-
Connection
-
-
Method Details
-
channelActive
- Specified by:
channelActive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelActive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext context) - Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
-
exceptionCaught
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
-
channelRead0
- Specified by:
channelRead0
in classio.netty.channel.SimpleChannelInboundHandler<Packet<?>>
-
genericsFtw
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) -
validateListener
-
syncAfterConfigurationChange
private static void syncAfterConfigurationChange(io.netty.channel.ChannelFuture future) -
setupInboundProtocol
public <T extends PacketListener> void setupInboundProtocol(ProtocolInfo<T> protocolInfo, T packetInfo) -
setupOutboundProtocol
-
setListenerForServerboundHandshake
-
initiateServerboundStatusConnection
public void initiateServerboundStatusConnection(String hostName, int port, ClientStatusPacketListener packetListener) -
initiateServerboundPlayConnection
public void initiateServerboundPlayConnection(String hostName, int port, ClientLoginPacketListener packetListener) -
initiateServerboundPlayConnection
public <S extends ServerboundPacketListener,C extends ClientboundPacketListener> void initiateServerboundPlayConnection(String hostName, int port, ProtocolInfo<S> serverboundProtocol, ProtocolInfo<C> clientbountProtocol, C packetListener, boolean isTransfer) -
initiateServerboundConnection
private <S extends ServerboundPacketListener,C extends ClientboundPacketListener> void initiateServerboundConnection(String hostName, int port, ProtocolInfo<S> serverboundProtocol, ProtocolInfo<C> clientboundProtocol, C packetListener, ClientIntent intention) -
send
-
send
-
send
-
runOnceConnected
-
sendPacket
-
doSendPacket
private void doSendPacket(Packet<?> p_packet, @Nullable PacketSendListener sendListener, boolean flush) -
flushChannel
public void flushChannel() -
flush
private void flush() -
flushQueue
private void flushQueue() -
tick
public void tick() -
tickSecond
protected void tickSecond() -
getRemoteAddress
-
getLoggableAddress
-
disconnect
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 viaClientboundDisconnectPacket
. Closing the channel this way does not send any disconnection packets, it simply terminates the underlying netty channel. -
disconnect
-
isMemoryConnection
public boolean isMemoryConnection() -
getReceiving
-
getSending
-
connectToServer
public static Connection connectToServer(InetSocketAddress address, boolean useEpollIfAvailable, @Nullable LocalSampleLogger sampleLogger) -
connect
public static io.netty.channel.ChannelFuture connect(InetSocketAddress address, boolean useEpollIfAvailable, Connection connection) -
outboundHandlerName
-
inboundHandlerName
-
configurePacketHandler
public void configurePacketHandler(io.netty.channel.ChannelPipeline pipeline) -
configureSerialization
public static void configureSerialization(io.netty.channel.ChannelPipeline pipeline, PacketFlow flow, boolean memoryOnly, @Nullable BandwidthDebugMonitor bandwithDebugMonitor) -
createFrameEncoder
private static io.netty.channel.ChannelOutboundHandler createFrameEncoder(boolean memoryOnly) -
createFrameDecoder
private static io.netty.channel.ChannelInboundHandler createFrameDecoder(@Nullable BandwidthDebugMonitor bandwithDebugMonitor, boolean memoryOnly) -
configureInMemoryPipeline
public static void configureInMemoryPipeline(io.netty.channel.ChannelPipeline pipeline, PacketFlow flow) -
connectToLocalServer
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
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
-
getDisconnectionDetails
-
setReadOnly
public void setReadOnly() -
setupCompression
public void setupCompression(int threshold, boolean validateDecompressed) Enables or disables compression for this connection. Ifthreshold
is >= 0 then aCompressionDecoder
andCompressionEncoder
are installed in the pipeline or updated if they already exist. Ifthreshold
is invalid input: '<' 0 then any such codec are removed. Compression is enabled as part of the connection handshake when the server sendsClientboundLoginCompressionPacket
. -
handleDisconnection
public void handleDisconnection() -
getAverageReceivedPackets
public float getAverageReceivedPackets() -
getAverageSentPackets
public float getAverageSentPackets() -
setBandwidthLogger
-
channel
public io.netty.channel.Channel channel() -
getDirection
-
getInboundProtocol
-