From 4f2b98188e82001151209962c34faa46abd84d58 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 1 Jun 2013 17:55:51 +1000 Subject: [PATCH] Don't allow stupid users to connect bungee to themselves --- proxy/src/main/java/net/md_5/bungee/PacketConstants.java | 6 ++++++ proxy/src/main/java/net/md_5/bungee/ServerConnector.java | 5 +++++ .../java/net/md_5/bungee/connection/InitialHandler.java | 8 +++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java index 315dd189..e63212da 100644 --- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java +++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java @@ -2,6 +2,7 @@ package net.md_5.bungee; import net.md_5.bungee.protocol.packet.Packet9Respawn; import net.md_5.bungee.protocol.packet.PacketCDClientStatus; +import net.md_5.bungee.protocol.packet.PacketFAPluginMessage; 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 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 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 ] ); } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index ba3c2bc8..8439ceb4 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -266,6 +266,11 @@ public class ServerConnector extends PacketHandler @Override 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" ) ) { ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() ); 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 98a6bd41..f9cf9ff1 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 @@ -16,6 +16,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.EncryptionUtil; +import net.md_5.bungee.PacketConstants; import net.md_5.bungee.UserConnection; import net.md_5.bungee.Util; import net.md_5.bungee.api.Callback; @@ -71,10 +72,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection ch.write( packet ); } }; - private static final PacketFAPluginMessage forgeMods = new PacketFAPluginMessage( "FML", new byte[] - { - 0, 0, 0, 0, 0, 2 - } ); private enum State { @@ -152,7 +149,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection } this.handshake = handshake; - unsafe().sendPacket( forgeMods ); + unsafe().sendPacket( PacketConstants.I_AM_BUNGEE ); + unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST ); unsafe().sendPacket( request = EncryptionUtil.encryptRequest() ); thisState = State.ENCRYPT; }