diff options
| author | mat <github@matdoes.dev> | 2023-02-13 18:22:42 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2023-02-13 18:22:42 -0600 |
| commit | edc37cfd4b16abc413733d91810efa774a91963f (patch) | |
| tree | ca20482714b7fe0731f8fe2187b54a19d836e7d6 /azalea-protocol/src/lib.rs | |
| parent | 37b0cbf0589913b4aab551ae011774e1c9680af7 (diff) | |
| download | azalea-drasl-edc37cfd4b16abc413733d91810efa774a91963f.tar.xz | |
fix bad compression on sending long packets
THANKS JAM \SHARP
Diffstat (limited to 'azalea-protocol/src/lib.rs')
| -rw-r--r-- | azalea-protocol/src/lib.rs | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs index 7c21f493..d9860a8b 100644 --- a/azalea-protocol/src/lib.rs +++ b/azalea-protocol/src/lib.rs @@ -79,14 +79,18 @@ impl Display for ServerAddress { #[cfg(test)] mod tests { - use std::io::Cursor; + use std::{ + io::Cursor, + time::{SystemTime, UNIX_EPOCH}, + }; use crate::{ - packets::login::{ - serverbound_hello_packet::ServerboundHelloPacket, ServerboundLoginPacket, + packets::{ + game::serverbound_chat_packet::{LastSeenMessagesUpdate, ServerboundChatPacket}, + login::{serverbound_hello_packet::ServerboundHelloPacket, ServerboundLoginPacket}, }, - read::read_packet, - write::write_packet, + read::{compression_decoder, read_packet}, + write::{compression_encoder, packet_encoder, write_packet}, }; use bytes::BytesMut; use uuid::Uuid; @@ -140,4 +144,29 @@ mod tests { .await .unwrap(); } + + #[tokio::test] + async fn test_read_long_compressed_chat() { + let compression_threshold = 256; + + let buf = packet_encoder( + &ServerboundChatPacket { + message: "a".repeat(256), + timestamp: 0, + salt: 0, + signature: None, + last_seen_messages: LastSeenMessagesUpdate::default(), + } + .get(), + ) + .unwrap(); + + let buf = compression_encoder(&buf, compression_threshold) + .await + .unwrap(); + + println!("{:?}", buf); + + compression_decoder(&mut Cursor::new(&buf), compression_threshold).unwrap(); + } } |
