Implement 1.7 style pings

This commit is contained in:
md_5 2013-10-27 12:59:35 +11:00
parent 5dfd14fbe5
commit b9158b7322

View File

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