From 332bdaaec03c197722c16f2288185f5efae7be8a Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 5 May 2013 08:31:44 +1000 Subject: [PATCH] Refactor forge support - closes #318 --- .../net/md_5/bungee/ServerConnection.java | 2 -- .../java/net/md_5/bungee/ServerConnector.java | 25 +++++++++++++------ .../bungee/connection/InitialHandler.java | 5 ++++ .../bungee/connection/UpstreamBridge.java | 1 + 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 6caa2fea..5a03e56b 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -19,8 +19,6 @@ public class ServerConnection implements Server @Getter private final BungeeServerInfo info; @Getter - private final boolean isForgeWrapper; - @Getter @Setter private boolean isObsolete; 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 77d13875..6e339312 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -48,6 +48,7 @@ public class ServerConnector extends PacketHandler private final BungeeServerInfo target; private State thisState = State.ENCRYPT_REQUEST; private SecretKey secretkey; + private boolean sentMessages; private enum State { @@ -59,7 +60,7 @@ public class ServerConnector extends PacketHandler public void exception(Throwable t) throws Exception { String message = "Exception Connectiong:" + Util.exception( t ); - if ( user.getServer() == null || user.getServer().isForgeWrapper() ) + if ( user.getServer() == null ) { user.disconnect( message ); } else @@ -99,7 +100,7 @@ public class ServerConnector extends PacketHandler { Preconditions.checkState( thisState == State.LOGIN, "Not exepcting LOGIN" ); - ServerConnection server = new ServerConnection( ch, target, false ); + ServerConnection server = new ServerConnection( ch, target ); ServerConnectedEvent event = new ServerConnectedEvent( user, server ); bungee.getPluginManager().callEvent( event ); @@ -113,9 +114,12 @@ public class ServerConnector extends PacketHandler } } - for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() ) + if ( !sentMessages ) { - ch.write( message ); + for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() ) + { + ch.write( message ); + } } if ( user.getSettings() != null ) @@ -125,8 +129,7 @@ public class ServerConnector extends PacketHandler synchronized ( user.getSwitchMutex() ) { - // TODO: This whole wrapper business is a hack - if ( user.getServer() == null || user.getServer().isForgeWrapper() ) + if ( user.getServer() == null ) { // Once again, first connection user.setClientEntityId( login.entityId ); @@ -226,7 +229,6 @@ public class ServerConnector extends PacketHandler ch.getHandle().pipeline().addBefore( "decoder", "decrypt", new CipherDecoder( decrypt ) ); ch.write( user.getPendingConnection().getForgeLogin() ); - user.setServer( new ServerConnection( ch, target, true ) ); ch.write( PacketCDClientStatus.CLIENT_LOGIN ); thisState = State.LOGIN; @@ -270,11 +272,20 @@ public class ServerConnector extends PacketHandler } if ( in.readByte() != 0 ) { + // TODO: Using forge flag ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( PacketDefinitions.FORGE_PROTOCOL ); } } user.sendPacket( pluginMessage ); // We have to forward these to the user, especially with Forge as stuff might break + if ( !sentMessages && user.getPendingConnection().getForgeLogin() != null ) + { + for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() ) + { + ch.write( message ); + } + sentMessages = true; + } } @Override 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 0dc15eda..273f4d77 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 @@ -63,6 +63,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection private State thisState = State.HANDSHAKE; private SecretKey sharedKey; private boolean disconnected; + private static final PacketFAPluginMessage forgeMods = new PacketFAPluginMessage( "FML", new byte[] + { + 0, 0, 0, 0, 0, 2 + } ); private enum State { @@ -133,6 +137,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection } this.handshake = handshake; + ch.write( forgeMods ); ch.write( request = EncryptionUtil.encryptRequest() ); thisState = State.ENCRYPT; } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index b2b205b4..90d60e31 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -1,5 +1,6 @@ package net.md_5.bungee.connection; +import java.util.Arrays; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.EntityMap; import net.md_5.bungee.UserConnection;