Parse player list from 'list' command.
authorGreg Burri <greg.burri@gmail.com>
Wed, 23 Jun 2021 10:38:53 +0000 (12:38 +0200)
committerGreg Burri <greg.burri@gmail.com>
Wed, 23 Jun 2021 10:38:53 +0000 (12:38 +0200)
backend/src/minecraft_controller.rs

index 9bcc7d3..d9a68c0 100644 (file)
@@ -75,12 +75,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
@@ -90,11 +84,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