load_average: String,
uptime: String,
world_size: String,
- nb_of_players: u32,
+ active_players: String,
last_backup: String,
}
load_average: info.format_load_average(),
uptime: info.format_uptime(),
world_size: info.format_world_size(),
- nb_of_players: info.get_nb_of_player(),
+ active_players: info.format_active_players(),
last_backup: info.format_last_backup()
},
None => {
let value_unknown = String::from(VALUE_UNKNOWN);
- MainTemplate { text_status: String::from("Valheim server is down :("), memory: value_unknown.clone(), load_average: value_unknown.clone(), uptime: value_unknown.clone(), world_size: value_unknown.clone(), nb_of_players: 0, last_backup: value_unknown.clone() }
+ MainTemplate {
+ text_status: String::from("Valheim server is down :("),
+ memory: value_unknown.clone(),
+ load_average: value_unknown.clone(),
+ uptime: value_unknown.clone(),
+ world_size: value_unknown.clone(),
+ active_players: value_unknown.clone(),
+ last_backup: value_unknown.clone() }
}
}
}
load_average_5min: f64, // [%].\r
uptime: u64, // [s].\r
world_size: u64, // [B].\r
- nb_of_players: u32,\r
+ active_players: Vec<String>,\r
last_backup: Option<SystemTime>,\r
}\r
\r
format_byte_size(self.world_size, 2)\r
}\r
\r
- pub fn get_nb_of_player(&self) -> u32 {\r
- self.nb_of_players\r
+ pub fn format_active_players(&self) -> String {\r
+ self.active_players.join(", ")\r
}\r
\r
pub fn format_last_backup(&self) -> String {\r
const VALHEIM_PROCESS_NAME: &str = "valheim_server";\r
\r
#[cfg(target_os = "linux")]\r
-fn get_number_of_players() -> u32 {\r
+fn get_active_players() -> Vec<String> {\r
let mut journal =\r
journal::OpenOptions::default().current_user(true).open().unwrap();\r
\r
journal.seek_tail().unwrap();\r
\r
+ let mut number_of_connections = -1;\r
+ let mut players : Vec<String> = Vec::new();\r
+\r
loop {\r
match journal.previous_entry() {\r
Ok(Some(entry)) => {\r
if let (Some(unit), Some(mess)) = (entry.get("_SYSTEMD_UNIT"), entry.get("MESSAGE")) {\r
if unit == "valheim.service" {\r
- if let Some(pos) = mess.find("Connections") {\r
+ //"Got character ZDOID from {}"\r
+ if let Some(pos) = mess.find("Got character ZDOID from") {\r
+ let character_str = mess.get(pos+25..).unwrap();\r
+ if let Some(pos_end) = character_str.find(" : ") {\r
+ let player_name = String::from(character_str.get(0..pos_end));\r
+ if !players.contains(player_name) {\r
+ players.push(player_name);\r
+ if players.len() == number_of_connections {\r
+ return players;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else if let Some(pos) = mess.find("Connections") {\r
let nb_of_connections_str = mess.get(pos+12..).unwrap();\r
if let Some(pos_end) = nb_of_connections_str.find(' ') {\r
if let Ok(n) = nb_of_connections_str.get(0..pos_end).unwrap().parse() {\r
- return n;\r
+ number_of_connections = n;\r
+ if players.len() >= number_of_connections {\r
+ return players;\r
+ }\r
}\r
}\r
}\r
}\r
}\r
},\r
- _ => return 0\r
+ _ => return players\r
}\r
}\r
}\r
\r
#[cfg(target_os = "windows")]\r
-fn get_number_of_players() -> u32 {\r
- 0\r
+fn get_active_players() -> Vec<String> {\r
+ Vec::new()\r
}\r
\r
fn get_last_backup_datetime(backup_path: &str) -> Option<SystemTime> {\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
- nb_of_players: get_number_of_players(),\r
+ active_players: get_active_players(),\r
last_backup: get_last_backup_datetime(backup_path)\r
}\r
)\r