aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-12-02 15:48:21 -0600
committermat <git@matdoes.dev>2023-12-02 15:48:21 -0600
commit1903dabe2cece2eab4a595b09636342aed260406 (patch)
tree5cdba0c0bf6a9e632173d92499a5e1e49ce748b0
parentc898fa5921126b111c705e9215ccdd203340119d (diff)
downloadazalea-drasl-1903dabe2cece2eab4a595b09636342aed260406.tar.xz
make address an Arc<RwLock>
-rw-r--r--azalea/src/swarm/mod.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index 2dfdc480..417ca168 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -37,9 +37,10 @@ pub struct Swarm {
bots: Arc<Mutex<HashMap<Entity, Client>>>,
- // bot_datas: Arc<Mutex<Vec<(Client, S)>>>,
- pub resolved_address: SocketAddr,
- pub address: ServerAddress,
+ // the address is public and mutable so plugins can change it
+ pub resolved_address: Arc<RwLock<SocketAddr>>,
+ pub address: Arc<RwLock<ServerAddress>>,
+
pub instance_container: Arc<RwLock<InstanceContainer>>,
bots_tx: mpsc::UnboundedSender<(Option<Event>, Client)>,
@@ -326,8 +327,8 @@ where
ecs_lock: ecs_lock.clone(),
bots: Arc::new(Mutex::new(HashMap::new())),
- resolved_address,
- address,
+ resolved_address: Arc::new(RwLock::new(resolved_address)),
+ address: Arc::new(RwLock::new(address)),
instance_container,
bots_tx,
@@ -524,17 +525,14 @@ impl Swarm {
account: &Account,
state: S,
) -> Result<Client, JoinError> {
- // tx is moved to the bot so it can send us events
- // rx is used to receive events from the bot
- // An event that causes the schedule to run. This is only used internally.
- // let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
- // let ecs_lock = start_ecs_runner(run_schedule_receiver,
- // run_schedule_sender.clone());
+ let address = self.address.read().clone();
+ let resolved_address = self.resolved_address.read().clone();
+
let (bot, mut rx) = Client::start_client(
self.ecs_lock.clone(),
account,
- &self.address,
- &self.resolved_address,
+ &address,
+ &resolved_address,
self.run_schedule_sender.clone(),
)
.await?;