Don't allow stupid users to connect bungee to themselves

This commit is contained in:
md_5 2013-06-01 17:55:51 +10:00
parent d5eb37c7a6
commit 4f2b98188e
3 changed files with 14 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package net.md_5.bungee;
import net.md_5.bungee.protocol.packet.Packet9Respawn; import net.md_5.bungee.protocol.packet.Packet9Respawn;
import net.md_5.bungee.protocol.packet.PacketCDClientStatus; import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
public class PacketConstants public class PacketConstants
{ {
@ -9,4 +10,9 @@ public class PacketConstants
public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" ); public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
public static final PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 ); public static final PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 );
public static final PacketFAPluginMessage FORGE_MOD_REQUEST = new PacketFAPluginMessage( "FML", new byte[]
{
0, 0, 0, 0, 0, 2
} );
public static final PacketFAPluginMessage I_AM_BUNGEE = new PacketFAPluginMessage( "BungeeCord", new byte[ 0 ] );
} }

View File

@ -266,6 +266,11 @@ public class ServerConnector extends PacketHandler
@Override @Override
public void handle(PacketFAPluginMessage pluginMessage) throws Exception public void handle(PacketFAPluginMessage pluginMessage) throws Exception
{ {
if ( pluginMessage.getData().length == 0 && pluginMessage.getTag().equals( "BungeeCord" ) )
{
throw new IllegalStateException( "May not connect to another BungeCord!" );
}
if ( ( pluginMessage.getData()[0] & 0xFF ) == 0 && pluginMessage.getTag().equals( "FML" ) ) if ( ( pluginMessage.getData()[0] & 0xFF ) == 0 && pluginMessage.getTag().equals( "FML" ) )
{ {
ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() ); ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() );

View File

@ -16,6 +16,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.EncryptionUtil; import net.md_5.bungee.EncryptionUtil;
import net.md_5.bungee.PacketConstants;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.Util; import net.md_5.bungee.Util;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
@ -71,10 +72,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
ch.write( packet ); ch.write( packet );
} }
}; };
private static final PacketFAPluginMessage forgeMods = new PacketFAPluginMessage( "FML", new byte[]
{
0, 0, 0, 0, 0, 2
} );
private enum State private enum State
{ {
@ -152,7 +149,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} }
this.handshake = handshake; this.handshake = handshake;
unsafe().sendPacket( forgeMods ); unsafe().sendPacket( PacketConstants.I_AM_BUNGEE );
unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST );
unsafe().sendPacket( request = EncryptionUtil.encryptRequest() ); unsafe().sendPacket( request = EncryptionUtil.encryptRequest() );
thisState = State.ENCRYPT; thisState = State.ENCRYPT;
} }