From 08958c2278b15ebeac8a964f392ebb792e479b61 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:31:40 -0600 Subject: Refactor azalea-protocol (#190) * start updating to 1.21.4 * fix block codegen and stop using block data from burger * rename packet related modules and structs to be simpler * ItemSlot -> ItemStack for more consistency with mojmap * .get() -> .into_packet() * simplify declare_state_packets by removing packet ids * rename read_from and write_into to azalea_read and azalea_write * rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite * McBuf -> AzBuf * remove most uses of into_variant * update codegen and use resourcelocation names for packets * implement #[limit(i)] attribute for AzBuf derive macro * fixes for 1.21.4 * fix examples * update some physics code and fix ChatType * remove unused imports in codegen * re-add some things to migrate.py and update +mc version numbers automatically * downgrade to 1.21.3 lol --- azalea-protocol/src/connect.rs | 87 ++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 54 deletions(-) (limited to 'azalea-protocol/src/connect.rs') diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index 0a449bfd..f64d9eb8 100755 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -16,12 +16,10 @@ use tokio::net::TcpStream; use tracing::{error, info}; use uuid::Uuid; -use crate::packets::configuration::{ - ClientboundConfigurationPacket, ServerboundConfigurationPacket, -}; +use crate::packets::config::{ClientboundConfigPacket, ServerboundConfigPacket}; use crate::packets::game::{ClientboundGamePacket, ServerboundGamePacket}; -use crate::packets::handshaking::{ClientboundHandshakePacket, ServerboundHandshakePacket}; -use crate::packets::login::clientbound_hello_packet::ClientboundHelloPacket; +use crate::packets::handshake::{ClientboundHandshakePacket, ServerboundHandshakePacket}; +use crate::packets::login::c_hello::ClientboundHello; use crate::packets::login::{ClientboundLoginPacket, ServerboundLoginPacket}; use crate::packets::status::{ClientboundStatusPacket, ServerboundStatusPacket}; use crate::packets::ProtocolPacket; @@ -66,10 +64,10 @@ pub struct WriteConnection { /// ClientIntention, PROTOCOL_VERSION, /// login::{ /// ClientboundLoginPacket, -/// serverbound_hello_packet::ServerboundHelloPacket, -/// serverbound_key_packet::ServerboundKeyPacket +/// ServerboundHello, +/// ServerboundKey /// }, -/// handshaking::client_intention_packet::ClientIntentionPacket +/// handshake::ServerboundIntention /// } /// }; /// @@ -79,28 +77,20 @@ pub struct WriteConnection { /// let mut conn = Connection::new(&resolved_address).await?; /// /// // handshake -/// conn.write( -/// ClientIntentionPacket { -/// protocol_version: PROTOCOL_VERSION, -/// hostname: resolved_address.ip().to_string(), -/// port: resolved_address.port(), -/// intention: ClientIntention::Login, -/// } -/// .get(), -/// ) -/// .await?; +/// conn.write(ServerboundIntention { +/// protocol_version: PROTOCOL_VERSION, +/// hostname: resolved_address.ip().to_string(), +/// port: resolved_address.port(), +/// intention: ClientIntention::Login, +/// }).await?; /// /// let mut conn = conn.login(); /// /// // login -/// conn.write( -/// ServerboundHelloPacket { -/// name: "bot".to_string(), -/// profile_id: uuid::Uuid::nil(), -/// } -/// .get(), -/// ) -/// .await?; +/// conn.write(ServerboundHello { +/// name: "bot".to_string(), +/// profile_id: uuid::Uuid::nil(), +/// }).await?; /// /// let (conn, game_profile) = loop { /// let packet = conn.read().await?; @@ -108,14 +98,10 @@ pub struct WriteConnection { /// ClientboundLoginPacket::Hello(p) => { /// let e = azalea_crypto::encrypt(&p.public_key, &p.challenge).unwrap(); /// -/// conn.write( -/// ServerboundKeyPacket { -/// key_bytes: e.encrypted_public_key, -/// encrypted_challenge: e.encrypted_challenge, -/// } -/// .get(), -/// ) -/// .await?; +/// conn.write(ServerboundKey { +/// key_bytes: e.encrypted_public_key, +/// encrypted_challenge: e.encrypted_challenge, +/// }).await?; /// conn.set_encryption_key(e.secret_key); /// } /// ClientboundLoginPacket::LoginCompression(p) => { @@ -243,7 +229,8 @@ where } /// Write a packet to the other side of the connection. - pub async fn write(&mut self, packet: W) -> std::io::Result<()> { + pub async fn write(&mut self, packet: impl crate::packets::Packet) -> std::io::Result<()> { + let packet = packet.into_variant(); self.writer.write(packet).await } @@ -368,9 +355,7 @@ impl Connection { /// Change our state from login to configuration. This is the state where /// the server sends us the registries and resource pack and stuff. #[must_use] - pub fn configuration( - self, - ) -> Connection { + pub fn configuration(self) -> Connection { Connection::from(self) } @@ -385,7 +370,7 @@ impl Connection { /// use azalea_protocol::connect::Connection; /// use azalea_protocol::packets::login::{ /// ClientboundLoginPacket, - /// serverbound_key_packet::ServerboundKeyPacket + /// ServerboundKey /// }; /// use uuid::Uuid; /// # use azalea_protocol::ServerAddress; @@ -414,12 +399,10 @@ impl Connection { /// e.secret_key, /// &p /// ).await?; - /// conn.write( - /// ServerboundKeyPacket { - /// key_bytes: e.encrypted_public_key, - /// encrypted_challenge: e.encrypted_challenge, - /// }.get() - /// ).await?; + /// conn.write(ServerboundKey { + /// key_bytes: e.encrypted_public_key, + /// encrypted_challenge: e.encrypted_challenge, + /// }).await?; /// conn.set_encryption_key(e.secret_key); /// } /// _ => {} @@ -432,7 +415,7 @@ impl Connection { access_token: &str, uuid: &Uuid, private_key: [u8; 16], - packet: &ClientboundHelloPacket, + packet: &ClientboundHello, ) -> Result<(), ClientSessionServerError> { azalea_auth::sessionserver::join( access_token, @@ -506,14 +489,12 @@ impl Connection { /// Change our state back to configuration. #[must_use] - pub fn configuration( - self, - ) -> Connection { + pub fn configuration(self) -> Connection { Connection::from(self) } } -impl Connection { +impl Connection { /// Change our state from configuration to game. This is the state that's /// used when the client is actually in the world. #[must_use] @@ -522,7 +503,7 @@ impl Connection } } -impl Connection { +impl Connection { /// Change our state from configuration to game. This is the state that's /// used when the client is actually in the world. #[must_use] @@ -534,9 +515,7 @@ impl Connection impl Connection { /// Change our state back to configuration. #[must_use] - pub fn configuration( - self, - ) -> Connection { + pub fn configuration(self) -> Connection { Connection::from(self) } } -- cgit v1.2.3