Hide PlayerConnection#enableCompression into NettyPlayerConnection

This commit is contained in:
themode 2020-10-24 00:05:22 +02:00
parent 70e047e6ee
commit 86d6092547
5 changed files with 13 additions and 12 deletions

View File

@ -40,9 +40,10 @@ public class EncryptionResponsePacket implements ClientPreplayPacket {
((NettyPlayerConnection) connection).setEncryptionKey(getSecretKey());
final int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
if (threshold > 0) {
connection.enableCompression(threshold);
if (threshold > 0 && connection instanceof NettyPlayerConnection) {
((NettyPlayerConnection) connection).enableCompression(threshold);
}
LoginSuccessPacket loginSuccessPacket = new LoginSuccessPacket(gameProfile.getId(), gameProfile.getName());
connection.sendPacket(loginSuccessPacket);
MinecraftServer.getLOGGER().info("UUID of player {} is {}", connection.getLoginUsername(), gameProfile.getId());

View File

@ -9,6 +9,7 @@ import net.minestom.server.network.packet.client.ClientPreplayPacket;
import net.minestom.server.network.packet.server.login.EncryptionRequestPacket;
import net.minestom.server.network.packet.server.login.LoginDisconnect;
import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
import net.minestom.server.network.player.NettyPlayerConnection;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.binary.BinaryReader;
@ -39,8 +40,8 @@ public class LoginStartPacket implements ClientPreplayPacket {
final int threshold = MinecraftServer.COMPRESSION_THRESHOLD;
if (threshold > 0) {
connection.enableCompression(threshold);
if (threshold > 0 && connection instanceof NettyPlayerConnection) {
((NettyPlayerConnection) connection).enableCompression(threshold);
}
LoginSuccessPacket successPacket = new LoginSuccessPacket(playerUuid, username);

View File

@ -12,11 +12,6 @@ import java.net.SocketAddress;
public class FakePlayerConnection extends PlayerConnection {
@Override
public void enableCompression(int threshold) {
throw new UnsupportedOperationException("FakePlayer cannot enable compression");
}
@Override
public void sendPacket(ByteBuf buffer, boolean copy) {
throw new UnsupportedOperationException("FakePlayer cannot read Bytebuf");

View File

@ -49,8 +49,14 @@ public class NettyPlayerConnection extends PlayerConnection {
getChannel().pipeline().addBefore("framer", "encrypt", new Encrypter(MojangCrypt.getCipher(1, secretKey)));
}
@Override
/**
* Enables compression and add a new channel to the pipeline.
*
* @param threshold the threshold for a packet to be compressible
* @throws IllegalStateException if encryption is already enabled for this connection
*/
public void enableCompression(int threshold) {
Check.stateCondition(compressed, "Compression is already enabled!");
this.compressed = true;
sendPacket(new SetCompressionPacket(threshold));
channel.pipeline().addAfter("framer", "compressor", new PacketCompressor(threshold));

View File

@ -76,8 +76,6 @@ public abstract class PlayerConnection {
}
}
public abstract void enableCompression(int threshold);
/**
* Sends a raw {@link ByteBuf} to the client.
*