Skip to content

Commit 19bf434

Browse files
committed
fix: repair discarded-value bugs and harden client packet handling
- mono-server: turret recharge assigned its saturating_add result (was discarded) and clamped to capacity. - bevy-client: projectile-move-end timer is now reassigned (was constructed then dropped); keyframe decode logs and skips malformed frames instead of panicking; F5 debug toggle uses just_pressed.
1 parent a6a2f85 commit 19bf434

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

packages/bevy-client/src/debug/plugin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ impl Plugin for DebugPlugin {
1919
}
2020

2121
fn toggle_debug_ui(mut debug_ui: ResMut<DebugUI>, input: Res<ButtonInput<KeyCode>>) {
22-
if input.pressed(KeyCode::F5) {
22+
// `just_pressed` so one keypress toggles once instead of flipping every frame held.
23+
if input.just_pressed(KeyCode::F5) {
2324
debug_ui.enabled = !debug_ui.enabled;
2425
}
2526
}

packages/bevy-client/src/engine/plugin.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ impl Plugin for EnginePlugin {
5353
}
5454

5555
fn reset_projectile_move_end_timer(mut projectile_timer: ResMut<ProjectileMoveEndTimer>, state: Res<State>) {
56-
projectile_timer.0.reset();
57-
Timer::from_seconds(
56+
// Re-arm the timer against the most recent observed tick duration so projectile
57+
// timing tracks the real server tick rate instead of the fixed startup value.
58+
projectile_timer.0 = Timer::from_seconds(
5859
state.global.last_tick_duration.as_secs_f32() * PROJECTILE_MOVE_END_TICK_PORTION,
5960
TimerMode::Once,
6061
);

packages/bevy-client/src/networker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ pub fn handle_network_events(network_info: ResMut<NetworkInfo>, mut state: ResMu
178178
ewebsock::WsEvent::Message(ewebsock::WsMessage::Binary(data)) => {
179179
println!("received binary message of len {:?}", data.len());
180180

181-
let keyframe: KeyFrame =
182-
postcard::from_bytes(&data).expect("failed to deserialize keyframe");
181+
let keyframe: KeyFrame = match postcard::from_bytes(&data) {
182+
Ok(keyframe) => keyframe,
183+
Err(err) => {
184+
// A single malformed frame must not crash the client.
185+
error!("failed to deserialize keyframe: {err}");
186+
return;
187+
}
188+
};
183189

184190
let Some(world) = deserialize_world_data(keyframe.world_data) else {
185191

packages/mono-server/src/simulations/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ pub fn update(game_state: &mut GameState) {
8484
}
8585

8686
for (entity, (turret, energy)) in &mut game_state.world.query::<(&Turret, &mut Energy)>() {
87-
let _ = energy.current.saturating_add(1000);
87+
energy.current = energy.current.saturating_add(1000).min(energy.capacity);
8888
}
8989
}

0 commit comments

Comments
 (0)