3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Add compression support for proxy->server connections.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-07-25 11:05:07 -04:00
Ursprung ca63bfd558
Commit 3c8a52aeb0
3 geänderte Dateien mit 13 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -17,14 +17,12 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder<ByteBuf> {
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
if (msg.readableBytes() <= threshold) {
System.out.println("not compressing packet of 0x" + msg.readableBytes() + " size");
// Under the threshold, there is nothing to do.
ProtocolUtils.writeVarInt(out, 0);
out.writeBytes(msg);
return;
}
System.out.println("compressing packet of 0x" + msg.readableBytes() + " size");
Deflater deflater = new Deflater();
byte[] buf = new byte[msg.readableBytes()];
msg.readBytes(buf);

Datei anzeigen

@ -23,6 +23,12 @@ public class MinecraftPipelineUtils {
}
public static void enableCompression(Channel ch, int threshold) {
if (threshold == -1) {
ch.pipeline().remove("compress-decoder");
ch.pipeline().remove("compress-encoder");
return;
}
MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold);
MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold);

Datei anzeigen

@ -7,10 +7,7 @@ import io.minimum.minecraft.velocity.data.ServerInfo;
import io.minimum.minecraft.velocity.protocol.netty.MinecraftDecoder;
import io.minimum.minecraft.velocity.protocol.netty.MinecraftEncoder;
import io.minimum.minecraft.velocity.protocol.netty.MinecraftPipelineUtils;
import io.minimum.minecraft.velocity.protocol.packets.Disconnect;
import io.minimum.minecraft.velocity.protocol.packets.Handshake;
import io.minimum.minecraft.velocity.protocol.packets.ServerLogin;
import io.minimum.minecraft.velocity.protocol.packets.ServerLoginSuccess;
import io.minimum.minecraft.velocity.protocol.packets.*;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import net.kyori.text.TextComponent;
@ -119,6 +116,12 @@ public class ServerConnection {
proxyPlayer.handleConnectionException(disconnect);
}
if (packet instanceof SetCompression) {
System.out.println("Enabling compression on server connection, this is inefficient!");
SetCompression sc = (SetCompression) packet;
MinecraftPipelineUtils.enableCompression(channel, sc.getThreshold());
}
if (packet instanceof ServerLoginSuccess) {
// the player has been logged on.
System.out.println("Player connected to remote server");