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
}
-