diff --git a/src/main/java/com/github/creeper123123321/viafabric/handler/VRDecodeHandler.java b/src/main/java/com/github/creeper123123321/viafabric/handler/VRDecodeHandler.java index a6fb467..e531c89 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/handler/VRDecodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viafabric/handler/VRDecodeHandler.java @@ -94,28 +94,11 @@ public class VRDecodeHandler extends ByteToMessageDecoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PipelineUtil.containsCause(cause, CancelException.class)) { - if (user.isActive()) { - for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { - runnable.run(); - } - } + if (PipelineUtil.containsCause(cause, CancelException.class)) return; - } super.exceptionCaught(ctx, cause); } - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - user.getPostProcessingTasks().get().addLast(new ArrayList<>()); - super.channelRead(ctx, msg); - if (user.isActive()) { - for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { - runnable.run(); - } - } - } - @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { ProtocolInfo info = user.get(ProtocolInfo.class); diff --git a/src/main/java/com/github/creeper123123321/viafabric/handler/VREncodeHandler.java b/src/main/java/com/github/creeper123123321/viafabric/handler/VREncodeHandler.java index 260d0e8..f1533ff 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/handler/VREncodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viafabric/handler/VREncodeHandler.java @@ -104,25 +104,8 @@ public class VREncodeHandler extends MessageToByteEncoder { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (PipelineUtil.containsCause(cause, CancelException.class)) { - if (user.isActive()) { - for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { - runnable.run(); - } - } + if (PipelineUtil.containsCause(cause, CancelException.class)) return; - } super.exceptionCaught(ctx, cause); } - - @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { - user.getPostProcessingTasks().get().addLast(new ArrayList<>()); - super.write(ctx, msg, promise); - if (user.isActive()) { - for (Runnable runnable : user.getPostProcessingTasks().get().pollLast()) { - runnable.run(); - } - } - } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/ClientConnectionChInit.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/ClientConnectionChInit.java index 42e9861..8c60ce7 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/ClientConnectionChInit.java +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/ClientConnectionChInit.java @@ -44,7 +44,7 @@ public class ClientConnectionChInit { @Inject(method = "initChannel(Lio/netty/channel/Channel;)V", at = @At(value = "TAIL"), remap = false) private void onInitChannel(Channel channel, CallbackInfo ci) { if (channel instanceof SocketChannel) { - UserConnection user = new VRUserConnection((SocketChannel) channel); + UserConnection user = new VRUserConnection(channel); new ProtocolPipeline(user).add(new Interceptor()); MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder"); diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinSplitterHandler.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinSplitterHandler.java new file mode 100644 index 0000000..c6f3290 --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinSplitterHandler.java @@ -0,0 +1,51 @@ +/* + * MIT License + * + * Copyright (c) 2018 creeper123123321 and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.github.creeper123123321.viafabric.mixin.client; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import net.minecraft.network.SplitterHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(SplitterHandler.class) +public abstract class MixinSplitterHandler extends ByteToMessageDecoder { + @Inject(method = "", at = @At("TAIL")) + public void onInit(CallbackInfo ci) { + setSingleDecode(true); + } + + @Inject(method = "decode", at = @At("RETURN"), remap = false) + protected void onDecode(ChannelHandlerContext ctx, ByteBuf in, List out, CallbackInfo ci) { + if (!out.isEmpty()) { + ctx.executor().execute(() -> ctx.channel().read()); + } + } +}