From 9b4631ba9fc7485f862a4c4a0233d142c4e2cc89 Mon Sep 17 00:00:00 2001 From: xjboss Date: Wed, 28 Jun 2017 21:13:29 +0800 Subject: [PATCH] Apply spigot ping patch --- .../network/NetHandlerStatusServer.java.patch | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/patches/net/minecraft/server/network/NetHandlerStatusServer.java.patch b/patches/net/minecraft/server/network/NetHandlerStatusServer.java.patch index 885e48b..b4532a5 100644 --- a/patches/net/minecraft/server/network/NetHandlerStatusServer.java.patch +++ b/patches/net/minecraft/server/network/NetHandlerStatusServer.java.patch @@ -3,11 +3,11 @@ @@ -1,5 +1,6 @@ package net.minecraft.server.network; -+ ++import io.netty.channel.ChannelFutureListener; import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.network.EnumConnectionState; import net.minecraft.network.NetworkManager; -@@ -11,6 +12,13 @@ +@@ -11,8 +12,21 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.IChatComponent; @@ -20,17 +20,33 @@ + public class NetHandlerStatusServer implements INetHandlerStatusServer { ++ //CraftBukkit start ++ private static final int WAITING = 0; ++ private static final int PING = 1; ++ private static final int DONE = 2; ++ private int state = WAITING; ++ //Craftbukkit end private final MinecraftServer field_147314_a; -@@ -37,7 +45,36 @@ + private final NetworkManager field_147313_b; + private static final String __OBFID = "CL_00001464"; +@@ -37,7 +51,46 @@ public void processServerQuery(C00PacketServerQuery p_147312_1_) { - this.field_147313_b.scheduleOutboundPacket(new S00PacketServerInfo(this.field_147314_a.func_147134_at()), new GenericFutureListener[0]); ++ this.field_147313_b.scheduleOutboundPacket(new S00PacketServerInfo(this.field_147314_a.func_147134_at())); ++ ++ if (state != WAITING) { ++ this.field_147313_b.closeChannel(null); ++ return; ++ } ++ state = PING; + // CraftBukkit start - fire ping event + class ServerListPingEvent extends org.bukkit.event.server.ServerListPingEvent + { + CraftIconCache icon = field_147314_a.server.getServerIcon(); + ++ + ServerListPingEvent() + { + super(((InetSocketAddress) field_147313_b.getSocketAddress()).getAddress(), field_147314_a.getMOTD(), field_147314_a.getConfigurationManager().getCurrentPlayerCount(), field_147314_a.getConfigurationManager().getMaxPlayers()); @@ -47,6 +63,7 @@ + this.icon = (CraftIconCache) icon; + } + } ++ + ServerListPingEvent event = new ServerListPingEvent(); + this.field_147314_a.server.getPluginManager().callEvent(event); + ServerStatusResponse ping = new ServerStatusResponse(); @@ -55,6 +72,7 @@ + ping.func_151319_a(new ServerStatusResponse.PlayerCountData(event.getMaxPlayers(), field_147314_a.getConfigurationManager().getCurrentPlayerCount())); + ping.func_151321_a(new ServerStatusResponse.MinecraftProtocolVersionIdentifier(field_147314_a.getServerModName() + " " + field_147314_a.getMinecraftVersion(), 5)); // TODO: Update when protocol changes + this.field_147313_b.scheduleOutboundPacket(new S00PacketServerInfo(ping), new GenericFutureListener[0]); ++ + // CraftBukkit end }