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

Merge branch 'main' of https://github.com/mat-1/azalea into main

This commit is contained in:
Ubuntu 2022-11-12 02:04:15 +00:00
commit 3530faea4e
3 changed files with 30 additions and 27 deletions

View file

@ -1,3 +1,5 @@
//! Translate Minecraft strings from their id.
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::io::Read; use std::io::Read;
use std::path::Path; use std::path::Path;

View file

@ -23,18 +23,18 @@ use uuid::Uuid;
/// The read half of a connection. /// The read half of a connection.
pub struct ReadConnection<R: ProtocolPacket> { pub struct ReadConnection<R: ProtocolPacket> {
read_stream: OwnedReadHalf, pub read_stream: OwnedReadHalf,
buffer: BytesMut, pub buffer: BytesMut,
compression_threshold: Option<u32>, pub compression_threshold: Option<u32>,
dec_cipher: Option<Aes128CfbDec>, pub dec_cipher: Option<Aes128CfbDec>,
_reading: PhantomData<R>, _reading: PhantomData<R>,
} }
/// The write half of a connection. /// The write half of a connection.
pub struct WriteConnection<W: ProtocolPacket> { pub struct WriteConnection<W: ProtocolPacket> {
write_stream: OwnedWriteHalf, pub write_stream: OwnedWriteHalf,
compression_threshold: Option<u32>, pub compression_threshold: Option<u32>,
enc_cipher: Option<Aes128CfbEnc>, pub enc_cipher: Option<Aes128CfbEnc>,
_writing: PhantomData<W>, _writing: PhantomData<W>,
} }
@ -45,26 +45,28 @@ pub struct WriteConnection<W: ProtocolPacket> {
/// Join an offline-mode server and go through the handshake. /// Join an offline-mode server and go through the handshake.
/// ```rust,no_run /// ```rust,no_run
/// #[tokio::main] /// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> { /// async fn main() -> anyhow::Result<()> {
/// let resolved_address = resolver::resolve_address(address).await?; /// let resolved_address = resolver::resolve_address(&"localhost".try_into().unwrap()).await?;
/// let mut conn = Connection::new(&resolved_address).await?; /// let mut conn = Connection::new(&resolved_address).await?;
/// ///
/// // handshake /// // handshake
/// conn.write( /// conn.write(
/// ClientIntentionPacket { /// ClientIntentionPacket {
/// protocol_version: PROTOCOL_VERSION, /// protocol_version: PROTOCOL_VERSION,
/// hostname: address.host.to_string(), /// hostname: resolved_address.ip().to_string(),
/// port: address.port, /// port: resolved_address.port(),
/// intention: ConnectionProtocol::Login, /// intention: ConnectionProtocol::Login,
/// }.get()); /// }
/// /// .get(),
/// )
/// .await?; /// .await?;
///
/// let mut conn = conn.login(); /// let mut conn = conn.login();
/// ///
/// // login /// // login
/// conn.write( /// conn.write(
/// ServerboundHelloPacket { /// ServerboundHelloPacket {
/// username, /// username: "bot".to_string(),
/// public_key: None, /// public_key: None,
/// profile_id: None, /// profile_id: None,
/// } /// }
@ -73,8 +75,8 @@ pub struct WriteConnection<W: ProtocolPacket> {
/// .await?; /// .await?;
/// ///
/// let (conn, game_profile) = loop { /// let (conn, game_profile) = loop {
/// let packet_result = conn.read().await?; /// let packet = conn.read().await?;
/// Ok(packet) => match packet { /// match packet {
/// ClientboundLoginPacket::Hello(p) => { /// ClientboundLoginPacket::Hello(p) => {
/// let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap(); /// let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
/// ///
@ -96,16 +98,14 @@ pub struct WriteConnection<W: ProtocolPacket> {
/// } /// }
/// ClientboundLoginPacket::LoginDisconnect(p) => { /// ClientboundLoginPacket::LoginDisconnect(p) => {
/// println!("login disconnect: {}", p.reason); /// println!("login disconnect: {}", p.reason);
/// bail!(JoinError::Disconnected(p.reason)); /// bail!("{}", p.reason);
/// } /// }
/// ClientboundLoginPacket::CustomQuery(p) => {} /// ClientboundLoginPacket::CustomQuery(p) => {}
/// },
/// Err(e) => {
/// eprintln!("Error: {:?}", e);
/// bail!("Error: {:?}", e);
/// } /// }
/// } /// };
/// }; ///
/// Ok(())
/// }
/// ``` /// ```
pub struct Connection<R: ProtocolPacket, W: ProtocolPacket> { pub struct Connection<R: ProtocolPacket, W: ProtocolPacket> {
pub reader: ReadConnection<R>, pub reader: ReadConnection<R>,

View file

@ -10,9 +10,10 @@
//! First, install Rust nightly with `rustup install nightly` and `rustup //! First, install Rust nightly with `rustup install nightly` and `rustup
//! default nightly`. //! default nightly`.
//! //!
//! Then, add one of the following lines to your Cargo.toml.\ //! Then, add one of the following lines to your Cargo.toml:
//!
//! Latest bleeding-edge version: //! Latest bleeding-edge version:
//! `azalea = { git="https://github.com/mat-1/Cargo.toml" }` //! `azalea = { git="https://github.com/mat-1/Cargo.toml" }`\
//! Latest "stable" release: //! Latest "stable" release:
//! `azalea = "0.3"` //! `azalea = "0.3"`
//! //!