Add stream helper to PacketFA
This commit is contained in:
parent
788b96dc0a
commit
8732904bfd
@ -1,6 +1,11 @@
|
|||||||
package net.md_5.bungee.protocol.packet;
|
package net.md_5.bungee.protocol.packet;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
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.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@ -45,4 +50,9 @@ public class PacketFAPluginMessage extends DefinedPacket
|
|||||||
{
|
{
|
||||||
handler.handle( this );
|
handler.handle( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataInput getStream()
|
||||||
|
{
|
||||||
|
return new DataInputStream( new ByteArrayInputStream( data ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,8 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.io.DataInput;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -276,10 +278,9 @@ public class ServerConnector extends PacketHandler
|
|||||||
throw new IllegalStateException( "May not connect to another BungeCord!" );
|
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();
|
int count = in.readInt();
|
||||||
for ( int i = 0; i < count; i++ )
|
for ( int i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@ package net.md_5.bungee.connection;
|
|||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import java.io.DataInput;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.md_5.bungee.EntityMap;
|
import net.md_5.bungee.EntityMap;
|
||||||
@ -185,7 +186,7 @@ public class DownstreamBridge extends PacketHandler
|
|||||||
@Override
|
@Override
|
||||||
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
|
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() );
|
PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() );
|
||||||
|
|
||||||
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
|
if ( bungee.getPluginManager().callEvent( event ).isCancelled() )
|
||||||
|
@ -111,7 +111,7 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
throw new CancelSendSignal();
|
throw new CancelSendSignal();
|
||||||
}
|
}
|
||||||
// Hack around Forge race conditions
|
// 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();
|
throw new CancelSendSignal();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.md_5.bungee.api.ProxyServer;
|
|||||||
import net.md_5.bungee.api.ReconnectHandler;
|
import net.md_5.bungee.api.ReconnectHandler;
|
||||||
import net.md_5.bungee.api.config.ListenerInfo;
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
public abstract class AbstractReconnectManager implements ReconnectHandler
|
public abstract class AbstractReconnectManager implements ReconnectHandler
|
||||||
@ -15,13 +16,9 @@ public abstract class AbstractReconnectManager implements ReconnectHandler
|
|||||||
{
|
{
|
||||||
ListenerInfo listener = player.getPendingConnection().getListener();
|
ListenerInfo listener = player.getPendingConnection().getListener();
|
||||||
String name;
|
String name;
|
||||||
String forced = listener.getForcedHosts().get( player.getPendingConnection().getVirtualHost().getHostString() );
|
ServerInfo forced = getHost( player.getPendingConnection() );
|
||||||
if ( forced == null && listener.isForceDefault() )
|
|
||||||
{
|
|
||||||
forced = listener.getDefaultServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
String server = ( forced == null ) ? getStoredServer( player ) : forced;
|
String server = ( forced == null ) ? getStoredServer( player ) : forced.getName();
|
||||||
name = ( server != null ) ? server : listener.getDefaultServer();
|
name = ( server != null ) ? server : listener.getDefaultServer();
|
||||||
ServerInfo info = ProxyServer.getInstance().getServerInfo( name );
|
ServerInfo info = ProxyServer.getInstance().getServerInfo( name );
|
||||||
if ( info == null )
|
if ( info == null )
|
||||||
@ -32,5 +29,16 @@ public abstract class AbstractReconnectManager implements ReconnectHandler
|
|||||||
return info;
|
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);
|
protected abstract String getStoredServer(ProxiedPlayer player);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user