aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/local_player.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2023-02-21 21:53:22 -0600
committermat <github@matdoes.dev>2023-02-21 21:53:22 -0600
commit48640ca303784a3761dabc7436cd96ac93db279b (patch)
tree0cbab5af69aa205f1f580e2eaec12fd8c4ec5f66 /azalea-client/src/local_player.rs
parent66094921c88e80187a712dca39e421a648d69198 (diff)
downloadazalea-drasl-48640ca303784a3761dabc7436cd96ac93db279b.tar.xz
properly disconnect on ungraceful disconnect
Diffstat (limited to 'azalea-client/src/local_player.rs')
-rw-r--r--azalea-client/src/local_player.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index 8298cf0a..d31f840f 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -46,9 +46,11 @@ pub struct LocalPlayer {
/// world. (Only relevant if you're using a shared world, i.e. a swarm)
pub world: Arc<RwLock<World>>,
- /// A list of async tasks that are running and will stop running when this
- /// LocalPlayer is dropped or disconnected with [`Self::disconnect`]
- pub(crate) tasks: Vec<JoinHandle<()>>,
+ /// A task that reads packets from the server. The client is disconnected
+ /// when this task ends.
+ pub(crate) read_packets_task: JoinHandle<()>,
+ /// A task that writes packets from the server.
+ pub(crate) write_packets_task: JoinHandle<()>,
}
/// Component for entities that can move and sprint. Usually only in
@@ -87,6 +89,8 @@ impl LocalPlayer {
entity: Entity,
packet_writer: mpsc::UnboundedSender<ServerboundGamePacket>,
world: Arc<RwLock<World>>,
+ read_packets_task: JoinHandle<()>,
+ write_packets_task: JoinHandle<()>,
) -> Self {
let client_information = ClientInformation::default();
@@ -102,7 +106,8 @@ impl LocalPlayer {
Some(entity),
))),
- tasks: Vec::new(),
+ read_packets_task,
+ write_packets_task,
}
}
@@ -117,9 +122,8 @@ impl LocalPlayer {
impl Drop for LocalPlayer {
/// Stop every active task when the `LocalPlayer` is dropped.
fn drop(&mut self) {
- for task in &self.tasks {
- task.abort();
- }
+ self.read_packets_task.abort();
+ self.write_packets_task.abort();
}
}