aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/swarm
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-04-09 07:15:30 +0000
committermat <git@matdoes.dev>2024-04-09 07:15:33 +0000
commitb66b5b6b9042c3817ebb6d426c5ecd523b271c32 (patch)
treee975035ef35c3fa4b18fe957ebe491eccc61c3e5 /azalea/src/swarm
parentcadc5605ec143d391382a77a431b55b44f5c5153 (diff)
downloadazalea-drasl-b66b5b6b9042c3817ebb6d426c5ecd523b271c32.tar.xz
add functions to ClientBuilder and SwarmBuilder for custom addresses
Diffstat (limited to 'azalea/src/swarm')
-rw-r--r--azalea/src/swarm/mod.rs42
1 files changed, 39 insertions, 3 deletions
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index 6d3885ef..2be56567 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -296,6 +296,28 @@ where
///
/// [`ServerAddress`]: azalea_protocol::ServerAddress
pub async fn start(self, address: impl TryInto<ServerAddress>) -> Result<!, StartError> {
+ // convert the TryInto<ServerAddress> into a ServerAddress
+ let address: ServerAddress = match address.try_into() {
+ Ok(address) => address,
+ Err(_) => return Err(StartError::InvalidAddress),
+ };
+
+ // resolve the address
+ let resolved_address = resolver::resolve_address(&address).await?;
+
+ self.start_with_custom_resolved_address(address, resolved_address)
+ .await
+ }
+
+ /// Do the same as [`Self::start`], but allow passing in a custom resolved
+ /// address. This is useful if the address you're connecting to doesn't
+ /// resolve to anything, like if the server uses the address field to pass
+ /// custom data (like Bungeecord or Forge).
+ pub async fn start_with_custom_resolved_address(
+ self,
+ address: impl TryInto<ServerAddress>,
+ resolved_address: SocketAddr,
+ ) -> Result<!, StartError> {
assert_eq!(
self.accounts.len(),
self.states.len(),
@@ -308,9 +330,6 @@ where
Err(_) => return Err(StartError::InvalidAddress),
};
- // resolve the address
- let resolved_address = resolver::resolve_address(&address).await?;
-
let instance_container = Arc::new(RwLock::new(InstanceContainer::default()));
// we can't modify the swarm plugins after this
@@ -528,6 +547,23 @@ impl Swarm {
let address = self.address.read().clone();
let resolved_address = *self.resolved_address.read();
+ self.add_with_custom_address(account, state, address, resolved_address)
+ .await
+ }
+ /// Add a new account to the swarm, using the given host and socket
+ /// address. This is useful if you want bots in the same swarm to connect to
+ /// different addresses. Usually you'll just want [`Self::add`] though.
+ ///
+ /// # Errors
+ ///
+ /// Returns an `Err` if the bot could not do a handshake successfully.
+ pub async fn add_with_custom_address<S: Component + Clone>(
+ &mut self,
+ account: &Account,
+ state: S,
+ address: ServerAddress,
+ resolved_address: SocketAddr,
+ ) -> Result<Client, JoinError> {
let (bot, mut rx) = Client::start_client(
self.ecs_lock.clone(),
account,