Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ default String decompressHandlerName() {
return "decompress";
}

/**
* Returns whether the platform's compression handler also writes the packet length. Only used in the 1.8 -> 1.7 protocol.
*
* @return true if the compression handler writes the packet length
*/
default boolean compressHandlerWritesLength() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@

public class ForwardMessageToByteEncoder extends MessageToByteEncoder<ByteBuf> {

private final boolean writeLength;

public ForwardMessageToByteEncoder(final boolean writeLength) {
this.writeLength = writeLength;
}

@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) {
Types.VAR_INT.writePrimitive(out, msg.readableBytes());
if (writeLength) {
Types.VAR_INT.writePrimitive(out, msg.readableBytes());
}
out.writeBytes(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onTransformPacket(UserConnection user) {

if (compressor != null) { // We can neutralize the effect of compressor to the client
pipeline.replace(decompressor, decompressor, new EmptyChannelHandler());
pipeline.replace(compressor, compressor, new ForwardMessageToByteEncoder());
pipeline.replace(compressor, compressor, new ForwardMessageToByteEncoder(ViaRewind.getPlatform().compressHandlerWritesLength()));
} else {
throw new IllegalStateException("Couldn't remove compression for 1.7!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public String decompressHandlerName() {
return "compression-decoder";
}

@Override
public boolean compressHandlerWritesLength() {
return true;
}

}