From 8732904bfd122cdbd479af55bd759e38a3680254 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 1 Jul 2013 13:45:36 +1000 Subject: [PATCH] Add stream helper to PacketFA --- .../packet/PacketFAPluginMessage.java | 10 ++++++++++ .../java/net/md_5/bungee/ServerConnector.java | 7 ++++--- .../bungee/connection/DownstreamBridge.java | 3 ++- .../bungee/connection/UpstreamBridge.java | 2 +- .../reconnect/AbstractReconnectManager.java | 20 +++++++++++++------ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java index 65053c54..74298432 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PacketFAPluginMessage.java @@ -1,6 +1,11 @@ package net.md_5.bungee.protocol.packet; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.Unpooled; +import java.io.ByteArrayInputStream; +import java.io.DataInput; +import java.io.DataInputStream; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -45,4 +50,9 @@ public class PacketFAPluginMessage extends DefinedPacket { handler.handle( this ); } + + public DataInput getStream() + { + return new DataInputStream( new ByteArrayInputStream( data ) ); + } } 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 e08b1987..aba90c6f 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -4,6 +4,8 @@ import com.google.common.base.Preconditions; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; +import io.netty.buffer.ByteBuf; +import java.io.DataInput; import java.security.PublicKey; import java.util.Objects; import java.util.Queue; @@ -276,10 +278,9 @@ public class ServerConnector extends PacketHandler throw new IllegalStateException( "May not connect to another BungeCord!" ); } - if ( pluginMessage.getTag().equals( "FML" ) && ( pluginMessage.getData()[0] & 0xFF ) == 0 ) + DataInput in = pluginMessage.getStream(); + if ( pluginMessage.getTag().equals( "FML" ) && in.readUnsignedByte() == 0 ) { - ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() ); - in.readUnsignedByte(); int count = in.readInt(); for ( int i = 0; i < count; i++ ) { diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index c305c794..b514b278 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -3,6 +3,7 @@ package net.md_5.bungee.connection; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; +import java.io.DataInput; import java.util.Objects; import lombok.RequiredArgsConstructor; import net.md_5.bungee.EntityMap; @@ -185,7 +186,7 @@ public class DownstreamBridge extends PacketHandler @Override public void handle(PacketFAPluginMessage pluginMessage) throws Exception { - ByteArrayDataInput in = ByteStreams.newDataInput( pluginMessage.getData() ); + DataInput in = pluginMessage.getStream(); PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) 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 941485fc..06cb073a 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 @@ -111,7 +111,7 @@ public class UpstreamBridge extends PacketHandler throw new CancelSendSignal(); } // Hack around Forge race conditions - if ( pluginMessage.getTag().equals( "FML" ) && ( pluginMessage.getData()[0] & 0xFF ) == 1 ) + if ( pluginMessage.getTag().equals( "FML" ) && pluginMessage.getStream().readUnsignedByte() == 1 ) { throw new CancelSendSignal(); } diff --git a/proxy/src/main/java/net/md_5/bungee/reconnect/AbstractReconnectManager.java b/proxy/src/main/java/net/md_5/bungee/reconnect/AbstractReconnectManager.java index 448073c8..eefbefcc 100644 --- a/proxy/src/main/java/net/md_5/bungee/reconnect/AbstractReconnectManager.java +++ b/proxy/src/main/java/net/md_5/bungee/reconnect/AbstractReconnectManager.java @@ -5,6 +5,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ReconnectHandler; import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; public abstract class AbstractReconnectManager implements ReconnectHandler @@ -15,13 +16,9 @@ public abstract class AbstractReconnectManager implements ReconnectHandler { ListenerInfo listener = player.getPendingConnection().getListener(); String name; - String forced = listener.getForcedHosts().get( player.getPendingConnection().getVirtualHost().getHostString() ); - if ( forced == null && listener.isForceDefault() ) - { - forced = listener.getDefaultServer(); - } + ServerInfo forced = getHost( player.getPendingConnection() ); - String server = ( forced == null ) ? getStoredServer( player ) : forced; + String server = ( forced == null ) ? getStoredServer( player ) : forced.getName(); name = ( server != null ) ? server : listener.getDefaultServer(); ServerInfo info = ProxyServer.getInstance().getServerInfo( name ); if ( info == null ) @@ -32,5 +29,16 @@ public abstract class AbstractReconnectManager implements ReconnectHandler return info; } + public static ServerInfo getHost(PendingConnection con) + { + String forced = con.getListener().getForcedHosts().get( con.getVirtualHost().getHostString() ); + + if ( forced == null && con.getListener().isForceDefault() ) + { + forced = con.getListener().getDefaultServer(); + } + return ( forced != null ) ? ProxyServer.getInstance().getServerInfo( forced ) : null; + } + protected abstract String getStoredServer(ProxiedPlayer player); }