X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=backend%2Fsrc%2Fminecraft_controller.rs;h=13a3e3f55356f58386cac5bf246d5e06a3daa639;hb=b18873a936be63f85a1f884fa86a60bfde241c02;hp=260a6e410fc2d0975539548aa3c953a95065fde8;hpb=16f93d7c5d110a92f90a4596e4fb3b994ae12932;p=minecraft_web.git diff --git a/backend/src/minecraft_controller.rs b/backend/src/minecraft_controller.rs index 260a6e4..13a3e3f 100644 --- a/backend/src/minecraft_controller.rs +++ b/backend/src/minecraft_controller.rs @@ -4,9 +4,6 @@ use std::{ fs, time::SystemTime }; use chrono::{ DateTime, offset::Local }; -#[cfg(target_os = "linux")] -use systemd::journal; - #[derive(Clone, Debug)] pub struct MinecraftExe { memory: u64, // [kB]. @@ -38,13 +35,11 @@ impl MinecraftExe { } pub fn format_active_players(&self) -> String { - /* Commented because the player list isn't correct (the number is). if self.active_players.len() == 0 { String::from("") } else { self.active_players.join(", ") - }*/ - self.active_players.len().to_string() + } } pub fn format_last_backup(&self) -> String { @@ -78,12 +73,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(); @@ -93,11 +82,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() }, } @@ -137,7 +130,7 @@ pub fn get_minecraft_executable_information(world_path: &str, backup_path: &str, if processes.len() >= 1 { let process = processes.first().unwrap(); - let world_size = match std::fs::metadata(world_path) { Ok(f) => f.len(), Err(_) => 0u64 }; + let world_size = match fs_extra::dir::get_size(world_path) { Ok(l) => l, Err(_) => 0u64 }; Some( MinecraftExe {