diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java index 8629f055..fbc8c7d3 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java @@ -1,14 +1,16 @@ package net.md_5.bungee.connection; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import lombok.RequiredArgsConstructor; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.netty.PacketHandler; -import net.md_5.bungee.protocol.packet.Kick; +import net.md_5.bungee.protocol.Protocol; +import net.md_5.bungee.protocol.packet.Handshake; +import net.md_5.bungee.protocol.packet.StatusRequest; +import net.md_5.bungee.protocol.packet.StatusResponse; @RequiredArgsConstructor public class PingHandler extends PacketHandler @@ -16,15 +18,15 @@ public class PingHandler extends PacketHandler private final ServerInfo target; private final Callback callback; + private ChannelWrapper channel; @Override public void connected(ChannelWrapper channel) throws Exception { - // TODO: Update this to 1.7 style! - channel.write( Unpooled.wrappedBuffer( new byte[] - { - (byte) 0xFE, (byte) 0x01 - } ) ); + this.channel = channel; + + channel.write( new Handshake( Protocol.PROTOCOL_VERSION, target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) ); + channel.write( new StatusRequest() ); } @Override @@ -34,11 +36,10 @@ public class PingHandler extends PacketHandler } @Override - public void handle(Kick kick) throws Exception + public void handle(StatusResponse statusResponse) throws Exception { - String[] split = kick.getMessage().split( "\00" ); - // ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) ); - // callback.done( ping, null ); + callback.done( BungeeCord.getInstance().gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null ); + channel.close(); } @Override