Display '<none>' if there is no active player.
authorGreg Burri <greg.burri@gmail.com>
Mon, 22 Mar 2021 10:12:01 +0000 (11:12 +0100)
committerGreg Burri <greg.burri@gmail.com>
Mon, 22 Mar 2021 10:12:01 +0000 (11:12 +0100)
.gitignore
backend/src/valheim_controller.rs

index 4e7a9ca..a7d4689 100644 (file)
@@ -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
index 0aa92de..a89c442 100644 (file)
@@ -38,7 +38,11 @@ impl ValheimExe {
     }\r
 \r
     pub fn format_active_players(&self) -> String {\r
-        self.active_players.join(", ")\r
+        if self.active_players.len() == 0 {\r
+            String::from("<none>")\r
+        } else {\r
+            self.active_players.join(", ")\r
+        }\r
     }\r
 \r
     pub fn format_last_backup(&self) -> String {\r
@@ -79,7 +83,7 @@ fn get_active_players() -> Vec<String> {
 \r
     journal.seek_tail().unwrap();\r
 \r
-    let mut number_of_connections = -1;\r
+    let mut number_of_connections = 0;\r
     let mut players : Vec<String> = Vec::new();\r
 \r
     loop {\r
@@ -91,8 +95,8 @@ fn get_active_players() -> Vec<String> {
                         if let Some(pos) = mess.find("Got character ZDOID from") {\r
                             let character_str = mess.get(pos+25..).unwrap();\r
                             if let Some(pos_end) = character_str.find(" : ") {\r
-                                let player_name = String::from(character_str.get(0..pos_end));\r
-                                if !players.contains(player_name) {\r
+                                let player_name = String::from(character_str.get(0..pos_end).unwrap());\r
+                                if !players.contains(&player_name) {\r
                                     players.push(player_name);\r
                                     if players.len() == number_of_connections {\r
                                         return players;\r