From bebcf77eb7aeecdeea5746ecc4da869a48c59dda Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 22 Mar 2021 11:12:01 +0100 Subject: [PATCH] Display '' if there is no active player. --- .gitignore | 3 ++- backend/src/valheim_controller.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) 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; -- 2.45.2