aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Sacchini <joey@sacchini.net>2020-12-03 01:37:10 -0500
committerJoey Sacchini <joey@sacchini.net>2020-12-03 01:37:10 -0500
commit0888fc50a6fb379a378193a5cbaecdaa1ac03d17 (patch)
tree0bb420621e5d9bbb40d8d72429d5cc1ba0b72204
parentd03d9bf2d0a3496286b3a08931d0f07bc6a40033 (diff)
downloadcraftio-rs-0888fc50a6fb379a378193a5cbaecdaa1ac03d17.tar.gz
craftio-rs-0888fc50a6fb379a378193a5cbaecdaa1ac03d17.tar.bz2
craftio-rs-0888fc50a6fb379a378193a5cbaecdaa1ac03d17.zip
make sure we set data_len to 0 when writing in compressed mode below threshold
-rw-r--r--Cargo.toml2
-rw-r--r--src/reader.rs16
-rw-r--r--src/writer.rs1
3 files changed, 15 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 56b60b9..d8e1c24 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2018"
license = "APACHE 2.0"
[dependencies]
-mcproto-rs = { git = "https://github.com/Twister915/mcproto-rs", branch = "master", default-features = false, features = ["std", "v1_16_3"] }
+mcproto-rs = { git = "https://github.com/Twister915/mcproto-rs", branch = "master", default-features = false, features = ["std", "v1_15_2", "v1_16_3"] }
futures = { version = "0.3.8", optional = true }
async-trait = { version = "0.1.42", optional = true }
aes = "0.6.0"
diff --git a/src/reader.rs b/src/reader.rs
index 001a561..4920e69 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -122,7 +122,10 @@ where
{
let (primary_packet_len, len_bytes) = rr_unwrap!(self.read_one_varint_sync());
let primary_packet_len = primary_packet_len.0 as usize;
- rr_unwrap!(self.read_n(VAR_INT_BUF_SIZE, primary_packet_len - VAR_INT_BUF_SIZE + len_bytes));
+ rr_unwrap!(self.read_n(
+ VAR_INT_BUF_SIZE,
+ primary_packet_len - VAR_INT_BUF_SIZE + len_bytes
+ ));
self.read_packet_in_buf::<'a, P>(len_bytes, primary_packet_len)
}
}
@@ -139,7 +142,13 @@ where
{
let (primary_packet_len, len_bytes) = rr_unwrap!(self.read_one_varint_async().await);
let primary_packet_len = primary_packet_len.0 as usize;
- rr_unwrap!(self.read_n_async(VAR_INT_BUF_SIZE, primary_packet_len - VAR_INT_BUF_SIZE + len_bytes).await);
+ rr_unwrap!(
+ self.read_n_async(
+ VAR_INT_BUF_SIZE,
+ primary_packet_len - VAR_INT_BUF_SIZE + len_bytes
+ )
+ .await
+ );
self.read_packet_in_buf::<P>(len_bytes, primary_packet_len)
}
}
@@ -211,7 +220,8 @@ impl<R> CraftReader<R> {
P: RawPacket<'a>,
{
// find data in buf
- let buf = &mut self.raw_buf.as_mut().expect("should exist right now")[offset..offset+size];
+ let buf =
+ &mut self.raw_buf.as_mut().expect("should exist right now")[offset..offset + size];
// decrypt the packet if encryption is enabled
if let Some(encryption) = self.encryption.as_mut() {
encryption.decrypt(buf);
diff --git a/src/writer.rs b/src/writer.rs
index a1f97c1..4c2de69 100644
--- a/src/writer.rs
+++ b/src/writer.rs
@@ -238,6 +238,7 @@ impl<W> CraftWriter<W> {
let start_offset = packet_len_start_at + n_shift_packet_len;
let end_at = start_offset + packet_len_bytes + 1 + body_size;
+ buf[start_offset+packet_len_bytes] = 0; // data_len = 0
&mut buf[start_offset..end_at]
}
} else {