Implement 1.7 style pings
This commit is contained in:
parent
5dfd14fbe5
commit
b9158b7322
@ -1,14 +1,16 @@
|
|||||||
package net.md_5.bungee.connection;
|
package net.md_5.bungee.connection;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.md_5.bungee.BungeeCord;
|
||||||
import net.md_5.bungee.api.Callback;
|
import net.md_5.bungee.api.Callback;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import net.md_5.bungee.api.ServerPing;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
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
|
@RequiredArgsConstructor
|
||||||
public class PingHandler extends PacketHandler
|
public class PingHandler extends PacketHandler
|
||||||
@ -16,15 +18,15 @@ public class PingHandler extends PacketHandler
|
|||||||
|
|
||||||
private final ServerInfo target;
|
private final ServerInfo target;
|
||||||
private final Callback<ServerPing> callback;
|
private final Callback<ServerPing> callback;
|
||||||
|
private ChannelWrapper channel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected(ChannelWrapper channel) throws Exception
|
public void connected(ChannelWrapper channel) throws Exception
|
||||||
{
|
{
|
||||||
// TODO: Update this to 1.7 style!
|
this.channel = channel;
|
||||||
channel.write( Unpooled.wrappedBuffer( new byte[]
|
|
||||||
{
|
channel.write( new Handshake( Protocol.PROTOCOL_VERSION, target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) );
|
||||||
(byte) 0xFE, (byte) 0x01
|
channel.write( new StatusRequest() );
|
||||||
} ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -34,11 +36,10 @@ public class PingHandler extends PacketHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Kick kick) throws Exception
|
public void handle(StatusResponse statusResponse) throws Exception
|
||||||
{
|
{
|
||||||
String[] split = kick.getMessage().split( "\00" );
|
callback.done( BungeeCord.getInstance().gson.fromJson( statusResponse.getResponse(), ServerPing.class ), null );
|
||||||
// ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
|
channel.close();
|
||||||
// callback.done( ping, null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user