diff --git a/src/main.rs b/src/main.rs index 611e08b..50834dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,6 +52,7 @@ async fn main() { .expect("Failed to start server!"); let mut status = server.get_server_status(); + hb_tx.send(status.clone()).await; loop { // TODO: Error handling if server.clients.len() > 0 { @@ -63,16 +64,18 @@ async fn main() { }, Err(e) => error!("Error: {e}"), } - }, + } ret = server::read_udp(&mut server.udp_socket) => { if let Some((addr, packet)) = ret { server.process_udp(addr, packet).await; } - }, + } + _ = tokio::time::sleep(tokio::time::Duration::from_millis(50)) => {} } } else { + trace!("eepy mode"); // TODO: Scuffed? - tokio::time::sleep(tokio::time::Duration::from_millis(50)).await; + tokio::time::sleep(tokio::time::Duration::from_millis(150)).await; } if let Err(e) = server.process().await { diff --git a/src/server/mod.rs b/src/server/mod.rs index 758de8d..a168190 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -86,7 +86,6 @@ pub async fn read_tcp(clients: &mut Vec) -> anyhow::Result { if let Some(raw_packet) = packet_opt { - // self.parse_packet(index, raw_packet).await?; Some((index, raw_packet)) } else { None @@ -720,6 +719,9 @@ impl Server { return Err(ServerError::BrokenPacket.into()); } else { // Sent as text so removing 48 brings it from [48-57] to [0-9] + if packet.data[3] < 48 || packet.data[5] < 48 { + return Err(ServerError::BrokenPacket.into()); + } let client_id = packet.data[3] - 48; let car_id = packet.data[5] - 48;