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

fix all the tests

except the examples i don't know how to exclude them from the tests
This commit is contained in:
mat 2022-11-27 15:48:47 -06:00
parent 2f1483f483
commit 0fed648359
5 changed files with 91 additions and 39 deletions

View file

@ -209,6 +209,7 @@ pub struct GameOwnershipItem {
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct ProfileResponse {
// todo: make the id a uuid
pub id: String,
pub name: String,
pub skins: Vec<serde_json::Value>,
@ -463,7 +464,7 @@ pub enum GetProfileError {
Http(#[from] reqwest::Error),
}
async fn get_profile(
pub async fn get_profile(
client: &reqwest::Client,
minecraft_access_token: &str,
) -> Result<ProfileResponse, GetProfileError> {

View file

@ -127,25 +127,8 @@ impl Client {
/// Send a message in chat.
///
/// ```rust,no_run
/// # use azalea::prelude::*;
/// # use parking_lot::Mutex;
/// # use std::sync::Arc;
/// # #[tokio::main]
/// # async fn main() {
/// # let account = Account::offline("bot");
/// # azalea::start(azalea::Options {
/// # account,
/// # address: "localhost",
/// # state: State::default(),
/// # plugins: plugins![],
/// # handle,
/// # })
/// # .await
/// # .unwrap();
/// # }
/// # #[derive(Default, Clone)]
/// # pub struct State {}
/// # async fn handle(bot: Client, event: Event, state: State) -> anyhow::Result<()> {
/// # use azalea_client::{Client, Event};
/// # async fn handle(bot: Client, event: Event) -> anyhow::Result<()> {
/// bot.chat("Hello, world!").await.unwrap();
/// # Ok(())
/// # }

View file

@ -214,14 +214,15 @@ impl Client {
/// # Examples
///
/// ```rust,no_run
/// use azalea_client::Client;
/// use azalea_client::{Client, Account};
///
/// #[tokio::main]
/// async fn main() -> Box<dyn std::error::Error> {
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let account = Account::offline("bot");
/// let (client, rx) = Client::join(&account, "localhost").await?;
/// client.chat("Hello, world!").await?;
/// client.shutdown().await?;
/// client.disconnect().await?;
/// Ok(())
/// }
/// ```
pub async fn join(
@ -1113,11 +1114,15 @@ impl Client {
/// If this is not set before the login packet, the default will be sent.
///
/// ```rust,no_run
/// # use azalea_client::{Client, ClientInformation};
/// # async fn example(bot: Client) -> Result<(), Box<dyn std::error::Error>> {
/// bot.set_client_information(ClientInformation {
/// view_distance: 2,
/// ..Default::default()
/// })
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn set_client_information(
&self,

View file

@ -263,8 +263,17 @@ impl Client {
/// [`Client::sprint`]. To stop walking, call walk with
/// `WalkDirection::None`.
///
/// # Examples
///
/// Walk for 1 second
/// ```rust,no_run
/// # use azalea_client::{Client, WalkDirection};
/// # use std::time::Duration;
/// # async fn example(mut bot: Client) {
/// bot.walk(WalkDirection::Forward);
/// tokio::time::sleep(Duration::from_secs(1)).await;
/// bot.walk(WalkDirection::None);
/// # }
/// ```
pub fn walk(&mut self, direction: WalkDirection) {
{
@ -277,6 +286,19 @@ impl Client {
/// Start sprinting in the given direction. To stop moving, call
/// [`Client::walk(WalkDirection::None)`]
///
/// # Examples
///
/// Sprint for 1 second
/// ```rust,no_run
/// # use azalea_client::{Client, WalkDirection, SprintDirection};
/// # use std::time::Duration;
/// # async fn example(mut bot: Client) {
/// bot.sprint(SprintDirection::Forward);
/// tokio::time::sleep(Duration::from_secs(1)).await;
/// bot.walk(WalkDirection::None);
/// # }
/// ```
pub fn sprint(&mut self, direction: SprintDirection) {
let mut physics_state = self.physics_state.lock();
physics_state.move_direction = WalkDirection::from(direction);

View file

@ -44,8 +44,22 @@ pub struct WriteConnection<W: ProtocolPacket> {
///
/// Join an offline-mode server and go through the handshake.
/// ```rust,no_run
/// use azalea_protocol::{
/// resolver,
/// connect::Connection,
/// packets::{
/// ConnectionProtocol, PROTOCOL_VERSION,
/// login::{
/// ClientboundLoginPacket,
/// serverbound_hello_packet::ServerboundHelloPacket,
/// serverbound_key_packet::{ServerboundKeyPacket, NonceOrSaltSignature}
/// },
/// handshake::client_intention_packet::ClientIntentionPacket
/// }
/// };
///
/// #[tokio::main]
/// async fn main() -> anyhow::Result<()> {
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let resolved_address = resolver::resolve_address(&"localhost".try_into().unwrap()).await?;
/// let mut conn = Connection::new(&resolved_address).await?;
///
@ -97,8 +111,8 @@ pub struct WriteConnection<W: ProtocolPacket> {
/// break (conn.game(), p.game_profile);
/// }
/// ClientboundLoginPacket::LoginDisconnect(p) => {
/// println!("login disconnect: {}", p.reason);
/// bail!("{}", p.reason);
/// eprintln!("login disconnect: {}", p.reason);
/// return Err("login disconnect".into());
/// }
/// ClientboundLoginPacket::CustomQuery(p) => {}
/// }
@ -258,24 +272,51 @@ impl Connection<ClientboundLoginPacket, ServerboundLoginPacket> {
/// # Examples
///
/// ```rust,no_run
/// let token = azalea_auth::auth(azalea_auth::AuthOpts {
/// ..Default::default()
/// })
/// .await;
/// let player_data = azalea_auth::get_profile(token).await;
/// use azalea_auth::AuthResult;
/// use azalea_protocol::connect::Connection;
/// use azalea_protocol::packets::login::{
/// ClientboundLoginPacket,
/// serverbound_key_packet::{ServerboundKeyPacket, NonceOrSaltSignature}
/// };
/// use uuid::Uuid;
/// # use azalea_protocol::ServerAddress;
///
/// let mut connection = azalea::Connection::new(&server_address).await?;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let AuthResult { access_token, profile } = azalea_auth::auth(
/// "example@example.com",
/// azalea_auth::AuthOpts::default()
/// ).await.expect("Couldn't authenticate");
/// #
/// # let address = ServerAddress::try_from("example@example.com").unwrap();
/// # let resolved_address = azalea_protocol::resolver::resolve_address(&address).await?;
///
/// let mut conn = Connection::new(&resolved_address).await?;
///
/// // transition to the login state, in a real program we would have done a handshake first
/// connection.login();
/// let mut conn = conn.login();
///
/// match connection.read().await? {
/// ClientboundLoginPacket::Hello(p) => {
/// // tell Mojang we're joining the server
/// connection.authenticate(&token, player_data.uuid, p).await?;
/// }
/// _ => {}
/// match conn.read().await? {
/// ClientboundLoginPacket::Hello(p) => {
/// // tell Mojang we're joining the server & enable encryption
/// let e = azalea_crypto::encrypt(&p.public_key, &p.nonce).unwrap();
/// conn.authenticate(
/// &access_token,
/// &Uuid::parse_str(&profile.id).expect("Invalid UUID"),
/// e.secret_key,
/// p
/// ).await?;
/// conn.write(
/// ServerboundKeyPacket {
/// nonce_or_salt_signature: NonceOrSaltSignature::Nonce(e.encrypted_nonce),
/// key_bytes: e.encrypted_public_key,
/// }.get()
/// ).await?;
/// conn.set_encryption_key(e.secret_key);
/// }
/// _ => {}
/// }
/// # Ok(())
/// # }
/// ```
pub async fn authenticate(
&self,