From: Greg Burri Date: Mon, 22 Mar 2021 10:12:01 +0000 (+0100) Subject: Display '' if there is no active player. X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=bebcf77eb7aeecdeea5746ecc4da869a48c59dda;p=valheim_web.git Display '' if there is no active player. --- diff --git a/.gitignore b/.gitignore index 4e7a9ca..a7d4689 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target **/*.rs.bk backend/static/style.css -style.css.map \ No newline at end of file +style.css.map +.sass-cache diff --git a/backend/src/valheim_controller.rs b/backend/src/valheim_controller.rs index 0aa92de..a89c442 100644 --- a/backend/src/valheim_controller.rs +++ b/backend/src/valheim_controller.rs @@ -38,7 +38,11 @@ impl ValheimExe { } pub fn format_active_players(&self) -> String { - self.active_players.join(", ") + if self.active_players.len() == 0 { + String::from("") + } else { + self.active_players.join(", ") + } } pub fn format_last_backup(&self) -> String { @@ -79,7 +83,7 @@ fn get_active_players() -> Vec { journal.seek_tail().unwrap(); - let mut number_of_connections = -1; + let mut number_of_connections = 0; let mut players : Vec = Vec::new(); loop { @@ -91,8 +95,8 @@ fn get_active_players() -> Vec { if let Some(pos) = mess.find("Got character ZDOID from") { let character_str = mess.get(pos+25..).unwrap(); if let Some(pos_end) = character_str.find(" : ") { - let player_name = String::from(character_str.get(0..pos_end)); - if !players.contains(player_name) { + 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 { return players;