fixed backend compression, remove debug

This commit is contained in:
creeper123123321 2020-06-30 17:30:57 -03:00 committed by Five (Xer)
parent bcb76350a1
commit 2d33447fc1
No known key found for this signature in database
GPG Key ID: A3F306B10E6330E7
3 changed files with 12 additions and 10 deletions

View File

@ -5,11 +5,9 @@ import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelDecoderException;
import us.myles.ViaVersion.exception.CancelCodecException;
import us.myles.ViaVersion.exception.CancelDecoderException;
import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
@ -18,7 +16,8 @@ import java.util.List;
@ChannelHandler.Sharable
public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info;
boolean handledCompression;
private boolean handledCompression;
private boolean skipDoubleTransform;
public VelocityDecodeHandler(UserConnection info) {
this.info = info;
@ -26,6 +25,12 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (skipDoubleTransform) {
skipDoubleTransform = false;
out.add(bytebuf.retain());
return;
}
if (!info.checkIncomingPacket()) throw CancelDecoderException.generate(null);
if (!info.shouldTransformPacket()) {
out.add(bytebuf.retain());
@ -40,6 +45,7 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
if (needsCompress) {
recompress(ctx, transformedBuf);
skipDoubleTransform = true;
}
out.add(transformedBuf.retain());
} finally {
@ -48,13 +54,12 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf draft) throws InvocationTargetException {
//if (handledCompression) return false;
if (handledCompression) return false;
int decoderIndex = ctx.pipeline().names().indexOf("compression-decoder");
if (decoderIndex == -1) return false;
handledCompression = true;
if (decoderIndex > ctx.pipeline().names().indexOf("via-decoder")) {
System.out.println("bad decoder order");
// Need to decompress this packet due to bad order
ByteBuf decompressed = (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder<?>) ctx.pipeline().get("compression-decoder"), ctx, draft).get(0);
try {

View File

@ -47,13 +47,12 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
}
private boolean handleCompressionOrder(ChannelHandlerContext ctx, ByteBuf buf) throws InvocationTargetException {
//if (handledCompression) return false;
if (handledCompression) return false;
int encoderIndex = ctx.pipeline().names().indexOf("compression-encoder");
if (encoderIndex == -1) return false;
handledCompression = true;
if (encoderIndex > ctx.pipeline().names().indexOf("via-encoder")) {
System.out.println("bad decoder order");
// Need to decompress this packet due to bad order
ByteBuf decompressed = (ByteBuf) PipelineUtil.callDecode((MessageToMessageDecoder<?>) ctx.pipeline().get("compression-decoder"), ctx, buf).get(0);
try {

View File

@ -31,14 +31,12 @@ public class VelocityVersionProvider extends VersionProvider {
}
private int getBackProtocol(UserConnection user) throws Exception {
System.out.println("backend protocol!");
ChannelHandler mcHandler = user.getChannel().pipeline().get("handler");
return ProtocolDetectorService.getProtocolId(
((ServerConnection) getAssociation.invoke(mcHandler)).getServerInfo().getName());
}
private int getFrontProtocol(UserConnection user) throws Exception {
System.out.println("frontend protocol!");
int playerVersion = user.getProtocolInfo().getProtocolVersion();
IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()