aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/disconnect.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-05-02 15:55:58 -0500
committerGitHub <noreply@github.com>2025-05-02 15:55:58 -0500
commit9a40b65bc1912298a43de43fd6e8477a8622a832 (patch)
treec429c62489926d6bbfc1675fea5a1860378d7a00 /azalea-client/src/plugins/disconnect.rs
parent52e34de95cd64a1c8ae1177cd7bc1d67fbab3c71 (diff)
downloadazalea-drasl-9a40b65bc1912298a43de43fd6e8477a8622a832.tar.xz
Add AutoReconnectPlugin (#221)
* add AutoReconnectPlugin * merge main * start simplifying swarm internals * fix Swarm::into_iter, handler functions, DisconnectEvent, and add some more docs * add ClientBuilder/SwarmBuilder::reconnect_after * fix a doctest * reword SwarmEvent::Disconnect doc * better behavior when we try to join twice * reconnect on ConnectionFailedEvent too * autoreconnect is less breaking now
Diffstat (limited to 'azalea-client/src/plugins/disconnect.rs')
-rw-r--r--azalea-client/src/plugins/disconnect.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/azalea-client/src/plugins/disconnect.rs b/azalea-client/src/plugins/disconnect.rs
index 343c25d8..987007c2 100644
--- a/azalea-client/src/plugins/disconnect.rs
+++ b/azalea-client/src/plugins/disconnect.rs
@@ -7,10 +7,7 @@ use bevy_ecs::prelude::*;
use derive_more::Deref;
use tracing::info;
-use crate::{
- InstanceHolder, client::JoinedClientBundle, connection::RawConnection,
- events::LocalPlayerEvents,
-};
+use crate::{InstanceHolder, client::JoinedClientBundle, connection::RawConnection};
pub struct DisconnectPlugin;
impl Plugin for DisconnectPlugin {
@@ -19,15 +16,28 @@ impl Plugin for DisconnectPlugin {
PostUpdate,
(
update_read_packets_task_running_component,
- disconnect_on_connection_dead,
remove_components_from_disconnected_players,
+ // this happens after `remove_components_from_disconnected_players` since that
+ // system removes `IsConnectionAlive`, which ensures that
+ // `DisconnectEvent` won't get called again from
+ // `disconnect_on_connection_dead`
+ disconnect_on_connection_dead,
)
.chain(),
);
}
}
-/// An event sent when a client is getting disconnected.
+/// An event sent when a client got disconnected from the server.
+///
+/// If the client was kicked with a reason, that reason will be present in the
+/// [`reason`](DisconnectEvent::reason) field.
+///
+/// This event won't be sent if creating the initial connection to the server
+/// failed, for that see [`ConnectionFailedEvent`].
+///
+/// [`ConnectionFailedEvent`]: crate::join::ConnectionFailedEvent
+
#[derive(Event)]
pub struct DisconnectEvent {
pub entity: Entity,
@@ -59,8 +69,8 @@ pub fn remove_components_from_disconnected_players(
.remove::<InLoadedChunk>()
// this makes it close the tcp connection
.remove::<RawConnection>()
- // swarm detects when this tx gets dropped to fire SwarmEvent::Disconnect
- .remove::<LocalPlayerEvents>();
+ // this makes it not send DisconnectEvent again
+ .remove::<IsConnectionAlive>();
// note that we don't remove the client from the ECS, so if they decide
// to reconnect they'll keep their state