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

merge main

This commit is contained in:
Ubuntu 2023-01-18 17:56:09 +00:00
commit a971a30fd1
11 changed files with 52 additions and 38 deletions

4
Cargo.lock generated
View file

@ -2475,9 +2475,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "typemap_rev"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fc45e9608894c9fefd9792d880560280086d73a4d8c8cb7436f27ca98550fb5"
checksum = "74b08b0c1257381af16a5c3605254d529d3e7e109f3c62befc5d168968192998"
[[package]]
name = "typenum"

4
azalea-auth/Cargo.toml Executable file → Normal file
View file

@ -18,9 +18,9 @@ reqwest = {version = "0.11.12", features = ["json"]}
serde = {version = "1.0.145", features = ["derive"]}
serde_json = "1.0.86"
thiserror = "1.0.37"
tokio = {version = "1.21.2", features = ["fs"]}
tokio = {version = "1.23.1", features = ["fs"]}
uuid = "^1.1.2"
[dev-dependencies]
env_logger = "0.9.1"
tokio = {version = "1.21.2", features = ["full"]}
tokio = {version = "1.23.1", features = ["full"]}

View file

@ -14,7 +14,7 @@ byteorder = "^1.4.3"
log = "0.4.17"
serde_json = {version = "^1.0", optional = true}
thiserror = "1.0.37"
tokio = {version = "^1.21.2", features = ["io-util", "net", "macros"]}
tokio = {version = "^1.23.1", features = ["io-util", "net", "macros"]}
uuid = "^1.1.2"
[features]

View file

@ -32,8 +32,8 @@ once_cell = "1.16.0"
parking_lot = {version = "^0.12.1", features = ["deadlock_detection"]}
regex = "1.7.0"
thiserror = "^1.0.34"
tokio = {version = "^1.21.2", features = ["sync"]}
typemap_rev = "0.2.0"
tokio = {version = "^1.23.1", features = ["sync"]}
typemap_rev = "0.3.0"
uuid = "^1.1.2"
[dev-dependencies]

View file

@ -11,6 +11,7 @@ use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use uuid::Uuid;
use crate::client::Client;
@ -73,6 +74,15 @@ impl ChatPacket {
self.split_sender_and_content().0
}
/// Get the UUID of the sender of the message. If it's not a
/// player-sent chat message, this will be None.
pub fn uuid(&self) -> Option<Uuid> {
match self {
ChatPacket::System(_) => return None,
ChatPacket::Player(m) => return Some(m.sender),
}
}
/// Get the content part of the message as a string. This does not preserve
/// formatting codes. If it's not a player-sent chat message or the sender
/// couldn't be determined, this will contain the entire message.

View file

@ -10,6 +10,7 @@ use crate::{
};
use azalea_auth::{game_profile::GameProfile, sessionserver::SessionServerError};
use azalea_chat::FormattedText;
use azalea_physics::PhysicsPlugin;
use azalea_protocol::{
connect::{Connection, ConnectionError},
@ -127,6 +128,8 @@ pub enum JoinError {
InvalidAddress,
#[error("Couldn't refresh access token: {0}")]
Auth(#[from] azalea_auth::AuthError),
#[error("Disconnected: {reason}")]
Disconnect { reason: FormattedText },
}
impl Client {
@ -368,6 +371,7 @@ impl Client {
}
ClientboundLoginPacket::LoginDisconnect(p) => {
debug!("Got disconnect {:?}", p);
return Err(JoinError::Disconnect { reason: p.reason });
}
ClientboundLoginPacket::CustomQuery(p) => {
debug!("Got custom query {:?}", p);

View file

@ -14,37 +14,37 @@ impl Client {
.expect("Our client is missing a required component.")
}
/// Return a lightweight [`Entity`] for the entity that matches the given
/// predicate function.
///
/// You can then use [`Self::map_entity`] to get components from this
/// entity.
pub fn entity_by<'a, F: ReadOnlyWorldQuery, Q: ReadOnlyWorldQuery>(
&mut self,
mut predicate: impl EntityPredicate<'a, Q>,
) -> Option<Entity> {
let mut ecs = self.ecs.lock();
let mut query = ecs.query_filtered::<(Entity, Q), F>();
let entity = query
.iter_mut(&mut ecs)
.find(|(_, q)| predicate.matches(q))
.map(|(entity, _)| entity);
entity
}
// /// Return a lightweight [`Entity`] for the entity that matches the given
// /// predicate function.
// ///
// /// You can then use [`Self::map_entity`] to get components from this
// /// entity.
// pub fn entity_by<'a, F: ReadOnlyWorldQuery, Q: ReadOnlyWorldQuery>(
// &mut self,
// mut predicate: impl EntityPredicate<'a, Q>,
// ) -> Option<Entity> {
// let mut ecs = self.ecs.lock();
// let mut query = ecs.query_filtered::<(Entity, Q), F>();
// let entity = query
// .iter_mut(&mut ecs)
// .find(|(_, q)| predicate.matches(q))
// .map(|(entity, _)| entity);
// entity
// }
}
pub trait EntityPredicate<'a, Q: ReadOnlyWorldQuery> {
fn matches(&self, components: &<Q as WorldQuery>::Item<'a>) -> bool;
}
impl<'a, F, Q> EntityPredicate<'a, Q> for F
where
F: Fn(Q) -> bool,
Q: ReadOnlyWorldQuery,
{
fn matches(&self, query: &<Q as WorldQuery>::Item<'a>) -> bool {
(self)(query)
}
}
// impl<'a, F, Q> EntityPredicate<'a, Q> for F
// where
// F: Fn(Q) -> bool,
// Q: ReadOnlyWorldQuery,
// {
// fn matches(&self, query: &<Q as WorldQuery>::Item<'a>) -> bool {
// (self)(query)
// }
// }
// impl<'a, F, Q1, Q2> EntityPredicate<'a, (Q1, Q2)> for F
// where
// F: Fn(Q1, Q2) -> bool,

2
azalea-protocol/Cargo.toml Executable file → Normal file
View file

@ -32,7 +32,7 @@ log = "0.4.17"
serde = {version = "1.0.130", features = ["serde_derive"]}
serde_json = "^1.0.72"
thiserror = "1.0.37"
tokio = {version = "^1.21.2", features = ["io-util", "net", "macros"]}
tokio = {version = "^1.23.1", features = ["io-util", "net", "macros"]}
tokio-util = {version = "0.7.4", features = ["codec"]}
trust-dns-resolver = {version = "^0.22.0", default-features = false, features = ["tokio-runtime"]}
uuid = "1.1.2"

View file

@ -29,7 +29,7 @@ num-traits = "0.2.15"
parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] }
priority-queue = "1.3.0"
thiserror = "^1.0.37"
tokio = "^1.21.2"
tokio = "^1.23.1"
uuid = "1.2.2"
bevy_app = { version = "0.9.1", default-features = false }
bevy_ecs = { version = "0.9.1", default-features = false }
@ -38,4 +38,4 @@ iyes_loopless = "0.9.1"
[dev-dependencies]
anyhow = "^1.0.65"
env_logger = "^0.9.1"
tokio = "^1.21.2"
tokio = "^1.23.1"

View file

@ -13,7 +13,7 @@
//! Then, add one of the following lines to your Cargo.toml:
//!
//! Latest bleeding-edge version:
//! `azalea = { git="https://github.com/mat-1/Cargo.toml" }`\
//! `azalea = { git="https://github.com/mat-1/azalea" }`\
//! Latest "stable" release:
//! `azalea = "0.5.0"`
//!

View file

@ -14,5 +14,5 @@ azalea-protocol = {path = "../azalea-protocol"}
env_logger = "0.9.1"
parking_lot = {version = "^0.12.1", features = ["deadlock_detection"]}
rand = "0.8.5"
tokio = "1.19.2"
tokio = "1.23.1"
uuid = "1.1.2"