diff --git a/build.gradle b/build.gradle index c6cc19d..a007466 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,7 @@ dependencies { include "com.viaversion:viarewind-common:3.0.6-SNAPSHOT" include "net.raphimc:ViaLegacy:2.2.22-SNAPSHOT" include "net.raphimc:ViaAprilFools:2.0.11-SNAPSHOT" - include("net.raphimc:ViaBedrock:0.0.4-SNAPSHOT") { + include("net.raphimc:ViaBedrock:0.0.5-SNAPSHOT") { exclude group: "io.netty" exclude group: "io.jsonwebtoken" } diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyNettyPipelineProvider.java b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyNettyPipelineProvider.java index 3dd566c..2eace1f 100644 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyNettyPipelineProvider.java +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyNettyPipelineProvider.java @@ -20,9 +20,9 @@ package net.raphimc.viaproxy.protocolhack.providers; import com.viaversion.viaversion.api.connection.UserConnection; import io.netty.channel.Channel; import net.raphimc.netminecraft.constants.MCPipeline; -import net.raphimc.viabedrock.netty.AesEncryption; -import net.raphimc.viabedrock.netty.SnappyCompression; -import net.raphimc.viabedrock.netty.ZLibCompression; +import net.raphimc.viabedrock.api.io.compression.ProtocolCompression; +import net.raphimc.viabedrock.netty.AesEncryptionCodec; +import net.raphimc.viabedrock.netty.CompressionCodec; import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider; import net.raphimc.vialoader.netty.VLPipeline; import net.raphimc.viaproxy.proxy.session.ProxyConnection; @@ -32,22 +32,16 @@ import javax.crypto.SecretKey; public class ViaProxyNettyPipelineProvider extends NettyPipelineProvider { @Override - public void enableCompression(UserConnection user, int threshold, int algorithm) { + public void enableCompression(UserConnection user, ProtocolCompression protocolCompression) { final ProxyConnection proxyConnection = ProxyConnection.fromUserConnection(user); final Channel channel = proxyConnection.getChannel(); + if (channel.pipeline().names().contains(MCPipeline.COMPRESSION_HANDLER_NAME)) { + throw new IllegalStateException("Compression already enabled"); + } + try { - channel.pipeline().remove(MCPipeline.COMPRESSION_HANDLER_NAME); - switch (algorithm) { - case 0: - channel.pipeline().addBefore(MCPipeline.SIZER_HANDLER_NAME, MCPipeline.COMPRESSION_HANDLER_NAME, new ZLibCompression()); - break; - case 1: - channel.pipeline().addBefore(MCPipeline.SIZER_HANDLER_NAME, MCPipeline.COMPRESSION_HANDLER_NAME, new SnappyCompression()); - break; - default: - throw new IllegalStateException("Invalid compression algorithm: " + algorithm); - } + channel.pipeline().addBefore(MCPipeline.SIZER_HANDLER_NAME, MCPipeline.COMPRESSION_HANDLER_NAME, new CompressionCodec(protocolCompression)); } catch (Throwable e) { throw new RuntimeException(e); } @@ -58,9 +52,12 @@ public class ViaProxyNettyPipelineProvider extends NettyPipelineProvider { final ProxyConnection proxyConnection = ProxyConnection.fromUserConnection(user); final Channel channel = proxyConnection.getChannel(); + if (channel.pipeline().names().contains(MCPipeline.ENCRYPTION_HANDLER_NAME)) { + throw new IllegalStateException("Encryption already enabled"); + } + try { - channel.pipeline().remove(MCPipeline.ENCRYPTION_HANDLER_NAME); - channel.pipeline().addAfter(VLPipeline.VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, MCPipeline.ENCRYPTION_HANDLER_NAME, new AesEncryption(key)); + channel.pipeline().addAfter(VLPipeline.VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME, MCPipeline.ENCRYPTION_HANDLER_NAME, new AesEncryptionCodec(key)); } catch (Throwable e) { throw new RuntimeException(e); } diff --git a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java index 7b0c8c9..dfe1d70 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerChannelInitializer.java @@ -79,6 +79,10 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer channel.pipeline().addLast(new ViaProxyVLPipeline(user, proxyConnection.getServerVersion())); channel.pipeline().addAfter(VLPipeline.VIA_CODEC_NAME, "via-" + MCPipeline.FLOW_CONTROL_HANDLER_NAME, new NoReadFlowControlHandler()); + if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest)) { + channel.pipeline().remove(MCPipeline.COMPRESSION_HANDLER_NAME); + channel.pipeline().remove(MCPipeline.ENCRYPTION_HANDLER_NAME); + } if (ViaProxy.EVENT_MANAGER.call(new Proxy2ServerChannelInitializeEvent(ITyped.Type.POST, channel, false)).isCancelled()) { channel.close();