1
0
forked from xjboss/KCauldronX

Apply spigot ping patch

This commit is contained in:
xjboss 2017-06-28 21:13:29 +08:00
parent 6a05406ed1
commit 9b4631ba9f

View File

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