Implement dual protocol version support.
This commit is contained in:
@@ -469,13 +469,13 @@ public class BungeeCord extends ProxyServer
|
||||
@Override
|
||||
public int getProtocolVersion()
|
||||
{
|
||||
return Protocol.PROTOCOL_VERSION;
|
||||
return Protocol.supportedVersions.get( Protocol.supportedVersions.size() - 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGameVersion()
|
||||
{
|
||||
return Protocol.MINECRAFT_VERSION;
|
||||
return "1.7.4";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -216,8 +216,8 @@ public final class UserConnection implements ProxiedPlayer
|
||||
protected void initChannel(Channel ch) throws Exception
|
||||
{
|
||||
PipelineUtils.BASE.initChannel( ch );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false ) );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false ) );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) );
|
||||
ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false, getPendingConnection().getVersion() ) );
|
||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
|
||||
}
|
||||
};
|
||||
|
@@ -175,8 +175,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
forced.ping( pingBack );
|
||||
} else
|
||||
{
|
||||
int protocol = ( Protocol.supportedVersions.contains( handshake.getProtocolVersion() ) ) ? handshake.getProtocolVersion() : -1;
|
||||
pingBack.done( new ServerPing(
|
||||
new ServerPing.Protocol( bungee.getGameVersion(), bungee.getProtocolVersion() ),
|
||||
new ServerPing.Protocol( bungee.getGameVersion(), protocol ),
|
||||
new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount(), null ),
|
||||
motd, BungeeCord.getInstance().config.favicon ),
|
||||
null );
|
||||
@@ -198,6 +199,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
{
|
||||
Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" );
|
||||
this.handshake = handshake;
|
||||
ch.setVersion( handshake.getProtocolVersion() );
|
||||
|
||||
// SRV records can end with a . depending on DNS / client.
|
||||
if ( handshake.getHost().endsWith( "." ) )
|
||||
@@ -233,14 +235,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" );
|
||||
this.loginRequest = loginRequest;
|
||||
|
||||
if ( handshake.getProtocolVersion() > bungee.getProtocolVersion() )
|
||||
if ( !Protocol.supportedVersions.contains( handshake.getProtocolVersion() ) )
|
||||
{
|
||||
disconnect( bungee.getTranslation( "outdated_server" ) );
|
||||
return;
|
||||
} else if ( handshake.getProtocolVersion() < bungee.getProtocolVersion() )
|
||||
{
|
||||
disconnect( bungee.getTranslation( "outdated_client" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( getName().length() > 16 )
|
||||
|
@@ -3,6 +3,7 @@ package net.md_5.bungee.connection;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.Callback;
|
||||
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.netty.ChannelWrapper;
|
||||
@@ -27,12 +28,12 @@ public class PingHandler extends PacketHandler
|
||||
public void connected(ChannelWrapper channel) throws Exception
|
||||
{
|
||||
this.channel = channel;
|
||||
MinecraftEncoder encoder = new MinecraftEncoder( Protocol.HANDSHAKE, false );
|
||||
MinecraftEncoder encoder = new MinecraftEncoder( Protocol.HANDSHAKE, false, ProxyServer.getInstance().getProtocolVersion() );
|
||||
|
||||
channel.getHandle().pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.STATUS, false ) );
|
||||
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( Protocol.PROTOCOL_VERSION, target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) );
|
||||
channel.write( new Handshake( ProxyServer.getInstance().getProtocolVersion(), target.getAddress().getHostString(), target.getAddress().getPort(), 1 ) );
|
||||
|
||||
encoder.setProtocol( Protocol.STATUS );
|
||||
channel.write( new StatusRequest() );
|
||||
|
@@ -28,6 +28,12 @@ public class ChannelWrapper
|
||||
ch.pipeline().get( MinecraftEncoder.class ).setProtocol( protocol );
|
||||
}
|
||||
|
||||
public void setVersion(int protocol)
|
||||
{
|
||||
ch.pipeline().get( MinecraftDecoder.class ).setProtocolVersion( protocol );
|
||||
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
|
||||
}
|
||||
|
||||
public synchronized void write(Object packet)
|
||||
{
|
||||
if ( !closed )
|
||||
|
@@ -43,8 +43,8 @@ public class PipelineUtils
|
||||
|
||||
BASE.initChannel( ch );
|
||||
ch.pipeline().addBefore( FRAME_DECODER, LEGACY_DECODER, new LegacyDecoder() );
|
||||
ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true ) );
|
||||
ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true ) );
|
||||
ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true, ProxyServer.getInstance().getProtocolVersion() ) );
|
||||
ch.pipeline().addBefore( FRAME_PREPENDER, LEGACY_KICKER, new KickStringWriter() );
|
||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) );
|
||||
}
|
||||
|
Reference in New Issue
Block a user