mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
improve docs a little more
This commit is contained in:
parent
f73872c0cc
commit
99d3a5de9d
4 changed files with 63 additions and 28 deletions
|
@ -34,7 +34,13 @@ impl Account {
|
||||||
/// a key for the cache, but it's recommended to use the real email to
|
/// a key for the cache, but it's recommended to use the real email to
|
||||||
/// avoid confusion.
|
/// avoid confusion.
|
||||||
pub async fn microsoft(email: &str) -> Result<Self, azalea_auth::AuthError> {
|
pub async fn microsoft(email: &str) -> Result<Self, azalea_auth::AuthError> {
|
||||||
let minecraft_dir = get_mc_dir::minecraft_dir().unwrap();
|
let minecraft_dir = get_mc_dir::minecraft_dir().expect(
|
||||||
|
format!(
|
||||||
|
"No {} environment variable found",
|
||||||
|
get_mc_dir::home_env_var()
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
|
);
|
||||||
let auth_result = azalea_auth::auth(
|
let auth_result = azalea_auth::auth(
|
||||||
email,
|
email,
|
||||||
azalea_auth::AuthOpts {
|
azalea_auth::AuthOpts {
|
||||||
|
|
|
@ -10,25 +10,52 @@ use std::path::PathBuf;
|
||||||
/// Mac: `$HOME/Library/Application Support/minecraft`\
|
/// Mac: `$HOME/Library/Application Support/minecraft`\
|
||||||
/// Linux: `$HOME/.minecraft`
|
/// Linux: `$HOME/.minecraft`
|
||||||
///
|
///
|
||||||
/// Anywhere else it'll return None.
|
/// If the environment variable is not set, this will return `None`.
|
||||||
pub fn minecraft_dir() -> Option<PathBuf> {
|
pub fn minecraft_dir() -> Option<PathBuf> {
|
||||||
|
let env_var = home_env_var();
|
||||||
|
let home = std::env::var(env_var)?;
|
||||||
|
let path = PathBuf::from(home).join(minecraft_dir_relative());
|
||||||
|
Some(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the name of the environment variable that's used for the home folder
|
||||||
|
/// on the user's operating system.
|
||||||
|
pub fn home_env_var() -> &'static str {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
let appdata = std::env::var("APPDATA").ok()?;
|
"USERPROFILE"
|
||||||
Some(PathBuf::from(appdata).join(".minecraft"))
|
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
let home = std::env::var("HOME").ok()?;
|
"HOME"
|
||||||
Some(PathBuf::from(home).join("Library/Application Support/minecraft"))
|
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
let home = std::env::var("HOME").ok()?;
|
"HOME"
|
||||||
Some(PathBuf::from(home).join(".minecraft"))
|
|
||||||
}
|
}
|
||||||
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
|
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
|
||||||
{
|
{
|
||||||
None
|
"HOME"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the path relative to the home folder where we expect to find the
|
||||||
|
/// .minecraft directory.
|
||||||
|
pub fn minecraft_dir_relative() -> &'static str {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
".minecraft"
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
"Library/Application Support/minecraft"
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
".minecraft"
|
||||||
|
}
|
||||||
|
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
|
||||||
|
{
|
||||||
|
".minecraft"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,26 +55,24 @@ pub struct WriteConnection<W: ProtocolPacket> {
|
||||||
/// hostname: address.host.to_string(),
|
/// hostname: address.host.to_string(),
|
||||||
/// port: address.port,
|
/// port: address.port,
|
||||||
/// intention: ConnectionProtocol::Login,
|
/// intention: ConnectionProtocol::Login,
|
||||||
/// }
|
/// }.get());
|
||||||
/// .get(),
|
|
||||||
/// )
|
|
||||||
/// .await?;
|
|
||||||
/// let mut conn = conn.login();
|
|
||||||
///
|
///
|
||||||
/// // login
|
/// .await?;
|
||||||
/// conn.write(
|
/// let mut conn = conn.login();
|
||||||
/// ServerboundHelloPacket {
|
|
||||||
/// username,
|
|
||||||
/// public_key: None,
|
|
||||||
/// profile_id: None,
|
|
||||||
/// }
|
|
||||||
/// .get(),
|
|
||||||
/// )
|
|
||||||
/// .await?;
|
|
||||||
///
|
///
|
||||||
/// let (conn, game_profile) = loop {
|
/// // login
|
||||||
/// let packet_result = conn.read().await;
|
/// conn.write(
|
||||||
/// match packet_result {
|
/// ServerboundHelloPacket {
|
||||||
|
/// username,
|
||||||
|
/// public_key: None,
|
||||||
|
/// profile_id: None,
|
||||||
|
/// }
|
||||||
|
/// .get(),
|
||||||
|
/// )
|
||||||
|
/// .await?;
|
||||||
|
///
|
||||||
|
/// let (conn, game_profile) = loop {
|
||||||
|
/// let packet_result = conn.read().await?;
|
||||||
/// Ok(packet) => match packet {
|
/// Ok(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();
|
||||||
|
@ -87,7 +85,8 @@ pub struct WriteConnection<W: ProtocolPacket> {
|
||||||
/// .get(),
|
/// .get(),
|
||||||
/// )
|
/// )
|
||||||
/// .await?;
|
/// .await?;
|
||||||
/// conn.set_encryption_key(e.secret_key); }
|
/// conn.set_encryption_key(e.secret_key);
|
||||||
|
/// }
|
||||||
/// ClientboundLoginPacket::LoginCompression(p) => {
|
/// ClientboundLoginPacket::LoginCompression(p) => {
|
||||||
/// conn.set_compression_threshold(p.compression_threshold);
|
/// conn.set_compression_threshold(p.compression_threshold);
|
||||||
/// }
|
/// }
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
//! You should probably use [`azalea`] or [`azalea_client`] instead, as
|
//! You should probably use [`azalea`] or [`azalea_client`] instead, as
|
||||||
//! azalea_protocol delegates much of the work, such as auth, to the user of
|
//! azalea_protocol delegates much of the work, such as auth, to the user of
|
||||||
//! the crate.
|
//! the crate.
|
||||||
|
//!
|
||||||
|
//! [`azalea`]: https://crates.io/crates/azalea
|
||||||
|
//! [`azalea_client`]: https://crates.io/crates/azalea-client
|
||||||
|
|
||||||
// these two are necessary for thiserror backtraces
|
// these two are necessary for thiserror backtraces
|
||||||
#![feature(error_generic_member_access)]
|
#![feature(error_generic_member_access)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue