Merge branch 'master' of gburri.org:valheim_web
authorGreg Burri <greg.burri@gmail.com>
Fri, 8 Apr 2022 19:35:04 +0000 (21:35 +0200)
committerGreg Burri <greg.burri@gmail.com>
Fri, 8 Apr 2022 19:35:04 +0000 (21:35 +0200)
1  2 
backend/src/valheim_controller.rs

@@@ -1,6 -1,7 +1,6 @@@
 -use sysinfo::{ ProcessExt, SystemExt };\r
  \r
  use std::{ fs, time::SystemTime };\r
 -\r
 +use sysinfo::{ ProcessExt, SystemExt };\r
  use chrono::{ DateTime, offset::Local };\r
  \r
  #[cfg(target_os = "linux")]\r
@@@ -37,11 -38,13 +37,13 @@@ impl ValheimExe 
      }\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
+         }*/\r
+         self.active_players.len().to_string()\r
      }\r
  \r
      pub fn format_last_backup(&self) -> String {\r
@@@ -81,6 -84,7 +83,7 @@@ const STRING_BEFORE_CHARACTER_NAME: &st
  #[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
  #[cfg(target_os = "linux")]\r
  fn get_active_players() -> Vec<String> {\r
      let mut journal =\r
@@@ -153,16 -157,17 +156,16 @@@ fn get_last_backup_datetime(backup_path
  pub fn get_valheim_executable_information(world_path: &str, backup_path: &str) -> Option<ValheimExe> {\r
      let mut system = sysinfo::System::new_all();\r
      system.refresh_system();\r
 -    let processes = system.get_process_by_name(VALHEIM_PROCESS_NAME);\r
 +    let mut processes = system.processes_by_name(VALHEIM_PROCESS_NAME);\r
  \r
 -    if processes.len() >= 1 {\r
 -        let process = processes.first().unwrap();\r
 +    if let Some(process) = processes.next() {\r
  \r
          let world_size = match std::fs::metadata(world_path) { Ok(f) => f.len(), Err(_) => 0u64 };\r
  \r
          Some(\r
              ValheimExe {\r
                  memory: process.memory(),\r
 -                load_average_5min: system.get_load_average().five / system.get_processors().len() as f64 * 100.,\r
 +                load_average_5min: system.load_average().five / system.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(),\r