aboutsummaryrefslogtreecommitdiff
path: root/azalea-client
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-12-12 01:29:49 -0600
committerGitHub <noreply@github.com>2025-12-12 01:29:49 -0600
commitf4a3c53eee7d29bade0c074f402c4a45aa98eca8 (patch)
treef25ec1d1390c5e96aba858141206a05812135b95 /azalea-client
parent7f761df3e7b72ce75be21ab9b3a533d0a5a938a5 (diff)
downloadazalea-drasl-f4a3c53eee7d29bade0c074f402c4a45aa98eca8.tar.xz
Delete `StartError` and `JoinError` (#296)
* delete StartError and JoinError * update changelog
Diffstat (limited to 'azalea-client')
-rw-r--r--azalea-client/src/client.rs47
-rw-r--r--azalea-client/src/lib.rs4
-rw-r--r--azalea-client/src/ping.rs24
-rw-r--r--azalea-client/src/plugins/join.rs23
4 files changed, 34 insertions, 64 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index aa2da1d5..579f5d26 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -2,7 +2,6 @@ use std::{
collections::HashMap,
fmt::Debug,
mem,
- net::SocketAddr,
sync::Arc,
thread,
time::{Duration, Instant},
@@ -23,10 +22,10 @@ use azalea_entity::{
};
use azalea_physics::local_player::PhysicsState;
use azalea_protocol::{
- ServerAddress,
+ address::{ResolvableAddr, ResolvedAddr},
connect::Proxy,
packets::{Packet, game::ServerboundGamePacket},
- resolve,
+ resolve::ResolveError,
};
use azalea_registry::{DataRegistryKeyRef, identifier::Identifier};
use azalea_world::{Instance, InstanceContainer, InstanceName, MinecraftEntityId, PartialInstance};
@@ -37,7 +36,6 @@ use bevy_ecs::{
schedule::{InternedScheduleLabel, LogLevel, ScheduleBuildSettings},
};
use parking_lot::{Mutex, RwLock};
-use thiserror::Error;
use tokio::{
sync::{
mpsc::{self},
@@ -87,15 +85,6 @@ pub struct Client {
pub ecs: Arc<Mutex<World>>,
}
-/// An error that happened while joining the server.
-#[derive(Error, Debug)]
-pub enum JoinError {
- #[error(transparent)]
- Resolver(#[from] resolve::ResolveError),
- #[error("The given address could not be parsed into a ServerAddress")]
- InvalidAddress,
-}
-
pub struct StartClientOpts {
pub ecs_lock: Arc<Mutex<World>>,
pub account: Account,
@@ -106,8 +95,7 @@ pub struct StartClientOpts {
impl StartClientOpts {
pub fn new(
account: Account,
- address: ServerAddress,
- resolved_address: SocketAddr,
+ address: ResolvedAddr,
event_sender: Option<mpsc::UnboundedSender<Event>>,
) -> StartClientOpts {
let mut app = App::new();
@@ -123,7 +111,6 @@ impl StartClientOpts {
account,
connect_opts: ConnectOpts {
address,
- resolved_address,
server_proxy: None,
sessionserver_proxy: None,
},
@@ -197,35 +184,25 @@ impl Client {
/// ```
pub async fn join(
account: Account,
- address: impl TryInto<ServerAddress>,
- ) -> Result<(Self, mpsc::UnboundedReceiver<Event>), JoinError> {
- let address: ServerAddress = address.try_into().map_err(|_| JoinError::InvalidAddress)?;
- let resolved_address = resolve::resolve_address(&address).await?;
+ address: impl ResolvableAddr,
+ ) -> Result<(Self, mpsc::UnboundedReceiver<Event>), ResolveError> {
+ let address = address.resolve().await?;
let (tx, rx) = mpsc::unbounded_channel();
- let client = Self::start_client(StartClientOpts::new(
- account,
- address,
- resolved_address,
- Some(tx),
- ))
- .await;
+ let client = Self::start_client(StartClientOpts::new(account, address, Some(tx))).await;
Ok((client, rx))
}
pub async fn join_with_proxy(
account: Account,
- address: impl TryInto<ServerAddress>,
+ address: impl ResolvableAddr,
proxy: Proxy,
- ) -> Result<(Self, mpsc::UnboundedReceiver<Event>), JoinError> {
- let address: ServerAddress = address.try_into().map_err(|_| JoinError::InvalidAddress)?;
- let resolved_address = resolve::resolve_address(&address).await?;
+ ) -> Result<(Self, mpsc::UnboundedReceiver<Event>), ResolveError> {
+ let address = address.resolve().await?;
let (tx, rx) = mpsc::unbounded_channel();
- let client = Self::start_client(
- StartClientOpts::new(account, address, resolved_address, Some(tx)).proxy(proxy),
- )
- .await;
+ let client =
+ Self::start_client(StartClientOpts::new(account, address, Some(tx)).proxy(proxy)).await;
Ok((client, rx))
}
diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs
index c818d96a..6d216b2b 100644
--- a/azalea-client/src/lib.rs
+++ b/azalea-client/src/lib.rs
@@ -27,8 +27,8 @@ pub use azalea_protocol::common::client_information::ClientInformation;
// version.
pub use bevy_tasks;
pub use client::{
- Client, InConfigState, InGameState, JoinError, JoinedClientBundle, LocalPlayerBundle,
- StartClientOpts, start_ecs_runner,
+ Client, InConfigState, InGameState, JoinedClientBundle, LocalPlayerBundle, StartClientOpts,
+ start_ecs_runner,
};
pub use events::Event;
pub use movement::{StartSprintEvent, StartWalkEvent};
diff --git a/azalea-client/src/ping.rs b/azalea-client/src/ping.rs
index 2c3ddfcf..08f909e4 100644
--- a/azalea-client/src/ping.rs
+++ b/azalea-client/src/ping.rs
@@ -3,7 +3,7 @@
use std::io;
use azalea_protocol::{
- ServerAddress,
+ address::{ResolvableAddr, ServerAddr},
connect::{Connection, ConnectionError, Proxy},
packets::{
ClientIntention, PROTOCOL_VERSION,
@@ -23,7 +23,7 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub enum PingError {
#[error("{0}")]
- Resolver(#[from] resolve::ResolveError),
+ Resolve(#[from] resolve::ResolveError),
#[error("{0}")]
Connection(#[from] ConnectionError),
#[error("{0}")]
@@ -48,23 +48,21 @@ pub enum PingError {
/// }
/// ```
pub async fn ping_server(
- address: impl TryInto<ServerAddress>,
+ address: impl ResolvableAddr,
) -> Result<ClientboundStatusResponse, PingError> {
- let address: ServerAddress = address.try_into().map_err(|_| PingError::InvalidAddress)?;
- let resolved_address = resolve::resolve_address(&address).await?;
- let conn = Connection::new(&resolved_address).await?;
- ping_server_with_connection(address, conn).await
+ let address = address.resolve().await?;
+ let conn = Connection::new(&address.socket).await?;
+ ping_server_with_connection(address.server, conn).await
}
/// Ping a Minecraft server through a SOCKS5 proxy.
pub async fn ping_server_with_proxy(
- address: impl TryInto<ServerAddress>,
+ address: impl ResolvableAddr,
proxy: Proxy,
) -> Result<ClientboundStatusResponse, PingError> {
- let address: ServerAddress = address.try_into().map_err(|_| PingError::InvalidAddress)?;
- let resolved_address = resolve::resolve_address(&address).await?;
- let conn = Connection::new_with_proxy(&resolved_address, proxy).await?;
- ping_server_with_connection(address, conn).await
+ let address = address.resolve().await?;
+ let conn = Connection::new_with_proxy(&address.socket, proxy).await?;
+ ping_server_with_connection(address.server, conn).await
}
/// Ping a Minecraft server after we've already created a [`Connection`].
@@ -72,7 +70,7 @@ pub async fn ping_server_with_proxy(
/// The `Connection` must still be in the handshake state (which is the state
/// it's in immediately after it's created).
pub async fn ping_server_with_connection(
- address: ServerAddress,
+ address: ServerAddr,
mut conn: Connection<ClientboundHandshakePacket, ServerboundHandshakePacket>,
) -> Result<ClientboundStatusResponse, PingError> {
// send the client intention packet and switch to the status state
diff --git a/azalea-client/src/plugins/join.rs b/azalea-client/src/plugins/join.rs
index 538369b0..f1e27165 100644
--- a/azalea-client/src/plugins/join.rs
+++ b/azalea-client/src/plugins/join.rs
@@ -1,8 +1,8 @@
-use std::{net::SocketAddr, sync::Arc};
+use std::sync::Arc;
use azalea_entity::{LocalEntity, indexing::EntityUuidIndex};
use azalea_protocol::{
- ServerAddress,
+ address::ResolvedAddr,
common::client_information::ClientInformation,
connect::{Connection, ConnectionError, Proxy},
packets::{
@@ -59,16 +59,11 @@ pub struct StartJoinServerEvent {
/// Options for how the connection to the server will be made.
///
-/// These are persisted on reconnects.
-///
-/// This is inserted as a component on clients to make auto-reconnecting work.
+/// These are persisted on reconnects. This is inserted as a component on
+/// clients to make auto-reconnecting work.
#[derive(Debug, Clone, Component)]
pub struct ConnectOpts {
- /// The unresolved address that we're going to tell the server that we used
- /// to connect.
- pub address: ServerAddress,
- /// The actual IP and port that we're going to make a connection to.
- pub resolved_address: SocketAddr,
+ pub address: ResolvedAddr,
/// The SOCKS5 proxy used for connecting to the Minecraft server.
pub server_proxy: Option<Proxy>,
/// The SOCKS5 proxy that will be used when authenticating our server join
@@ -172,15 +167,15 @@ async fn create_conn_and_send_intention_packet(
opts: ConnectOpts,
) -> Result<LoginConn, ConnectionError> {
let mut conn = if let Some(proxy) = opts.server_proxy {
- Connection::new_with_proxy(&opts.resolved_address, proxy).await?
+ Connection::new_with_proxy(&opts.address.socket, proxy).await?
} else {
- Connection::new(&opts.resolved_address).await?
+ Connection::new(&opts.address.socket).await?
};
conn.write(ServerboundIntention {
protocol_version: PROTOCOL_VERSION,
- hostname: opts.address.host.clone(),
- port: opts.address.port,
+ hostname: opts.address.server.host.clone(),
+ port: opts.address.server.port,
intention: ClientIntention::Login,
})
.await?;