Comment out the code to format player list
[minecraft_web.git] / backend / src / minecraft_controller.rs
index 260a6e4..f04ed24 100644 (file)
@@ -4,9 +4,6 @@ use std::{ fs, time::SystemTime };
 \r
 use chrono::{ DateTime, offset::Local };\r
 \r
-#[cfg(target_os = "linux")]\r
-use systemd::journal;\r
-\r
 #[derive(Clone, Debug)]\r
 pub struct MinecraftExe {\r
     memory: u64, // [kB].\r
@@ -38,13 +35,11 @@ impl MinecraftExe {
     }\r
 \r
     pub fn format_active_players(&self) -> String {\r
-        /* Commented because the player list isn't correct (the number is).\r
         if self.active_players.len() == 0 {\r
             String::from("<none>")\r
         } else {\r
             self.active_players.join(", ")\r
-        }*/\r
-        self.active_players.len().to_string()\r
+        }\r
     }\r
 \r
     pub fn format_last_backup(&self) -> String {\r
@@ -78,12 +73,6 @@ fn format_byte_size(bytes: u64, precision: usize) -> String {
 \r
 const MINECRAFT_PROCESS_NAME: &str = "java";\r
 \r
-#[cfg(target_os = "linux")]\r
-const STRING_BEFORE_CHARACTER_NAME: &str = "Got character ZDOID from";\r
-\r
-#[cfg(target_os = "linux")]\r
-const STRING_BEFORE_NB_OF_CONNECTIONS: &str = "Connections";\r
-\r
 // It doesn't work for the moment, it only scan the connection event and do not treat disconnections.\r
 fn get_active_players(rcon_password: &str) -> Vec<String> {\r
     let mut client = minecraft_client_rs::Client::new("127.0.0.1:25575".to_string()).unwrap();\r
@@ -93,11 +82,15 @@ fn get_active_players(rcon_password: &str) -> Vec<String> {
             Ok(_) => {\r
                 match client.send_command("list".to_string()) {\r
                     Ok(resp) => {\r
-                        println!("{}", resp.body);\r
-                        Vec::new()\r
+                        resp.body\r
+                            .split('\n')\r
+                            .skip(1)\r
+                            .filter(|n| !n.is_empty())\r
+                            .map(|n| n.to_string())\r
+                            .collect()\r
                     },\r
                     Err(_e) => {\r
-                        println!("Error asking seed");\r
+                        println!("Error from 'list' command");\r
                         Vec::new()\r
                     },\r
                 }\r