mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-25 12:15:14 +01:00
Maybe better workaround for packets sent in bulk
This commit is contained in:
parent
05e58f65eb
commit
8ece4d1b99
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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 = "<init>", 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<Object> out, CallbackInfo ci) {
|
||||
if (!out.isEmpty()) {
|
||||
ctx.executor().execute(() -> ctx.channel().read());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user