From 3f60bdadac1a02e1109148bbbe5a8a3545f13849 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:16:51 -0500 Subject: Move login state to the ECS (#213) * use packet handlers code for login custom_query * initial broken implementation for ecs-only login * fixes * run Update schedule 60 times per second and delete code related to run_schedule_sender * fix tests * fix online-mode * reply to query packets in a separate system and make it easier for plugins to disable individual replies * remove unused imports --- azalea-protocol/src/connect.rs | 5 +++-- azalea-protocol/src/packets/game/s_client_information.rs | 2 +- azalea-protocol/src/packets/login/s_custom_query.rs | 9 --------- azalea-protocol/src/read.rs | 2 ++ azalea-protocol/src/write.rs | 11 ++++++++++- 5 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 azalea-protocol/src/packets/login/s_custom_query.rs (limited to 'azalea-protocol') diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index 13a86ed8..77968eed 100644 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -344,8 +344,9 @@ impl Connection { impl Connection { /// Set our compression threshold, i.e. the maximum size that a packet is - /// allowed to be without getting compressed. If you set it to less than 0 - /// then compression gets disabled. + /// allowed to be without getting compressed. Setting it to 0 means every + /// packet will be compressed. If you set it to less than 0, + /// then compression is disabled. pub fn set_compression_threshold(&mut self, threshold: i32) { // if you pass a threshold of less than 0, compression is disabled if threshold >= 0 { diff --git a/azalea-protocol/src/packets/game/s_client_information.rs b/azalea-protocol/src/packets/game/s_client_information.rs index 5861212c..c8e76f63 100644 --- a/azalea-protocol/src/packets/game/s_client_information.rs +++ b/azalea-protocol/src/packets/game/s_client_information.rs @@ -5,5 +5,5 @@ use crate::common::client_information::ClientInformation; #[derive(Clone, Debug, AzBuf, ServerboundGamePacket)] pub struct ServerboundClientInformation { - pub information: ClientInformation, + pub client_information: ClientInformation, } diff --git a/azalea-protocol/src/packets/login/s_custom_query.rs b/azalea-protocol/src/packets/login/s_custom_query.rs deleted file mode 100644 index 39ecdcef..00000000 --- a/azalea-protocol/src/packets/login/s_custom_query.rs +++ /dev/null @@ -1,9 +0,0 @@ -use azalea_buf::{AzBuf, UnsizedByteArray}; -use azalea_protocol_macros::ServerboundLoginPacket; - -#[derive(Clone, Debug, AzBuf, ServerboundLoginPacket)] -pub struct ServerboundCustomQuery { - #[var] - pub transaction_id: u32, - pub data: Option, -} diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs index 64d35a08..038af319 100644 --- a/azalea-protocol/src/read.rs +++ b/azalea-protocol/src/read.rs @@ -285,6 +285,8 @@ where buffer.get_mut().extend_from_slice(&bytes); } } +/// Read a packet from the stream, then if necessary decrypt it, decompress +/// it, and split it. pub fn try_read_raw_packet( stream: &mut R, buffer: &mut Cursor>, diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index adefc340..dd863f9e 100644 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -54,6 +54,15 @@ pub async fn write_raw_packet( where W: AsyncWrite + Unpin + Send, { + let network_packet = encode_to_network_packet(raw_packet, compression_threshold, cipher); + stream.write_all(&network_packet).await +} + +pub fn encode_to_network_packet( + raw_packet: &[u8], + compression_threshold: Option, + cipher: &mut Option, +) -> Vec { trace!("Writing raw packet: {raw_packet:?}"); let mut raw_packet = raw_packet.to_vec(); if let Some(threshold) = compression_threshold { @@ -64,7 +73,7 @@ where if let Some(cipher) = cipher { azalea_crypto::encrypt_packet(cipher, &mut raw_packet); } - stream.write_all(&raw_packet).await + raw_packet } pub fn compression_encoder( -- cgit v1.2.3