From: Greg Burri Date: Mon, 22 Mar 2021 21:42:54 +0000 (+0100) Subject: Be sure the right number of connection is used X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=150411e0cffb5ad0127d822c39a38c2e92b2bd99;p=valheim_web.git Be sure the right number of connection is used --- diff --git a/backend/src/valheim_controller.rs b/backend/src/valheim_controller.rs index 29f30f1..8c04e23 100644 --- a/backend/src/valheim_controller.rs +++ b/backend/src/valheim_controller.rs @@ -85,7 +85,7 @@ fn get_active_players() -> Vec { journal.seek_tail().unwrap(); - let mut number_of_connections = 0; + let mut number_of_connections = -1i32; let mut players : Vec = Vec::new(); loop { @@ -99,7 +99,7 @@ fn get_active_players() -> Vec { let player_name = String::from(character_str.get(0..pos_end).unwrap()); if !players.contains(&player_name) { players.push(player_name); - if players.len() == number_of_connections { + if players.len() as i32 == number_of_connections { return players; } } @@ -109,11 +109,12 @@ fn get_active_players() -> Vec { let nb_of_connections_str = mess.get(pos+STRING_BEFORE_NB_OF_CONNECTIONS.len()+1..).unwrap(); if let Some(pos_end) = nb_of_connections_str.find(' ') { if let Ok(n) = nb_of_connections_str.get(0..pos_end).unwrap().parse() { - if n > number_of_connections { - number_of_connections = n; - } - if players.len() >= number_of_connections { - return players; + if number_of_connections == -1 { + number_of_connections = n as i32 + + if players.len() as i32 >= number_of_connections { + return players; + } } } }