From 86ef046544568afa8a5c2ac6218f08086bc993b8 Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Wed, 9 Apr 2014 16:42:08 +0100 Subject: [PATCH] Pass the protocol version through when using ping pass through --- proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java | 8 +++++++- .../java/net/md_5/bungee/connection/InitialHandler.java | 2 +- .../main/java/net/md_5/bungee/connection/PingHandler.java | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index be96fb50..3180d61a 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; import lombok.Synchronized; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -105,6 +106,11 @@ public class BungeeServerInfo implements ServerInfo @Override public void ping(final Callback callback) + { + ping( callback, ProxyServer.getInstance().getProtocolVersion() ); + } + + public void ping(final Callback callback, final int protocolVersion) { Preconditions.checkNotNull( callback, "callback" ); @@ -115,7 +121,7 @@ public class BungeeServerInfo implements ServerInfo { if ( future.isSuccess() ) { - future.channel().pipeline().get( HandlerBoss.class ).setHandler( new PingHandler( BungeeServerInfo.this, callback ) ); + future.channel().pipeline().get( HandlerBoss.class ).setHandler( new PingHandler( BungeeServerInfo.this, callback, protocolVersion ) ); } else { callback.done( null, future.cause() ); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index ec73271d..2386a4fa 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -167,7 +167,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection if ( forced != null && listener.isPingPassthrough() ) { - forced.ping( pingBack ); + ((BungeeServerInfo) forced).ping( pingBack, handshake.getProtocolVersion() ); } else { int protocol = ( Protocol.supportedVersions.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : -1; 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 50f7a414..2e291d03 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 @@ -22,18 +22,19 @@ public class PingHandler extends PacketHandler private final ServerInfo target; private final Callback callback; + private final int protocol; private ChannelWrapper channel; @Override public void connected(ChannelWrapper channel) throws Exception { this.channel = channel; - MinecraftEncoder encoder = new MinecraftEncoder( Protocol.HANDSHAKE, false, ProxyServer.getInstance().getProtocolVersion() ); + MinecraftEncoder encoder = new MinecraftEncoder( Protocol.HANDSHAKE, false, protocol ); channel.getHandle().pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.STATUS, false, ProxyServer.getInstance().getProtocolVersion() ) ); channel.getHandle().pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, encoder ); - channel.write( new Handshake( ProxyServer.getInstance().getProtocolVersion(), target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) ); + channel.write( new Handshake( protocol, target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) ); encoder.setProtocol( Protocol.STATUS ); channel.write( new StatusRequest() );