Skip to content

Commit f03ce1e

Browse files
committed
Stop server immediately as well
1 parent 1f1333d commit f03ce1e

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

bevy_replicon_example_backend/src/server.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ impl Plugin for RepliconExampleServerPlugin {
2020
app.add_systems(
2121
PreUpdate,
2222
(
23-
set_stopped.run_if(resource_removed::<ExampleServer>),
2423
set_running.run_if(resource_added::<ExampleServer>),
2524
receive_packets.run_if(resource_exists::<ExampleServer>),
2625
)
@@ -29,9 +28,14 @@ impl Plugin for RepliconExampleServerPlugin {
2928
)
3029
.add_systems(
3130
PostUpdate,
32-
send_packets
33-
.in_set(ServerSet::SendPackets)
34-
.run_if(resource_exists::<ExampleServer>),
31+
(
32+
set_stopped
33+
.before(ServerSet::Send)
34+
.run_if(resource_removed::<ExampleServer>),
35+
send_packets
36+
.in_set(ServerSet::SendPackets)
37+
.run_if(resource_exists::<ExampleServer>),
38+
),
3539
);
3640
}
3741
}

src/shared/backend/replicon_server.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ use log::{debug, trace, warn};
55
/// Stores information about the server independent from the messaging backend.
66
///
77
/// The messaging backend is responsible for updating this resource:
8-
/// - When the server is started or stopped, [`Self::set_running`] should be used to reflect this.
8+
/// - When the server starts or stops, [`Self::set_running`] should be used to update its status:
9+
/// - Set to `true` in [`ServerSet::ReceivePackets`](crate::server::ServerSet::ReceivePackets) to
10+
/// allow immediate processing of received messages.
11+
/// - Set to `false` before [`ServerSet::Send`](crate::server::ServerSet::Send) to ensure
12+
/// the server stops immediately on the same frame.
913
/// - For receiving messages, [`Self::insert_received`] should be used.
1014
/// A system to forward messages from the backend to Replicon should run in [`ServerSet::ReceivePackets`](crate::server::ServerSet::ReceivePackets).
1115
/// - For sending messages, [`Self::drain_sent`] should be used to drain all sent messages.

0 commit comments

Comments
 (0)