From 843e66f19026da14513787c35682df0ab7238fbc Mon Sep 17 00:00:00 2001 From: Romain 'Maz' BILLOIR Date: Sat, 8 Jun 2024 22:14:43 +0200 Subject: [PATCH 1/5] Fix typo in README file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 122ef55c..14d46de9 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ See also [What kind of networking should X game use?](https://github.com/bevyeng Check out the [quick start guide](https://docs.rs/bevy_replicon). -See also [examples](bevy_replicon_renet/examples) with [`bevy_replicon_renet`](bevy_replicon_renet) as a messaging backed. +See also [examples](bevy_replicon_renet/examples) with [`bevy_replicon_renet`](bevy_replicon_renet) as a messaging backend. Have any questions? Feel free to ask in the dedicated [`bevy_replicon` channel](https://discord.com/channels/691052431525675048/1090432346907492443) in Bevy's Discord server. From 9dc6c2ed642c8661ae4151be3b0eada17f3c6571 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Sat, 8 Jun 2024 22:05:36 +0300 Subject: [PATCH 2/5] Fix events example and improve doc comments --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aee43945..7d21bcaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -279,7 +279,7 @@ fn send_events(mut dummy_events: EventWriter) { dummy_events.send_default(); } -/// Receives event on server and single-player. +/// Receives events on server or single-player. fn receive_events(mut dummy_events: EventReader>) { for FromClient { client_id, event } in dummy_events.read() { info!("received event {event:?} from {client_id:?}"); @@ -338,7 +338,7 @@ from the send list): # let mut app = App::new(); # app.add_plugins(RepliconPlugins); app.add_server_event::(ChannelKind::Ordered) - .add_systems(Update, (send_events, receive_events.run_if(has_authority))); + .add_systems(Update, (send_events.run_if(has_authority), receive_events)); /// Sends an event from server or single-player. fn send_events(mut dummy_events: EventWriter>) { @@ -348,7 +348,7 @@ fn send_events(mut dummy_events: EventWriter>) { }); } -/// Receives event on client and single-player. +/// Receives events on client or listen server. fn receive_events(mut dummy_events: EventReader) { for event in dummy_events.read() { info!("received event {event:?} from server"); From 70ae8c704ac80b8c575f908806491d5fe047edb0 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Sat, 8 Jun 2024 23:55:09 +0300 Subject: [PATCH 3/5] Add logging for messages and do not send empty acks (#284) --- CHANGELOG.md | 8 ++++++++ src/client.rs | 12 +++++++----- src/client/replicon_client.rs | 12 +++++++++++- src/server/replicon_server.rs | 17 +++++++++++++---- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 512810c8..80038506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Logging for sending and receiving messages. + +### Changed + +- Do not send empty ack messages from client. + ## [0.26.2] - 2024-06-05 ### Added diff --git a/src/client.rs b/src/client.rs index 07ec809b..983b36e1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -156,12 +156,14 @@ fn apply_replication( // (unless user requested history via marker). let init_tick = *world.resource::(); let acks_size = mem::size_of::() * client.received_count(ReplicationChannel::Update); - let mut acks = Vec::with_capacity(acks_size); - for message in client.receive(ReplicationChannel::Update) { - let update_index = read_update_message(params, buffered_updates, message)?; - bincode::serialize_into(&mut acks, &update_index)?; + if acks_size != 0 { + let mut acks = Vec::with_capacity(acks_size); + for message in client.receive(ReplicationChannel::Update) { + let update_index = read_update_message(params, buffered_updates, message)?; + bincode::serialize_into(&mut acks, &update_index)?; + } + client.send(ReplicationChannel::Init, acks); } - client.send(ReplicationChannel::Init, acks); apply_update_messages(world, params, buffered_updates, init_tick) } diff --git a/src/client/replicon_client.rs b/src/client/replicon_client.rs index 4ad00d53..43db8beb 100644 --- a/src/client/replicon_client.rs +++ b/src/client/replicon_client.rs @@ -63,6 +63,11 @@ impl RepliconClient { .get_mut(channel_id as usize) .unwrap_or_else(|| panic!("client should have a receive channel with id {channel_id}")); + trace!( + "received {} message(s) from channel {channel_id}", + channel_messages.len() + ); + channel_messages.drain(..) } @@ -73,7 +78,12 @@ impl RepliconClient { return; } - self.sent_messages.push((channel_id.into(), message.into())); + let channel_id: u8 = channel_id.into(); + let message: Bytes = message.into(); + + trace!("sending {} bytes over channel {channel_id}", message.len()); + + self.sent_messages.push((channel_id, message)); } /// Sets the client connection status. diff --git a/src/server/replicon_server.rs b/src/server/replicon_server.rs index 117c3d8e..88d46e58 100644 --- a/src/server/replicon_server.rs +++ b/src/server/replicon_server.rs @@ -56,12 +56,17 @@ impl RepliconServer { } let channel_id = channel_id.into(); - let receive_channel = self + let channel_messages = self .received_messages .get_mut(channel_id as usize) .unwrap_or_else(|| panic!("server should have a receive channel with id {channel_id}")); - receive_channel.drain(..) + trace!( + "received {} message(s) from channel {channel_id}", + channel_messages.len() + ); + + channel_messages.drain(..) } /// Sends a message to a client over a channel. @@ -76,8 +81,12 @@ impl RepliconServer { return; } - self.sent_messages - .push((client_id, channel_id.into(), message.into())); + let channel_id: u8 = channel_id.into(); + let message: Bytes = message.into(); + + trace!("sending {} bytes over channel {channel_id}", message.len()); + + self.sent_messages.push((client_id, channel_id, message)); } /// Marks the server as running or stopped. From 434837b34c6616bc0edee44e99c9bd224bd3e32a Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Sun, 9 Jun 2024 03:02:22 +0300 Subject: [PATCH 4/5] Bump version to 0.26.3 --- CHANGELOG.md | 5 ++++- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80038506..68b352d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.26.3] - 2024-06-09 + ### Added - Logging for sending and receiving messages. @@ -517,7 +519,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Initial release after separation from [Project Harmonia](https://github.com/projectharmonia/project_harmonia). -[unreleased]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.2...HEAD +[unreleased]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.3...HEAD +[0.26.3]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.2...v0.26.3 [0.26.2]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.1...v0.26.2 [0.26.1]: https://github.com/projectharmonia/bevy_replicon/compare/v0.26.0...v0.26.1 [0.26.0]: https://github.com/projectharmonia/bevy_replicon/compare/v0.25.3...v0.26.0 diff --git a/Cargo.toml b/Cargo.toml index 2b77c240..2ce70b62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_replicon" -version = "0.26.2" +version = "0.26.3" authors = [ "Hennadii Chernyshchyk ", "koe ", From b3f1505d150e3efeafa089306504ec6943b76fb2 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Thu, 13 Jun 2024 05:57:54 +0300 Subject: [PATCH 5/5] Fix examples running on LAN (#290) - We should bind "0.0.0.0" for UdpSocket. - ` public_addresses` is not needed with `ServerAuthentication::Unsecure`. --- bevy_replicon_renet/examples/simple_box.rs | 7 +++---- bevy_replicon_renet/examples/tic_tac_toe.rs | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/bevy_replicon_renet/examples/simple_box.rs b/bevy_replicon_renet/examples/simple_box.rs index ab633521..2c2e69c7 100644 --- a/bevy_replicon_renet/examples/simple_box.rs +++ b/bevy_replicon_renet/examples/simple_box.rs @@ -89,14 +89,13 @@ impl SimpleBoxPlugin { }); let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; - let public_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port); - let socket = UdpSocket::bind(public_addr)?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port))?; let server_config = ServerConfig { current_time, max_clients: 10, protocol_id: PROTOCOL_ID, authentication: ServerAuthentication::Unsecure, - public_addresses: vec![public_addr], + public_addresses: Default::default(), }; let transport = NetcodeServerTransport::new(server_config, socket)?; @@ -130,7 +129,7 @@ impl SimpleBoxPlugin { let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let client_id = current_time.as_millis() as u64; let server_addr = SocketAddr::new(ip, port); - let socket = UdpSocket::bind((ip, 0))?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?; let authentication = ClientAuthentication::Unsecure { client_id, protocol_id: PROTOCOL_ID, diff --git a/bevy_replicon_renet/examples/tic_tac_toe.rs b/bevy_replicon_renet/examples/tic_tac_toe.rs index afe6cbb7..5aba126b 100644 --- a/bevy_replicon_renet/examples/tic_tac_toe.rs +++ b/bevy_replicon_renet/examples/tic_tac_toe.rs @@ -262,14 +262,13 @@ impl TicTacToePlugin { }); let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; - let public_addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port); - let socket = UdpSocket::bind(public_addr)?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port))?; let server_config = ServerConfig { current_time, max_clients: 1, protocol_id: PROTOCOL_ID, authentication: ServerAuthentication::Unsecure, - public_addresses: vec![public_addr], + public_addresses: Default::default(), }; let transport = NetcodeServerTransport::new(server_config, socket)?; @@ -290,7 +289,7 @@ impl TicTacToePlugin { let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?; let client_id = current_time.as_millis() as u64; let server_addr = SocketAddr::new(ip, port); - let socket = UdpSocket::bind((ip, 0))?; + let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?; let authentication = ClientAuthentication::Unsecure { client_id, protocol_id: PROTOCOL_ID,