mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 20:59:12 +01:00
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;
|
||||
|
||||
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 ) );
|
||||
}
|
||||
}
|
||||
|
@ -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++ )
|
||||
{
|
||||
|
@ -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() )
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user