1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 23:44:38 +00:00

misc fixes

This commit is contained in:
mat 2022-04-30 02:10:21 -05:00
commit 153b5b45e4
3 changed files with 18 additions and 23 deletions

View file

@ -11,14 +11,7 @@ use azalea_protocol::{
}, },
resolver, ServerAddress, resolver, ServerAddress,
}; };
use std::{ use std::sync::Arc;
borrow::BorrowMut,
cell::RefCell,
future::Future,
pin::Pin,
rc::Rc,
sync::{Arc, Weak},
};
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::sync::Mutex; use tokio::sync::Mutex;
@ -88,8 +81,8 @@ impl Client {
conn.write( conn.write(
ServerboundKeyPacket { ServerboundKeyPacket {
nonce: e.encrypted_nonce.into(), nonce: e.encrypted_nonce,
shared_secret: e.encrypted_public_key.into(), shared_secret: e.encrypted_public_key,
} }
.get(), .get(),
) )
@ -237,6 +230,6 @@ impl Account {
} }
pub async fn join(&self, address: &ServerAddress) -> Result<Client, String> { pub async fn join(&self, address: &ServerAddress) -> Result<Client, String> {
Client::join(&self, address).await Client::join(self, address).await
} }
} }

View file

@ -76,7 +76,7 @@ impl<T: McBufWritable> McBufWritable for BrigadierNumber<T> {
if self.max.is_some() { if self.max.is_some() {
flags |= 0x02; flags |= 0x02;
} }
buf.write_i8(flags); buf.write_byte(flags)?;
if let Some(min) = &self.min { if let Some(min) = &self.min {
min.write_into(buf)?; min.write_into(buf)?;
} }

View file

@ -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 crate::{connect::PacketFlow, mc_buf::Readable, packets::ProtocolPacket};
use async_compression::tokio::bufread::ZlibDecoder; use async_compression::tokio::bufread::ZlibDecoder;
@ -35,13 +39,13 @@ where
{ {
// Packet ID // Packet ID
let packet_id = stream.read_varint().await?; 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 // this is always true in multiplayer, false in singleplayer
static VALIDATE_DECOMPRESSED: bool = true; static VALIDATE_DECOMPRESSED: bool = true;
pub static MAXIMUM_UNCOMPRESSED_LENGTH: u32 = 8388608; pub static MAXIMUM_UNCOMPRESSED_LENGTH: u32 = 2097152;
async fn compression_decoder<R>( async fn compression_decoder<R>(
stream: &mut R, stream: &mut R,
@ -103,28 +107,26 @@ where
impl<R> AsyncRead for EncryptedStream<'_, R> impl<R> AsyncRead for EncryptedStream<'_, R>
where where
R: AsyncRead + std::marker::Unpin + std::marker::Send, R: AsyncRead + Unpin + Send,
{ {
fn poll_read( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>, cx: &mut Context<'_>,
buf: &mut tokio::io::ReadBuf<'_>, buf: &mut tokio::io::ReadBuf<'_>,
) -> std::task::Poll<std::io::Result<()>> { ) -> Poll<std::io::Result<()>> {
// i hate this // i hate this
let polled = self.as_mut().stream.as_mut().poll_read(cx, buf); let polled = self.as_mut().stream.as_mut().poll_read(cx, buf);
match polled { match polled {
std::task::Poll::Ready(r) => { Poll::Ready(r) => {
if let Some(cipher) = self.as_mut().cipher.get_mut() { if let Some(cipher) = self.as_mut().cipher.get_mut() {
azalea_auth::encryption::decrypt_packet(cipher, buf.initialized_mut()); azalea_auth::encryption::decrypt_packet(cipher, buf.initialized_mut());
} }
match r { match r {
Ok(()) => std::task::Poll::Ready(Ok(())), Ok(()) => Poll::Ready(Ok(())),
Err(e) => panic!("{:?}", e), Err(e) => panic!("{:?}", e),
} }
} }
std::task::Poll::Pending => { Poll::Pending => Poll::Pending,
return std::task::Poll::Pending;
}
} }
} }
} }