From 153b5b45e42a031e9ee7dd2764840b07ce1cb47b Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 30 Apr 2022 02:10:21 -0500 Subject: [PATCH] misc fixes --- azalea-client/src/connect.rs | 15 ++++-------- .../clientbound_declare_commands_packet.rs | 2 +- azalea-protocol/src/read.rs | 24 ++++++++++--------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index 2aa25f2d..b0d7dffc 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -11,14 +11,7 @@ use azalea_protocol::{ }, resolver, ServerAddress, }; -use std::{ - borrow::BorrowMut, - cell::RefCell, - future::Future, - pin::Pin, - rc::Rc, - sync::{Arc, Weak}, -}; +use std::sync::Arc; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::Mutex; @@ -88,8 +81,8 @@ impl Client { conn.write( ServerboundKeyPacket { - nonce: e.encrypted_nonce.into(), - shared_secret: e.encrypted_public_key.into(), + nonce: e.encrypted_nonce, + shared_secret: e.encrypted_public_key, } .get(), ) @@ -237,6 +230,6 @@ impl Account { } pub async fn join(&self, address: &ServerAddress) -> Result { - Client::join(&self, address).await + Client::join(self, address).await } } diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs index 33b710d5..afaa7fdd 100755 --- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs @@ -76,7 +76,7 @@ impl McBufWritable for BrigadierNumber { if self.max.is_some() { flags |= 0x02; } - buf.write_i8(flags); + buf.write_byte(flags)?; if let Some(min) = &self.min { min.write_into(buf)?; } diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs index b249e3d7..51224499 100755 --- a/azalea-protocol/src/read.rs +++ b/azalea-protocol/src/read.rs @@ -1,4 +1,8 @@ -use std::{cell::Cell, pin::Pin}; +use std::{ + cell::Cell, + pin::Pin, + task::{Context, Poll}, +}; use crate::{connect::PacketFlow, mc_buf::Readable, packets::ProtocolPacket}; use async_compression::tokio::bufread::ZlibDecoder; @@ -35,13 +39,13 @@ where { // Packet ID let packet_id = stream.read_varint().await?; - Ok(P::read(packet_id.try_into().unwrap(), flow, stream).await?) + P::read(packet_id.try_into().unwrap(), flow, stream).await } // this is always true in multiplayer, false in singleplayer static VALIDATE_DECOMPRESSED: bool = true; -pub static MAXIMUM_UNCOMPRESSED_LENGTH: u32 = 8388608; +pub static MAXIMUM_UNCOMPRESSED_LENGTH: u32 = 2097152; async fn compression_decoder( stream: &mut R, @@ -103,28 +107,26 @@ where impl AsyncRead for EncryptedStream<'_, R> where - R: AsyncRead + std::marker::Unpin + std::marker::Send, + R: AsyncRead + Unpin + Send, { fn poll_read( mut self: Pin<&mut Self>, - cx: &mut std::task::Context<'_>, + cx: &mut Context<'_>, buf: &mut tokio::io::ReadBuf<'_>, - ) -> std::task::Poll> { + ) -> Poll> { // i hate this let polled = self.as_mut().stream.as_mut().poll_read(cx, buf); match polled { - std::task::Poll::Ready(r) => { + Poll::Ready(r) => { if let Some(cipher) = self.as_mut().cipher.get_mut() { azalea_auth::encryption::decrypt_packet(cipher, buf.initialized_mut()); } match r { - Ok(()) => std::task::Poll::Ready(Ok(())), + Ok(()) => Poll::Ready(Ok(())), Err(e) => panic!("{:?}", e), } } - std::task::Poll::Pending => { - return std::task::Poll::Pending; - } + Poll::Pending => Poll::Pending, } } }