peer count fix
This commit is contained in:
@@ -464,8 +464,26 @@ async fn update_game_db(games: Vec<Game>, app: AppHandle) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user