Fix compression packet order (#811)

This commit is contained in:
EpicPlayerA10 2022-03-26 15:40:14 +01:00 committed by GitHub
parent 835b8ca89d
commit 40024da5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package net.minestom.server.network;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.event.EventDispatcher;
import net.minestom.server.event.player.AsyncPlayerPreLoginEvent;
@ -10,6 +11,7 @@ import net.minestom.server.instance.Instance;
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
import net.minestom.server.network.packet.server.play.KeepAlivePacket;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.network.player.PlayerSocketConnection;
import net.minestom.server.utils.StringUtils;
import net.minestom.server.utils.async.AsyncUtils;
import net.minestom.server.utils.debug.DebugUtils;
@ -194,6 +196,11 @@ public final class ConnectionManager {
public CompletableFuture<Void> startPlayState(@NotNull Player player, boolean register) {
return AsyncUtils.runAsync(() -> {
final PlayerConnection playerConnection = player.getPlayerConnection();
// Compression
if (playerConnection instanceof PlayerSocketConnection socketConnection) {
final int threshold = MinecraftServer.getCompressionThreshold();
if (threshold > 0) socketConnection.startCompression();
}
// Call pre login event
AsyncPlayerPreLoginEvent asyncPlayerPreLoginEvent = new AsyncPlayerPreLoginEvent(player);
EventDispatcher.call(asyncPlayerPreLoginEvent);

View File

@ -2,7 +2,6 @@ package net.minestom.server.network.packet.client.login;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.extras.MojangAuth;
import net.minestom.server.extras.bungee.BungeeCordProxy;
@ -31,20 +30,10 @@ public record LoginStartPacket(@NotNull String username) implements ClientPrepla
@Override
public void process(@NotNull PlayerConnection connection) {
final boolean isSocketConnection = connection instanceof PlayerSocketConnection;
// Cache the login username and start compression if enabled
// Proxy support (only for socket clients) and cache the login username
if (isSocketConnection) {
PlayerSocketConnection socketConnection = (PlayerSocketConnection) connection;
socketConnection.UNSAFE_setLoginUsername(username);
// Compression
final int threshold = MinecraftServer.getCompressionThreshold();
if (threshold > 0) {
socketConnection.startCompression();
}
}
// Proxy support (only for socket clients)
if (isSocketConnection) {
final PlayerSocketConnection socketConnection = (PlayerSocketConnection) connection;
// Velocity support
if (VelocityProxy.isEnabled()) {
final int messageId = ThreadLocalRandom.current().nextInt();