\r
const MINECRAFT_PROCESS_NAME: &str = "java";\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
+struct StatusFromRcon {\r
+ players: Vec<String>,\r
+}\r
+\r
+fn get_status_from_rcon(rcon_password: &str) -> StatusFromRcon {\r
let mut client = minecraft_client_rs::Client::new("127.0.0.1:25575".to_string()).unwrap();\r
\r
- let players =\r
+ let status =\r
match client.authenticate(rcon_password.to_string()) {\r
Ok(_) => {\r
- match client.send_command("list".to_string()) {\r
- Ok(resp) => {\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 from 'list' command");\r
- Vec::new()\r
- },\r
+ StatusFromRcon {\r
+ players:\r
+ match client.send_command("list".to_string()) {\r
+ Ok(resp) => {\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 from 'list' command");\r
+ Vec::new()\r
+ },\r
+ }\r
}\r
},\r
Err(_e) => {\r
println!("Authentication error");\r
- Vec::new()\r
+ StatusFromRcon { players: Vec::new() }\r
},\r
};\r
\r
client.close().unwrap();\r
\r
- players\r
+ status\r
}\r
\r
fn get_last_backup_datetime(backup_path: &str) -> Option<SystemTime> {\r
\r
let world_size = match fs_extra::dir::get_size(world_path) { Ok(l) => l, Err(_) => 0u64 };\r
\r
+ let status_from_rcon = get_status_from_rcon(rcon_password);\r
+\r
Some(\r
MinecraftExe {\r
memory: process.memory(),\r
load_average_5min: system.get_load_average().five / system.get_processors().len() as f64 * 100.,\r
uptime: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() - process.start_time(),\r
world_size,\r
- active_players: get_active_players(rcon_password),\r
+ active_players: status_from_rcon.players,\r
last_backup: get_last_backup_datetime(backup_path)\r
}\r
)\r