3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

fixed backend compression, remove debug

Dieser Commit ist enthalten in:
creeper123123321 2020-06-30 17:30:57 -03:00 committet von Five (Xer)
Ursprung bcb76350a1
Commit 2d33447fc1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: A3F306B10E6330E7
3 geänderte Dateien mit 12 neuen und 10 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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