diff --git a/src/main/java/com/zenith/Proxy.java b/src/main/java/com/zenith/Proxy.java index 5323b0340..6086817d5 100644 --- a/src/main/java/com/zenith/Proxy.java +++ b/src/main/java/com/zenith/Proxy.java @@ -284,7 +284,7 @@ public synchronized void connect() { if (CONFIG.client.viaversion.autoProtocolVersion) updateViaProtocolVersion(); ChannelInitializer originalChannelInitializer = this.client.buildChannelInitializer(); - final MCProxyViaServerProxy viaProxy = new MCProxyViaServerProxy(); + final MCProxyViaServerProxy viaProxy = new MCProxyViaServerProxy(this.client); viaProxy.init(); ChannelInitializer viaChannelInitializer = viaProxy.inject(originalChannelInitializer); Bootstrap bootstrap = this.client.buildBootstrap(viaChannelInitializer); diff --git a/src/main/java/com/zenith/via/MCProxyViaServerProxy.java b/src/main/java/com/zenith/via/MCProxyViaServerProxy.java index f71067d6e..70039e3dd 100644 --- a/src/main/java/com/zenith/via/MCProxyViaServerProxy.java +++ b/src/main/java/com/zenith/via/MCProxyViaServerProxy.java @@ -13,6 +13,7 @@ import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.util.VersionInfo; import com.viaversion.viaversion.velocity.util.LoggerWrapper; +import com.zenith.network.client.ClientSession; import com.zenith.via.handler.MCProxyViaChannelInitializer; import com.zenith.via.platform.*; import io.netty.channel.Channel; @@ -33,6 +34,11 @@ public class MCProxyViaServerProxy implements ViaServerProxyPlatform inject(final ChannelInitializer original) { - return new MCProxyViaChannelInitializer(original); + return new MCProxyViaChannelInitializer(original, this.client); } @Override diff --git a/src/main/java/com/zenith/via/handler/MCProxyViaChannelInitializer.java b/src/main/java/com/zenith/via/handler/MCProxyViaChannelInitializer.java index cf6e8278d..d3b4a74ae 100644 --- a/src/main/java/com/zenith/via/handler/MCProxyViaChannelInitializer.java +++ b/src/main/java/com/zenith/via/handler/MCProxyViaChannelInitializer.java @@ -2,6 +2,7 @@ import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; +import com.zenith.network.client.ClientSession; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import lombok.NonNull; @@ -21,9 +22,11 @@ public class MCProxyViaChannelInitializer extends ChannelInitializer { } private final ChannelInitializer original; + private final ClientSession client; - public MCProxyViaChannelInitializer(ChannelInitializer original) { + public MCProxyViaChannelInitializer(ChannelInitializer original, final ClientSession client) { this.original = original; + this.client = client; } @Override @@ -39,7 +42,7 @@ protected void initChannel(@NonNull Channel channel) throws Exception { // pipeline order before readTimeout -> encryption -> sizer -> compression -> codec -> manager // pipeline order after readTimeout -> encryption -> sizer -> compression -> via-encoder -> via-decoder -> codec -> manager - channel.pipeline().addBefore("codec", "via-encoder", new MCProxyViaEncodeHandler(userConnection)); - channel.pipeline().addBefore("codec", "via-decoder", new MCProxyViaDecodeHandler(userConnection)); + channel.pipeline().addBefore("codec", "via-encoder", new MCProxyViaEncodeHandler(userConnection, this.client)); + channel.pipeline().addBefore("codec", "via-decoder", new MCProxyViaDecodeHandler(userConnection, this.client)); } } diff --git a/src/main/java/com/zenith/via/handler/MCProxyViaDecodeHandler.java b/src/main/java/com/zenith/via/handler/MCProxyViaDecodeHandler.java index 61fd90977..21e2a053e 100644 --- a/src/main/java/com/zenith/via/handler/MCProxyViaDecodeHandler.java +++ b/src/main/java/com/zenith/via/handler/MCProxyViaDecodeHandler.java @@ -3,6 +3,7 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.exception.CancelCodecException; import com.viaversion.viaversion.exception.CancelDecoderException; +import com.zenith.network.client.ClientSession; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -13,9 +14,11 @@ @ChannelHandler.Sharable public class MCProxyViaDecodeHandler extends MessageToMessageDecoder { private final UserConnection info; + private final ClientSession client; - public MCProxyViaDecodeHandler(UserConnection info) { + public MCProxyViaDecodeHandler(UserConnection info, final ClientSession client) { this.info = info; + this.client = client; } @Override @@ -38,6 +41,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List o @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof CancelCodecException) return; - super.exceptionCaught(ctx, cause); + if (!this.client.callPacketError(cause)) + super.exceptionCaught(ctx, cause); } } diff --git a/src/main/java/com/zenith/via/handler/MCProxyViaEncodeHandler.java b/src/main/java/com/zenith/via/handler/MCProxyViaEncodeHandler.java index 8db885e83..f9ffe9298 100644 --- a/src/main/java/com/zenith/via/handler/MCProxyViaEncodeHandler.java +++ b/src/main/java/com/zenith/via/handler/MCProxyViaEncodeHandler.java @@ -3,6 +3,7 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.exception.CancelCodecException; import com.viaversion.viaversion.exception.CancelEncoderException; +import com.zenith.network.client.ClientSession; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -13,9 +14,11 @@ @ChannelHandler.Sharable public class MCProxyViaEncodeHandler extends MessageToMessageEncoder { private final UserConnection info; + private final ClientSession client; - public MCProxyViaEncodeHandler(UserConnection info) { + public MCProxyViaEncodeHandler(UserConnection info, final ClientSession client) { this.info = info; + this.client = client; } @Override @@ -38,6 +41,7 @@ protected void encode(ChannelHandlerContext ctx, ByteBuf bytebuf, List o @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof CancelCodecException) return; - super.exceptionCaught(ctx, cause); + if (!this.client.callPacketError(cause)) + super.exceptionCaught(ctx, cause); } } diff --git a/src/main/java/com/zenith/via/platform/MCProxyViaAPI.java b/src/main/java/com/zenith/via/platform/MCProxyViaAPI.java index 2c46d44e0..2afec0e77 100644 --- a/src/main/java/com/zenith/via/platform/MCProxyViaAPI.java +++ b/src/main/java/com/zenith/via/platform/MCProxyViaAPI.java @@ -8,7 +8,7 @@ public class MCProxyViaAPI extends ViaAPIBase { @Override public int getPlayerVersion(MinecraftProtocol player) { - return ProtocolVersion.v1_12_2.getVersion(); + return ProtocolVersion.v1_20.getVersion(); } @Override diff --git a/src/test/java/com/zenith/PingTest.java b/src/test/java/com/zenith/PingTest.java index 4de14785e..9e0c7a5ce 100644 --- a/src/test/java/com/zenith/PingTest.java +++ b/src/test/java/com/zenith/PingTest.java @@ -11,4 +11,10 @@ public void constPing() { // testing ping srv dns resolver assertEquals(ProtocolVersionDetector.getProtocolVersion("constantiam.net", 25565), 762); } + +// @Test + public void nineb9tPing() { + // testing ping srv dns resolver + assertEquals(ProtocolVersionDetector.getProtocolVersion("9b9t.com", 25565), 757); + } }