Small diff cleanup

This commit is contained in:
Nassim Jahnke
2024-12-19 15:55:01 +01:00
parent 4353c33213
commit a438cc45f6
4 changed files with 57 additions and 114 deletions

View File

@@ -48,30 +48,25 @@
sendFlushAndClose(context, createLegacyDisconnectPacket(context.alloc(), string));
} else {
if (byteBuf.readUnsignedByte() != 1) {
@@ -43,16 +_,35 @@
@@ -43,16 +_,39 @@
}
if (byteBuf.isReadable()) {
- if (!readCustomPayloadPacket(byteBuf)) {
+ // Paper start - Replace with improved version below
+ // Paper start - Replace below
+ if (byteBuf.readUnsignedByte() != LegacyProtocolUtils.CUSTOM_PAYLOAD_PACKET_ID) {
+ string = this.readLegacy1_6(context, byteBuf);
+ if (string == null) {
+ return;
+ }
+ }
+ // if (!readCustomPayloadPacket(byteBuf)) {
+ // return;
+ // }
+
+ // LOGGER.debug("Ping: (1.6) from {}", socketAddress);
+ // Paper end - Replace with improved version below
+ // Paper end - Replace below
+ } else {
+ LOGGER.debug("Ping: (1.4-1.5.x) from {}", net.minecraft.server.MinecraftServer.getServer().logIPs() ? socketAddress : "<ip address withheld>"); // Paper - Respect logIPs option
+ }
+
+ // Paper start - Call PaperServerListPingEvent and use results
+ if (string == null) {
+ // Paper start - Call PaperServerListPingEvent and use results
+ com.destroystokyo.paper.event.server.PaperServerListPingEvent event = com.destroystokyo.paper.network.PaperLegacyStatusClient.processRequest(net.minecraft.server.MinecraftServer.getServer(), (java.net.InetSocketAddress) socketAddress, 127, null); // Paper
+ if (event == null) {
+ context.close();
@@ -79,11 +74,19 @@
+ flag = false;
return;
}
-
- LOGGER.debug("Ping: (1.6) from {}", socketAddress);
- } else {
- LOGGER.debug("Ping: (1.4-1.5.x) from {}", socketAddress);
+ string = String.format(Locale.ROOT, "§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", event.getProtocolVersion(), this.server.getServerVersion(), event.getMotd(), event.getNumPlayers(), event.getMaxPlayers()); // CraftBukkit
+ // See createVersion1Response
+ string = String.format(
+ Locale.ROOT,
+ "§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d",
+ event.getProtocolVersion(), this.server.getServerVersion(),
+ event.getMotd(),
+ event.getNumPlayers(),
+ event.getMaxPlayers()
+ );
+ // Paper end - Call PaperServerListPingEvent and use results
}
-

View File

@@ -95,7 +95,7 @@
}
}
@@ -88,37 +_,124 @@
@@ -88,30 +_,117 @@
public void handlePong(ServerboundPongPacket packet) {
}
@@ -206,31 +206,20 @@
protected void keepConnectionAlive() {
Profiler.get().push("keepAlive");
- long millis = Util.getMillis();
long millis = Util.getMillis();
- if (!this.isSingleplayerOwner() && millis - this.keepAliveTime >= 15000L) {
- if (this.keepAlivePending) {
- this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE);
- } else if (this.checkIfClosed(millis)) {
+ // Paper start - give clients a longer time to respond to pings as per pre 1.12.2 timings
+ // This should effectively place the keepalive handling back to "as it was" before 1.12.2
+ long currentTime = Util.getMillis();
+ long elapsedTime = currentTime - this.keepAliveTime;
+ if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // Paper - use vanilla's 15000L between keep alive packets
+ if (this.keepAlivePending && !this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // Paper - check keepalive limit, don't fire if already disconnected
+ final long elapsedTime = millis - this.keepAliveTime;
+ if (!this.isSingleplayerOwner() && elapsedTime >= 15000L) { // use vanilla's 15000L between keep alive packets
+ if (this.keepAlivePending && !this.processedDisconnect && elapsedTime >= KEEPALIVE_LIMIT) { // check keepalive limit, don't fire if already disconnected
+ // Paper end - give clients a longer time to respond to pings as per pre 1.12.2 timings
+ this.disconnect(TIMEOUT_DISCONNECTION_MESSAGE, org.bukkit.event.player.PlayerKickEvent.Cause.TIMEOUT); // Paper - kick event cause
+ } else if (this.checkIfClosed(currentTime)) { // Paper
} else if (this.checkIfClosed(millis)) {
this.keepAlivePending = true;
- this.keepAliveTime = millis;
- this.keepAliveChallenge = millis;
+ this.keepAliveTime = currentTime;
+ this.keepAliveChallenge = currentTime;
this.send(new ClientboundKeepAlivePacket(this.keepAliveChallenge));
}
}
+ // Paper end - give clients a longer time to respond to pings as per pre 1.12.2 timings
Profiler.get().pop();
}
this.keepAliveTime = millis;
@@ -126,7 +_,7 @@
private boolean checkIfClosed(long time) {
if (this.closed) {

View File

@@ -68,7 +68,6 @@
? new RateKickingConnection(rateLimitPacketsPerSecond)
: new Connection(PacketFlow.SERVERBOUND));
- ServerConnectionListener.this.connections.add(connection);
+ // ServerConnectionListener.this.connections.add(connection); // Paper
+ // Paper start - Add support for Proxy Protocol
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.proxyProtocol) {
+ channel.pipeline().addAfter("timeout", "haproxy-decoder", new io.netty.handler.codec.haproxy.HAProxyMessageDecoder());
@@ -98,6 +97,7 @@
+ });
+ }
+ // Paper end - Add support for proxy protocol
+ // ServerConnectionListener.this.connections.add(connection); // Paper - prevent blocking on adding a new connection while the server is ticking
+ ServerConnectionListener.this.pending.add(connection); // Paper - prevent blocking on adding a new connection while the server is ticking
connection.configurePacketHandler(channelPipeline);
connection.setListenerForServerboundHandshake(