From cceca83dac677347c574ec4ebb6d62f6e196178c Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Tue, 1 Jul 2025 14:43:47 -0400 Subject: [PATCH] Add very rough heartbeat This also means that the peer can be started up before the main game --- src/net/plugin.rs | 62 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/src/net/plugin.rs b/src/net/plugin.rs index d621d45..2c01beb 100644 --- a/src/net/plugin.rs +++ b/src/net/plugin.rs @@ -1,21 +1,21 @@ -use std::net::SocketAddr; +use std::{net::SocketAddr, time::Duration}; use bevy::prelude::*; -use crate::game::prelude::Seed; - use super::{ queues::{NetworkReceive, NetworkSend}, socket::bind_socket, }; +use crate::game::prelude::Seed; -fn handle_network_io( +fn handle_network_input( receive: Res, send: Res, seed: Option>, mut commands: Commands, ) -> Result { for (message, address) in receive.iter() { + // Temporary logic just for initial connection, if there is already a seed then the peer wants it if let Some(ref value) = seed { send.send((**value).into(), address)?; } else { @@ -26,6 +26,25 @@ fn handle_network_io( Ok(()) } +const TIMEOUT: Duration = Duration::from_secs(5); + +fn heartbeat( + peers: Query<(&Peer, &mut PeerSendTiming)>, + send: Res, + time: Res