peer count fix

This commit is contained in:
2025-11-13 21:09:52 +01:00
parent 97bd87640e
commit 4d38f6640a
@@ -464,8 +464,26 @@ async fn update_game_db(games: Vec<Game>, app: AppHandle) {
let state = app.state::<LanSpreadState>(); let state = app.state::<LanSpreadState>();
// Store games list {
*state.games.write().await = GameDB::from(games); let mut game_db = state.games.write().await;
// Reset peer counts up front. Presence/metadata stay anchored to the baked game.db.
for game in game_db.games.values_mut() {
game.peer_count = 0;
}
for peer_game in games {
if let Some(existing) = game_db.get_mut_game_by_id(&peer_game.id) {
existing.peer_count = peer_game.peer_count;
} else {
log::debug!(
"Peer advertised unknown game {id}; ignoring because game.db is ground truth",
id = peer_game.id
);
}
}
}
refresh_games_list(&app).await; refresh_games_list(&app).await;
} }