From 961190a467994abf518b5ec0d88b6665369a77a1 Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Sun, 9 Aug 2026 15:27:16 -0400 Subject: [PATCH] Factor in connection latency when respawning player, bump LiteRustLib (with fix #143) --- Cargo.lock | 8 ++------ rc_multiplayer/Cargo.toml | 8 ++++---- rc_multiplayer/src/matches/modes/battle_arena.rs | 7 +++++++ rc_multiplayer/src/matches/modes/mod.rs | 4 ++-- rc_multiplayer/src/matches/modes/pit.rs | 7 +++++++ rc_multiplayer/src/matches/modes/team_death_match.rs | 7 +++++++ 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b1b865..a9cd36c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2706,9 +2706,7 @@ checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "literustlib" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c053853b6b4fbb6907900433ec84772b464088a2c8c508e95e05998800d01d42" +version = "0.5.0" dependencies = [ "bytes", "num_enum 0.7.6", @@ -2716,9 +2714,7 @@ dependencies = [ [[package]] name = "literustlib_server" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dab424002ff8523d212b08ccc5db462d797ca51bd7cca820329e173881e5fa71" +version = "0.5.0" dependencies = [ "async-recursion", "async-trait", diff --git a/rc_multiplayer/Cargo.toml b/rc_multiplayer/Cargo.toml index b77d077..28e50f8 100644 --- a/rc_multiplayer/Cargo.toml +++ b/rc_multiplayer/Cargo.toml @@ -22,10 +22,10 @@ num-quaternion.workspace = true rand.workspace = true git-version.workspace = true -#literustlib_server = { version = "0.4", path = "../../LiteRustLib/server" } -#literustlib = { version = "0.4", path = "../../LiteRustLib" } -literustlib_server = { version = "0.4" } -literustlib = { version = "0.4" } +literustlib_server = { version = "0.5", path = "../../LiteRustLib/server" } +literustlib = { version = "0.5", path = "../../LiteRustLib" } +#literustlib_server = { version = "0.4" } +#literustlib = { version = "0.4" } rlnl = { version = "0.1", path = "../../rlnl" } oj_serdes.workspace = true diff --git a/rc_multiplayer/src/matches/modes/battle_arena.rs b/rc_multiplayer/src/matches/modes/battle_arena.rs index 0f8ceb5..e1c8e3f 100644 --- a/rc_multiplayer/src/matches/modes/battle_arena.rs +++ b/rc_multiplayer/src/matches/modes/battle_arena.rs @@ -1298,6 +1298,12 @@ impl BattleArenaLogic { }; if let Some(player_desc) = generic.user_descriptor(player_id) { let connections = generic.users.read().await.values().map(|player_info| player_info.connection.clone()).collect(); + let my_connection_latency = generic.users.read().await + .iter() + .filter(|(user_player_id, _)| **user_player_id == player_id) + .next() + .unwrap() + .1.connection.connection.latency(); tokio::task::spawn(super::respawn_player_after( respawn_timestamp, connections, @@ -1305,6 +1311,7 @@ impl BattleArenaLogic { Some(self.map_center.clone()), player_id, player_desc.machine.is_alive.clone(), + my_connection_latency, )); } else { log::error!("Player {} cannot respawn because they are not in the game!?", player_id); diff --git a/rc_multiplayer/src/matches/modes/mod.rs b/rc_multiplayer/src/matches/modes/mod.rs index 3333278..6371e3c 100644 --- a/rc_multiplayer/src/matches/modes/mod.rs +++ b/rc_multiplayer/src/matches/modes/mod.rs @@ -16,8 +16,8 @@ pub use team_death_match::TeamDeathMatchLogic; pub(super) mod trackers; -async fn respawn_player_after(after: chrono::DateTime, players: Vec, spawn: oj_rc_core::persist::config::Point, looking_at: Option, player_id: u8, alive_flag: std::sync::Arc) { - let sleep_dur = after.signed_duration_since(chrono::Utc::now()).to_std().expect("Respawn duration too long to sleep"); +async fn respawn_player_after(after: chrono::DateTime, players: Vec, spawn: oj_rc_core::persist::config::Point, looking_at: Option, player_id: u8, alive_flag: std::sync::Arc, player_latency: std::time::Duration) { + let sleep_dur = after.signed_duration_since(chrono::Utc::now()).to_std().expect("Respawn duration too long to sleep") - player_latency; tokio::time::sleep(sleep_dur).await; let spawn_payload = rlnl::events::sync::SpawnPoint { pos: rlnl::types::PosQuatPair { diff --git a/rc_multiplayer/src/matches/modes/pit.rs b/rc_multiplayer/src/matches/modes/pit.rs index dd1d639..5fc0a2f 100644 --- a/rc_multiplayer/src/matches/modes/pit.rs +++ b/rc_multiplayer/src/matches/modes/pit.rs @@ -368,6 +368,12 @@ impl PitLogic { ).await; let spawn_point = Self::choose_spawn_point(&generic.map_config, player_id).1; let connections = generic.users.read().await.values().map(|player_info| player_info.connection.clone()).collect(); + let my_connection_latency = generic.users.read().await + .iter() + .filter(|(user_player_id, _)| **user_player_id == player_id) + .next() + .unwrap() + .1.connection.connection.latency(); tokio::task::spawn(super::respawn_player_after( respawn_timestamp, connections, @@ -375,6 +381,7 @@ impl PitLogic { Some(self.map_center.clone()), player_id, player_desc.machine.is_alive.clone(), + my_connection_latency, )); } } diff --git a/rc_multiplayer/src/matches/modes/team_death_match.rs b/rc_multiplayer/src/matches/modes/team_death_match.rs index 855d37b..8641fc8 100644 --- a/rc_multiplayer/src/matches/modes/team_death_match.rs +++ b/rc_multiplayer/src/matches/modes/team_death_match.rs @@ -307,6 +307,12 @@ impl TeamDeathMatchLogic { }; if let Some(player_desc) = generic.user_descriptor(player_id) { let connections = generic.users.read().await.values().map(|player_info| player_info.connection.clone()).collect(); + let my_connection_latency = generic.users.read().await + .iter() + .filter(|(user_player_id, _)| **user_player_id == player_id) + .next() + .unwrap() + .1.connection.connection.latency(); tokio::task::spawn(super::respawn_player_after( respawn_timestamp, connections, @@ -314,6 +320,7 @@ impl TeamDeathMatchLogic { Some(self.map_center.clone()), player_id, player_desc.machine.is_alive.clone(), + my_connection_latency, )); } else { log::error!("Player {} cannot respawn because they are not in the game!?", player_id);