geforkt von Mirrors/Velocity
Add compression support for proxy->server connections.
Dieser Commit ist enthalten in:
Ursprung
ca63bfd558
Commit
3c8a52aeb0
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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");
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren