diff options
| author | mat <github@matdoes.dev> | 2021-12-16 17:51:05 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-16 17:51:05 -0600 |
| commit | 227ba5511d50af8c7c46a47e09db7f55a0ed84b7 (patch) | |
| tree | 1067828ee2082e0f073a4d16b201b2888c55b6e8 /azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs | |
| parent | 999116ed7c5edf113e12aae150c2e23974d539dc (diff) | |
| download | azalea-drasl-227ba5511d50af8c7c46a47e09db7f55a0ed84b7.tar.xz | |
add a few more login packets
Diffstat (limited to 'azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs')
| -rw-r--r-- | azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs new file mode 100644 index 00000000..87fc6e03 --- /dev/null +++ b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs @@ -0,0 +1,32 @@ +use std::hash::Hash; +use tokio::io::BufReader; + +use crate::mc_buf::Readable; + +use super::LoginPacket; + +#[derive(Hash, Clone, Debug)] +pub struct ClientboundLoginCompressionPacket { + pub compression_threshold: i32, +} + +impl ClientboundLoginCompressionPacket { + pub fn get(self) -> LoginPacket { + LoginPacket::ClientboundLoginCompressionPacket(self) + } + + pub fn write(&self, buf: &mut Vec<u8>) { + buf.write_varint(self.compression_threshold).unwrap(); + } + + pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( + buf: &mut BufReader<T>, + ) -> Result<LoginPacket, String> { + let compression_threshold = buf.read_varint().await?; + + Ok(ClientboundLoginCompressionPacket { + compression_threshold + } + .get()) + } +} |
