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
|
@Setter
|
||||||
private Protocol protocol;
|
private Protocol protocol;
|
||||||
private boolean server;
|
private boolean server;
|
||||||
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private int protocolVersion;
|
private int protocolVersion;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.api.connection.Server;
|
||||||
import net.md_5.bungee.netty.ChannelWrapper;
|
import net.md_5.bungee.netty.ChannelWrapper;
|
||||||
import net.md_5.bungee.protocol.DefinedPacket;
|
import net.md_5.bungee.protocol.DefinedPacket;
|
||||||
|
import net.md_5.bungee.protocol.Protocol;
|
||||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -30,6 +32,7 @@ public class ServerConnection implements Server
|
|||||||
private final boolean forgeServer = false;
|
private final boolean forgeServer = false;
|
||||||
@Getter
|
@Getter
|
||||||
private final Queue<KeepAliveData> keepAlives = new ArrayDeque<>();
|
private final Queue<KeepAliveData> keepAlives = new ArrayDeque<>();
|
||||||
|
private final Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
private final Unsafe unsafe = new Unsafe()
|
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
|
@Override
|
||||||
public void sendData(String channel, byte[] data)
|
public void sendData(String channel, byte[] data)
|
||||||
{
|
{
|
||||||
unsafe().sendPacket( new PluginMessage( channel, data, forgeServer ) );
|
sendPacketQueued( new PluginMessage( channel, data, forgeServer ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -182,7 +182,7 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
public void sendPacketQueued(DefinedPacket packet)
|
public void sendPacketQueued(DefinedPacket packet)
|
||||||
{
|
{
|
||||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
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 );
|
packetQueue.add( packet );
|
||||||
} else
|
} else
|
||||||
|
@ -331,6 +331,9 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
ch.setDecodeProtocol( Protocol.CONFIGURATION );
|
ch.setDecodeProtocol( Protocol.CONFIGURATION );
|
||||||
ch.write( new LoginAcknowledged() );
|
ch.write( new LoginAcknowledged() );
|
||||||
ch.setEncodeProtocol( Protocol.CONFIGURATION );
|
ch.setEncodeProtocol( Protocol.CONFIGURATION );
|
||||||
|
|
||||||
|
con.getServer().sendQueuedPackets();
|
||||||
|
|
||||||
throw CancelSendSignal.INSTANCE;
|
throw CancelSendSignal.INSTANCE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,11 @@ public class ChannelWrapper
|
|||||||
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
|
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getEncodeVersion()
|
||||||
|
{
|
||||||
|
return ch.pipeline().get( MinecraftEncoder.class ).getProtocolVersion();
|
||||||
|
}
|
||||||
|
|
||||||
public void write(Object packet)
|
public void write(Object packet)
|
||||||
{
|
{
|
||||||
if ( !closed )
|
if ( !closed )
|
||||||
|
Loading…
Reference in New Issue
Block a user