1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

fix example in azalea_protocol::connect

This commit is contained in:
mat 2022-11-11 19:05:00 -06:00
parent dc62ada865
commit 1df4f9f477

View file

@ -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<W: ProtocolPacket> {
/// Join an offline-mode server and go through the handshake.
/// ```rust,no_run
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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<W: ProtocolPacket> {
/// .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<W: ProtocolPacket> {
/// }
/// 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<R: ProtocolPacket, W: ProtocolPacket> {
pub reader: ReadConnection<R>,