From bcb51f804f8a2586e9194708b981c62caea6864d Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Sat, 7 Feb 2026 11:48:48 -0500 Subject: [PATCH] Pass more network config info to multiplayer server impl, address #82 --- Cargo.lock | 1 + rc_core/src/persist/multiplayer.rs | 44 ++++++++++++++++++++++++++++++ rc_multiplayer/src/main.rs | 13 +++++++-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86fcf32..7eeed19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2108,6 +2108,7 @@ dependencies = [ "async-recursion", "async-trait", "bytes", + "chrono", "literustlib", "log", "tokio", diff --git a/rc_core/src/persist/multiplayer.rs b/rc_core/src/persist/multiplayer.rs index ba5756e..03b1b74 100644 --- a/rc_core/src/persist/multiplayer.rs +++ b/rc_core/src/persist/multiplayer.rs @@ -51,6 +51,7 @@ impl super::config::SelfValidator for MultiplayerConfig { message: "Game match may have broken vehicle flipping functionality due to more than 1 ClientAI per player".to_owned(), }); } + is_ok &= self.network.validate_in(info, &(), "network"); // TODO is_ok } @@ -76,6 +77,49 @@ pub struct NetworkConf { pub max_bulk_resend: u8, } +impl super::config::SelfValidator for NetworkConf { + type Context = (); + fn validate(&self, info: &mut super::config::ValidationInfo, _ctx: &Self::Context) -> bool { + let mut is_ok = true; + if self.max_delay < 0 { + info.error(super::config::ValidationMessage { + path: vec!["max_delay".to_owned()], + message: "Max delay cannot be negative (how do you live in the future!?)".to_owned(), + }); + is_ok = false; + } + if self.resend_delay_base < 0.0 { + info.error(super::config::ValidationMessage { + path: vec!["resend_delay_base".to_owned()], + message: "Resend delay cannot be negative (how do you live in the future!?)".to_owned(), + }); + is_ok = false; + } + if self.resend_delay_rtt_mult < 0.0 { + info.error(super::config::ValidationMessage { + path: vec!["resend_delay_rtt_mult".to_owned()], + message: "Resend delay multiplier cannot be negative (how do you live in the future!?)".to_owned(), + }); + is_ok = false; + } + if self.network_peer_update_interval < 0 { + info.error(super::config::ValidationMessage { + path: vec!["network_peer_update_interval".to_owned()], + message: "Update interval cannot be negative (how do you live in the future!?)".to_owned(), + }); + is_ok = false; + } + if self.max_delay_for_disconnect_ms < 0 { + info.error(super::config::ValidationMessage { + path: vec!["max_delay_for_disconnect_ms".to_owned()], + message: "Max delay cannot be negative (how do you live in the future!?)".to_owned(), + }); + is_ok = false; + } + is_ok + } +} + pub(super) fn default_match_autostart_after_s() -> Option { Some(180) } diff --git a/rc_multiplayer/src/main.rs b/rc_multiplayer/src/main.rs index 1082bf6..e69022e 100644 --- a/rc_multiplayer/src/main.rs +++ b/rc_multiplayer/src/main.rs @@ -40,11 +40,18 @@ async fn main() -> std::io::Result<()> { matches_chann, }; - let mtu = oj_rc_core::ConfigProvider::<()>::network_config(&init_ctx.config).max_packet_size; + let net_conf = oj_rc_core::ConfigProvider::<()>::network_config(&init_ctx.config); let dos_protection = oj_rc_core::ConfigProvider::<()>::server_config(&init_ctx.config).dos_protect; - let max_bulk_resend = oj_rc_core::ConfigProvider::<()>::network_config(&init_ctx.config).max_bulk_resend; let event_handler = events::handler(&init_ctx).await; - let server = literustlib_server::Server::new(event_handler, (args.ip, args.port), mtu, dos_protection, max_bulk_resend as usize).await.expect("Bad server"); + let server_conf = literustlib_server::ServerConfig { + max_bulk_resends: net_conf.max_bulk_resend as usize, + resend_delay_base: net_conf.resend_delay_base, + resend_delay_rtt_mult: net_conf.resend_delay_rtt_mult, + timeout: std::time::Duration::from_millis(net_conf.max_delay_for_disconnect_ms as u64), + dos_protection, + mtu: net_conf.max_packet_size, + }; + let server = literustlib_server::Server::new(event_handler, (args.ip, args.port), server_conf).await.expect("Bad server"); let start_time = chrono::Utc::now(); START_TIMESTAMP_S.store(start_time.timestamp(), std::sync::atomic::Ordering::Relaxed);