Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ and then catch exceptions and close if they fire.
Part of this commit was authored by: Spottedleaf, sandtechnology

diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e7e150804 100644
index 80f641eee1ebbfffeba7ab1bcc86a705b000f40b..41cfa987e45cb83abcaf6aa2e9b1c2d0796d9c25 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -64,7 +64,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
Expand Down Expand Up @@ -102,7 +102,7 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e
}
}

@@ -419,21 +450,42 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -435,21 +466,42 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}

private void doSendPacket(final Packet<?> packet, final @Nullable ChannelFutureListener listener, final boolean flush) {
Expand All @@ -125,7 +125,7 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e
} else {
- this.channel.write(packet, this.channel.voidPromise());
+ future = this.channel.write(packet, this.channel.voidPromise()); // Paper - Optimize network
+ }
}
+
+ // Paper start - Optimize network
+ if (packet.hasFinishListener()) {
Expand All @@ -136,7 +136,7 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e
+ Component reason = Component.translatable("disconnect.genericReason", "Internal Exception: " + e.getMessage());
+ this.send(new ClientboundDisconnectPacket(reason), PacketSendListener.thenRun(() -> this.disconnect(reason)));
+ packet.onPacketDispatchFinish(player, null);
}
+ }
+ // Paper end - Optimize network
}

Expand All @@ -149,7 +149,7 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e
}
}

@@ -445,16 +497,57 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -461,16 +513,57 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
}
}

Expand Down Expand Up @@ -212,15 +212,15 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e

private static final int MAX_PER_TICK = io.papermc.paper.configuration.GlobalConfiguration.get().misc.maxJoinsPerTick; // Paper - Buffer joins to world
private static int joinAttemptsThisTick; // Paper - Buffer joins to world
@@ -524,6 +617,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -540,6 +633,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {

public void disconnect(final DisconnectionDetails details) {
this.preparing = false; // Spigot
+ this.clearPacketQueue(); // Paper - Optimize network
if (this.channel == null) {
this.delayedDisconnect = details;
}
@@ -705,7 +799,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -721,7 +815,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
public void handleDisconnection() {
if (this.channel != null && !this.channel.isOpen()) {
if (this.disconnectionHandled) {
Expand All @@ -229,7 +229,7 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e
} else {
this.disconnectionHandled = true;
PacketListener packetListener = this.getPacketListener();
@@ -716,7 +810,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -732,7 +826,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
);
disconnectListener.onDisconnect(details);
}
Expand All @@ -238,7 +238,7 @@ index 13faa13a9d3120cdeaca63d6eb3a0feb8019fb3a..d14aea970ce98edfe3dc3692e707334e
// Paper start - Add PlayerConnectionCloseEvent
if (packetListener instanceof net.minecraft.server.network.ServerCommonPacketListenerImpl commonPacketListener) {
/* Player was logged in, either game listener or configuration listener */
@@ -751,4 +845,96 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -767,4 +861,96 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
public void setBandwidthLogger(final LocalSampleLogger bandwidthLogger) {
this.bandwidthDebugMonitor = new BandwidthDebugMonitor(bandwidthLogger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ index 595db570b0ade9cad7de77d2ab7b10d9e68699df..ac095f59d9f17d8239d6493d1c1e3942
+ // Paper end - Use Velocity cipher
}
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index d14aea970ce98edfe3dc3692e707334e7e150804..0f06d509125e72ec11d263d0d5c2179d65f6d8dd 100644
index 41cfa987e45cb83abcaf6aa2e9b1c2d0796d9c25..1abd8acf2738b882a4e1829c0b801be1c6ce011c 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -730,11 +730,22 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -746,11 +746,22 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
return connection;
}

Expand All @@ -297,7 +297,7 @@ index d14aea970ce98edfe3dc3692e707334e7e150804..0f06d509125e72ec11d263d0d5c2179d

public boolean isEncrypted() {
return this.encrypted;
@@ -772,16 +783,17 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
@@ -788,16 +799,17 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {

public void setupCompression(final int threshold, final boolean validateDecompressed) {
if (threshold >= 0) {
Expand Down Expand Up @@ -334,7 +334,7 @@ index 6d506004583b2415ab356e34e2f8d6ac0e39cca2..474b7f06223514d95bad3d91356dfaa5
.add(
new ServerBootstrap()
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 50e4f4037702875fe7755b169947abd800b06e7b..722c832ce18fd930d9fdb4f718dc13bfc962e5dd 100644
index 8fcaa9675b6bbd4c68fd8980dfad195d188145be..a28d755ec314f889af65e186d2bcd19a5b7056d3 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -251,11 +251,9 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@
} catch (RejectedExecutionException ignored) {
this.disconnect(Component.translatable("multiplayer.disconnect.server_shutdown"));
} catch (ClassCastException exception) {
@@ -296,6 +_,22 @@
}
}

+ // Paper start - Add netty task scheduling helper
+ public void scheduleNettyTask(final Runnable task) {
+ final boolean connected = this.isConnected();
+ if (!connected && !this.preparing) {
+ return;
+ }
+
+ if (connected && this.pendingActions.isEmpty()) {
+ this.channel.eventLoop().execute(task);
+ } else {
+ this.pendingActions.add(new WrappedConsumer(connection -> connection.channel.eventLoop().execute(task)));
+ this.flushQueue();
+ }
+ }
+ // Paper end - Add netty task scheduling helper
+
private void sendPacket(final Packet<?> packet, final @Nullable ChannelFutureListener listener, final boolean flush) {
this.sentPackets++;
if (this.channel.eventLoop().inEventLoop()) {
@@ -343,10 +_,30 @@
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
}
}
}
@@ -139,9 +_,9 @@
@@ -139,19 +_,19 @@

private void verifyLoginAndFinishConnectionSetup(final GameProfile profile) {
PlayerList playerList = this.server.getPlayerList();
Expand All @@ -154,9 +154,16 @@
+ this.disconnectAsync(error); // Paper
} else {
if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
this.connection
@@ -151,7 +_,7 @@
);
- this.connection
- .send(
- new ClientboundLoginCompressionPacket(this.server.getCompressionThreshold()),
- PacketSendListener.thenRun(() -> this.connection.setupCompression(this.server.getCompressionThreshold(), true))
- );
+ // Paper start - Schedule compression setup after compression packet
+ final int compressionThreshold = this.server.getCompressionThreshold();
+ this.connection.send(new ClientboundLoginCompressionPacket(compressionThreshold));
+ this.connection.scheduleNettyTask(() -> this.connection.setupCompression(compressionThreshold, true));
+ // Paper end - Schedule compression setup after compression packet
}

- boolean waitForDisconnection = playerList.disconnectAllPlayersWithProfile(profile.id());
Expand Down