From 5df9e614e940f47256773b7d0787e46f90082ff7 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 23 Jun 2021 12:38:53 +0200 Subject: [PATCH] Parse player list from 'list' command. --- backend/src/minecraft_controller.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/minecraft_controller.rs b/backend/src/minecraft_controller.rs index 9bcc7d3..d9a68c0 100644 --- a/backend/src/minecraft_controller.rs +++ b/backend/src/minecraft_controller.rs @@ -75,12 +75,6 @@ fn format_byte_size(bytes: u64, precision: usize) -> String { const MINECRAFT_PROCESS_NAME: &str = "java"; -#[cfg(target_os = "linux")] -const STRING_BEFORE_CHARACTER_NAME: &str = "Got character ZDOID from"; - -#[cfg(target_os = "linux")] -const STRING_BEFORE_NB_OF_CONNECTIONS: &str = "Connections"; - // It doesn't work for the moment, it only scan the connection event and do not treat disconnections. fn get_active_players(rcon_password: &str) -> Vec { let mut client = minecraft_client_rs::Client::new("127.0.0.1:25575".to_string()).unwrap(); @@ -90,11 +84,15 @@ fn get_active_players(rcon_password: &str) -> Vec { Ok(_) => { match client.send_command("list".to_string()) { Ok(resp) => { - println!("{}", resp.body); - Vec::new() + resp.body + .split('\n') + .skip(1) + .filter(|n| !n.is_empty()) + .map(|n| n.to_string()) + .collect() }, Err(_e) => { - println!("Error asking seed"); + println!("Error from 'list' command"); Vec::new() }, } -- 2.45.2