mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 12:46:05 +01:00
Add (hopefully temporary) queue for plugin messages to server
This commit is contained in:
parent
7b27dfaf5e
commit
497c6879e0
@ -15,6 +15,7 @@ public class MinecraftEncoder extends MessageToByteEncoder<DefinedPacket>
|
||||
@Setter
|
||||
private Protocol protocol;
|
||||
private boolean server;
|
||||
@Getter
|
||||
@Setter
|
||||
private int protocolVersion;
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -13,6 +14,7 @@ import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.netty.ChannelWrapper;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Protocol;
|
||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ -30,6 +32,7 @@ public class ServerConnection implements Server
|
||||
private final boolean forgeServer = false;
|
||||
@Getter
|
||||
private final Queue<KeepAliveData> keepAlives = new ArrayDeque<>();
|
||||
private final Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private final Unsafe unsafe = new Unsafe()
|
||||
{
|
||||
@ -40,10 +43,31 @@ public class ServerConnection implements Server
|
||||
}
|
||||
};
|
||||
|
||||
public void sendPacketQueued(DefinedPacket packet)
|
||||
{
|
||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
||||
if ( !encodeProtocol.TO_SERVER.hasPacket( packet.getClass(), ch.getEncodeVersion() ) )
|
||||
{
|
||||
packetQueue.add( packet );
|
||||
} else
|
||||
{
|
||||
unsafe().sendPacket( packet );
|
||||
}
|
||||
}
|
||||
|
||||
public void sendQueuedPackets()
|
||||
{
|
||||
DefinedPacket packet;
|
||||
while ( ( packet = packetQueue.poll() ) != null )
|
||||
{
|
||||
unsafe().sendPacket( packet );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendData(String channel, byte[] data)
|
||||
{
|
||||
unsafe().sendPacket( new PluginMessage( channel, data, forgeServer ) );
|
||||
sendPacketQueued( new PluginMessage( channel, data, forgeServer ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,7 +182,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
public void sendPacketQueued(DefinedPacket packet)
|
||||
{
|
||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
||||
if ( encodeProtocol != Protocol.GAME && !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
|
||||
if ( !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
|
||||
{
|
||||
packetQueue.add( packet );
|
||||
} else
|
||||
|
@ -331,6 +331,9 @@ public class UpstreamBridge extends PacketHandler
|
||||
ch.setDecodeProtocol( Protocol.CONFIGURATION );
|
||||
ch.write( new LoginAcknowledged() );
|
||||
ch.setEncodeProtocol( Protocol.CONFIGURATION );
|
||||
|
||||
con.getServer().sendQueuedPackets();
|
||||
|
||||
throw CancelSendSignal.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,11 @@ public class ChannelWrapper
|
||||
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
|
||||
}
|
||||
|
||||
public int getEncodeVersion()
|
||||
{
|
||||
return ch.pipeline().get( MinecraftEncoder.class ).getProtocolVersion();
|
||||
}
|
||||
|
||||
public void write(Object packet)
|
||||
{
|
||||
if ( !closed )
|
||||
|
Loading…
Reference in New Issue
Block a user