Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Feb 10, 2024
1 parent 19eeae2 commit ac6b0e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ protected void encode(ChannelHandlerContext ctx, BedrockBatchWrapper msg, List<O
if (msg.getCompressed() == null && msg.getUncompressed() == null) {
throw new IllegalStateException("Batch was not encoded before");
} else if (msg.getCompressed() != null && !msg.isModified()) { // already compressed
if (this.prefixed) {
this.onPassedThrough(ctx, msg);
out.add(msg.retain());
} else { // we need to prefix the compressed data
if (!this.prefixed) { // we need to prefix the compressed data
CompositeByteBuf buf = ctx.alloc().compositeDirectBuffer(2);
buf.addComponent(true, ctx.alloc().ioBuffer(1).writeByte(getCompressionHeader(msg.getAlgorithm())));
buf.addComponent(true, msg.getCompressed().retainedSlice());

this.onPassedThrough(ctx, msg);
out.add(buf.retain());
msg.setCompressed(buf, msg.getAlgorithm());
}

this.onPassedThrough(ctx, msg);
out.add(msg.retain());
} else {
ByteBuf compressed = this.zstdCompression.encode(ctx, msg.getUncompressed());

Expand All @@ -59,14 +57,14 @@ protected byte getCompressionHeader0(CompressionAlgorithm algorithm) {
return -2;
}

return -1;
return super.getCompressionHeader0(algorithm);
}

protected CompressionAlgorithm getCompressionAlgorithm0(byte header) {
if (header == -2) {
return ProxyTransportAlgorithm.ZSTD;
}

return null;
return super.getCompressionAlgorithm0(header);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.waterdog.waterdogpe.network.connection.client.ClientConnection;
import dev.waterdog.waterdogpe.network.connection.codec.batch.BedrockBatchDecoder;
import dev.waterdog.waterdogpe.network.connection.codec.batch.BedrockBatchEncoder;
import dev.waterdog.waterdogpe.network.connection.codec.client.ClientPacketQueue;
import dev.waterdog.waterdogpe.network.connection.codec.compression.CompressionType;
import dev.waterdog.waterdogpe.network.connection.codec.packet.BedrockPacketCodec;
import dev.waterdog.waterdogpe.network.serverinfo.ServerInfo;
Expand Down Expand Up @@ -56,14 +57,13 @@ protected void initChannel(Channel channel) {
.addLast(FRAME_DECODER, new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
.addLast(FRAME_ENCODER, new LengthFieldPrepender(4));


ClientConnection connection = this.createConnection(channel);
channel.pipeline()
.addLast(ProxyTransportCompressionCodec.NAME, new ProxyTransportCompressionCodec(getCompressionStrategy(compression, rakVersion, true), false))
.addLast(BedrockBatchDecoder.NAME, BATCH_DECODER)
.addLast(BedrockBatchEncoder.NAME, new BedrockBatchEncoder())
.addLast(BedrockPacketCodec.NAME, getPacketCodec(rakVersion));

ClientConnection connection = this.createConnection(channel);
if (connection instanceof ChannelHandler handler) { // For reference: This will take care of the packets received being handled.
channel.pipeline().addLast(ClientConnection.NAME, handler);
}
Expand Down

This file was deleted.

0 comments on commit ac6b0e5

Please sign in to comment.