Refactor forge support - closes #318

This commit is contained in:
md_5 2013-05-05 08:31:44 +10:00
parent 904a1bfaa3
commit 332bdaaec0
4 changed files with 24 additions and 9 deletions

View File

@ -19,8 +19,6 @@ public class ServerConnection implements Server
@Getter
private final BungeeServerInfo info;
@Getter
private final boolean isForgeWrapper;
@Getter
@Setter
private boolean isObsolete;

View File

@ -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

View File

@ -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;
}

View File

@ -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;