#3797: Expose sendPacketQueued to unsafe interface
This commit is contained in:
parent
47f8c29a7c
commit
9476ffccdb
@ -84,5 +84,15 @@ public interface Connection
|
|||||||
* @param packet the packet to send
|
* @param packet the packet to send
|
||||||
*/
|
*/
|
||||||
void sendPacket(DefinedPacket packet);
|
void sendPacket(DefinedPacket packet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue a packet to this connection.
|
||||||
|
* If the packet is not registered for the connections current encoder protocol, it will be queued until it is,
|
||||||
|
* otherwise it will be sent immediately.
|
||||||
|
*
|
||||||
|
* @param packet the packet to be queued
|
||||||
|
* @throws UnsupportedOperationException if used for a PendingConnection
|
||||||
|
*/
|
||||||
|
void sendPacketQueued(DefinedPacket packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class BungeeTitle implements Title
|
|||||||
{
|
{
|
||||||
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_17 )
|
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_17 )
|
||||||
{
|
{
|
||||||
( (UserConnection) player ).sendPacketQueued( packet.newPacket );
|
player.unsafe().sendPacketQueued( packet.newPacket );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
player.unsafe().sendPacket( packet.oldPacket );
|
player.unsafe().sendPacket( packet.oldPacket );
|
||||||
|
@ -14,6 +14,7 @@ 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.Protocol;
|
||||||
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||||
import net.md_5.bungee.protocol.packet.PluginMessage;
|
import net.md_5.bungee.protocol.packet.PluginMessage;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -40,6 +41,18 @@ public class ServerConnection implements Server
|
|||||||
{
|
{
|
||||||
ch.write( packet );
|
ch.write( packet );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendPacketQueued(DefinedPacket packet)
|
||||||
|
{
|
||||||
|
if ( ch.getEncodeVersion() >= ProtocolConstants.MINECRAFT_1_20_2 )
|
||||||
|
{
|
||||||
|
ServerConnection.this.sendPacketQueued( packet );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
sendPacket( packet );
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void sendPacketQueued(DefinedPacket packet)
|
public void sendPacketQueued(DefinedPacket packet)
|
||||||
@ -53,6 +66,8 @@ public class ServerConnection implements Server
|
|||||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
Protocol encodeProtocol = ch.getEncodeProtocol();
|
||||||
if ( !encodeProtocol.TO_SERVER.hasPacket( packet.getClass(), ch.getEncodeVersion() ) )
|
if ( !encodeProtocol.TO_SERVER.hasPacket( packet.getClass(), ch.getEncodeVersion() ) )
|
||||||
{
|
{
|
||||||
|
// we should limit this so bad api usage won't oom the server.
|
||||||
|
Preconditions.checkState( packetQueue.size() <= 4096, "too many queued packets" );
|
||||||
packetQueue.add( packet );
|
packetQueue.add( packet );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
@ -150,6 +150,18 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
{
|
{
|
||||||
ch.write( packet );
|
ch.write( packet );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendPacketQueued(DefinedPacket packet)
|
||||||
|
{
|
||||||
|
if ( pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_20_2 )
|
||||||
|
{
|
||||||
|
UserConnection.this.sendPacketQueued( packet );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
sendPacket( packet );
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public boolean init()
|
public boolean init()
|
||||||
@ -191,6 +203,8 @@ public final class UserConnection implements ProxiedPlayer
|
|||||||
Protocol encodeProtocol = ch.getEncodeProtocol();
|
Protocol encodeProtocol = ch.getEncodeProtocol();
|
||||||
if ( !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
|
if ( !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
|
||||||
{
|
{
|
||||||
|
// we should limit this so bad api usage won't oom the server.
|
||||||
|
Preconditions.checkState( packetQueue.size() <= 4096, "too many queued packets" );
|
||||||
packetQueue.add( packet );
|
packetQueue.add( packet );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
@ -122,6 +122,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|||||||
{
|
{
|
||||||
ch.write( packet );
|
ch.write( packet );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendPacketQueued(DefinedPacket packet)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported" );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@Getter
|
@Getter
|
||||||
private boolean onlineMode = BungeeCord.getInstance().config.isOnlineMode();
|
private boolean onlineMode = BungeeCord.getInstance().config.isOnlineMode();
|
||||||
|
@ -103,7 +103,7 @@ public class UpstreamBridge extends PacketHandler
|
|||||||
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_19_3 )
|
if ( player.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_19_3 )
|
||||||
{
|
{
|
||||||
// need to queue, because players in config state could receive it
|
// need to queue, because players in config state could receive it
|
||||||
( (UserConnection) player ).sendPacketQueued( newPacket );
|
player.unsafe().sendPacketQueued( newPacket );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
player.unsafe().sendPacket( oldPacket );
|
player.unsafe().sendPacket( oldPacket );
|
||||||
|
Loading…
Reference in New Issue
Block a user