3
0
KCauldronX/patches/net/minecraft/server/network/NetHandlerStatusServer.java.patch

80 lines
3.5 KiB
Diff
Raw Normal View History

2015-03-22 17:38:04 +00:00
--- ../src-base/minecraft/net/minecraft/server/network/NetHandlerStatusServer.java
+++ ../src-work/minecraft/net/minecraft/server/network/NetHandlerStatusServer.java
@@ -1,5 +1,6 @@
package net.minecraft.server.network;
2017-06-28 13:13:29 +00:00
+import io.netty.channel.ChannelFutureListener;
2015-03-22 17:38:04 +00:00
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.NetworkManager;
2017-06-28 13:13:29 +00:00
@@ -11,8 +12,21 @@
2015-03-22 17:38:04 +00:00
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IChatComponent;
+// CraftBukkit start
+import java.net.InetSocketAddress;
+import net.minecraft.network.ServerStatusResponse;
+import net.minecraft.util.ChatComponentText;
+import org.bukkit.craftbukkit.util.CraftIconCache;
+// CraftBukkit end
+
public class NetHandlerStatusServer implements INetHandlerStatusServer
{
2017-06-28 13:13:29 +00:00
+ //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
2015-03-22 17:38:04 +00:00
private final MinecraftServer field_147314_a;
2017-06-28 13:13:29 +00:00
private final NetworkManager field_147313_b;
private static final String __OBFID = "CL_00001464";
@@ -37,7 +51,46 @@
2015-03-22 17:38:04 +00:00
public void processServerQuery(C00PacketServerQuery p_147312_1_)
{
- this.field_147313_b.scheduleOutboundPacket(new S00PacketServerInfo(this.field_147314_a.func_147134_at()), new GenericFutureListener[0]);
2017-06-28 13:13:29 +00:00
+ 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;
2015-03-22 17:38:04 +00:00
+ // CraftBukkit start - fire ping event
+ class ServerListPingEvent extends org.bukkit.event.server.ServerListPingEvent
+ {
+ CraftIconCache icon = field_147314_a.server.getServerIcon();
+
2017-06-28 13:13:29 +00:00
+
2015-03-22 17:38:04 +00:00
+ ServerListPingEvent()
+ {
+ super(((InetSocketAddress) field_147313_b.getSocketAddress()).getAddress(), field_147314_a.getMOTD(), field_147314_a.getConfigurationManager().getCurrentPlayerCount(), field_147314_a.getConfigurationManager().getMaxPlayers());
+ }
+
+ @Override
+ public void setServerIcon(org.bukkit.util.CachedServerIcon icon)
+ {
+ if (!(icon instanceof CraftIconCache))
+ {
+ throw new IllegalArgumentException(icon + " was not created by " + org.bukkit.craftbukkit.CraftServer.class);
+ }
+
+ this.icon = (CraftIconCache) icon;
+ }
+ }
2017-06-28 13:13:29 +00:00
+
2015-03-22 17:38:04 +00:00
+ ServerListPingEvent event = new ServerListPingEvent();
+ this.field_147314_a.server.getPluginManager().callEvent(event);
+ ServerStatusResponse ping = new ServerStatusResponse();
+ ping.func_151320_a(event.icon.value);
+ ping.func_151315_a(new ChatComponentText(event.getMotd()));
+ 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]);
2017-06-28 13:13:29 +00:00
+
2015-03-22 17:38:04 +00:00
+ // CraftBukkit end
}
public void processPing(C01PacketPing p_147311_1_)