func (this *SessionOutBridge) SetCompression(threshold int) { if this.state == STATE_INIT || this.state == STATE_CONNECTED { this.session.SetCompression(threshold) } if this.compressionThreshold == threshold { return } this.compressionThreshold = threshold if threshold == -1 { this.pipeline.Remove("zlib") return } else { codec := packet.NewPacketCodecZlib(threshold) if this.pipeline.HasName("zlib") { this.pipeline.Replace("zlib", codec) } else { this.pipeline.AddBefore("zlib", "registry", codec) } } }
func (this *Session) SetCompression(threshold int) { if this.compressionThreshold == threshold { return } this.compressionThreshold = threshold registry := this.pipeline.Get("registry") if registry == minecraft.LoginPacketServerCodec { this.Write(minecraft.NewPacketClientLoginSetCompression(threshold)) } else if registry == minecraft.PlayPacketServerCodec { this.Write(minecraft.NewPacketClientSetCompression(threshold)) } if threshold == -1 { this.pipeline.Remove("zlib") return } else { codec := packet.NewPacketCodecZlib(threshold) if this.pipeline.HasName("zlib") { this.pipeline.Replace("zlib", codec) } else { this.pipeline.AddBefore("zlib", "registry", codec) } } }