From 1df4f9f4777ff3453914734d53f249f00897f558 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 11 Nov 2022 19:05:00 -0600 Subject: fix example in azalea_protocol::connect --- azalea-protocol/src/connect.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'azalea-protocol/src') diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index f67d0e4a..a873a4a0 100644 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -11,7 +11,7 @@ use crate::write::write_packet; use azalea_auth::sessionserver::SessionServerError; use azalea_crypto::{Aes128CfbDec, Aes128CfbEnc}; use bytes::BytesMut; -use log::{info, error}; +use log::{error, info}; use std::fmt::Debug; use std::marker::PhantomData; use std::net::SocketAddr; @@ -45,26 +45,28 @@ pub struct WriteConnection { /// Join an offline-mode server and go through the handshake. /// ```rust,no_run /// #[tokio::main] -/// async fn main() -> Result<(), Box> { -/// let resolved_address = resolver::resolve_address(address).await?; +/// async fn main() -> anyhow::Result<()> { +/// let resolved_address = resolver::resolve_address(&"localhost".try_into().unwrap()).await?; /// let mut conn = Connection::new(&resolved_address).await?; /// /// // handshake /// conn.write( /// ClientIntentionPacket { -/// protocol_version: PROTOCOL_VERSION, -/// hostname: address.host.to_string(), -/// port: address.port, -/// intention: ConnectionProtocol::Login, -/// }.get()); -/// +/// protocol_version: PROTOCOL_VERSION, +/// hostname: resolved_address.ip().to_string(), +/// port: resolved_address.port(), +/// intention: ConnectionProtocol::Login, +/// } +/// .get(), +/// ) /// .await?; +/// /// let mut conn = conn.login(); /// /// // login /// conn.write( /// ServerboundHelloPacket { -/// username, +/// username: "bot".to_string(), /// public_key: None, /// profile_id: None, /// } @@ -73,8 +75,8 @@ pub struct WriteConnection { /// .await?; /// /// let (conn, game_profile) = loop { -/// let packet_result = conn.read().await?; -/// Ok(packet) => match packet { +/// let packet = conn.read().await?; +/// match packet { /// ClientboundLoginPacket::Hello(p) => { /// let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap(); /// @@ -96,16 +98,14 @@ pub struct WriteConnection { /// } /// ClientboundLoginPacket::LoginDisconnect(p) => { /// println!("login disconnect: {}", p.reason); -/// bail!(JoinError::Disconnected(p.reason)); +/// bail!("{}", p.reason); /// } /// ClientboundLoginPacket::CustomQuery(p) => {} -/// }, -/// Err(e) => { -/// eprintln!("Error: {:?}", e); -/// bail!("Error: {:?}", e); /// } -/// } -/// }; +/// }; +/// +/// Ok(()) +/// } /// ``` pub struct Connection { pub reader: ReadConnection, -- cgit v1.2.3 From 9e09df18376d58a976cc3dbbf53a48277c428a08 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 11 Nov 2022 19:24:45 -0600 Subject: make some stuff in azalea-protocol public --- azalea-protocol/src/connect.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'azalea-protocol/src') diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index a873a4a0..e903b820 100644 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -23,18 +23,18 @@ use uuid::Uuid; /// The read half of a connection. pub struct ReadConnection { - read_stream: OwnedReadHalf, - buffer: BytesMut, - compression_threshold: Option, - dec_cipher: Option, + pub read_stream: OwnedReadHalf, + pub buffer: BytesMut, + pub compression_threshold: Option, + pub dec_cipher: Option, _reading: PhantomData, } /// The write half of a connection. pub struct WriteConnection { - write_stream: OwnedWriteHalf, - compression_threshold: Option, - enc_cipher: Option, + pub write_stream: OwnedWriteHalf, + pub compression_threshold: Option, + pub enc_cipher: Option, _writing: PhantomData, } -- cgit v1.2.3