X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=backend%2Fsrc%2Fmain.rs;h=84485c22accdde0e04712a672117d042bc9829dd;hb=2f8ea6c56e1d0f6d481c31766fb18c883c673068;hp=a71142722207a239cbd3e7e8ac07e793c331d4ef;hpb=b76be16ce4c1bf35f67bab105e0f454da6662240;p=valheim_web.git diff --git a/backend/src/main.rs b/backend/src/main.rs index a711427..84485c2 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,14 +1,10 @@ - -extern crate listenfd; extern crate askama; -// use futures::sink::With; -use listenfd::ListenFd; +use std::{ sync::Mutex, env::args, fs::File, io::prelude::* }; + use actix_files as fs; use actix_web::{ get, web, Responder, middleware, App, HttpServer }; use askama::Template; - -use std::{ sync::Mutex, env::args, fs::File, io::prelude::* }; use ron::{ de::from_reader, ser::{ to_string_pretty, PrettyConfig } }; use serde::{ Deserialize, Serialize }; @@ -23,7 +19,8 @@ struct MainTemplate { memory: String, load_average: String, uptime: String, - world_size: String + world_size: String, + nb_of_players: u32, } const VALUE_UNKNOWN: &str = "-"; @@ -39,11 +36,12 @@ async fn main_page(config_shared: web::Data>) -> impl Responder { memory: info.format_memory(), load_average: info.format_load_average(), uptime: info.format_uptime(), - world_size: info.format_world_size() + world_size: info.format_world_size(), + nb_of_players: info.get_nb_of_player() }, 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() } + 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 } } } } @@ -55,7 +53,7 @@ struct Config { world_path: String, } -fn empty_string() -> String { "".to_string() } +fn empty_string() -> String { "".to_owned() } impl Config { fn default() -> Self { @@ -95,8 +93,7 @@ async fn main() -> std::io::Result<()> { let config_shared = web::Data::new(Mutex::new(config)); - let mut listenfd = ListenFd::from_env(); - let mut server = + let server = HttpServer::new( move || { App::new() @@ -106,14 +103,9 @@ async fn main() -> std::io::Result<()> { .service(main_page) .service(fs::Files::new("/static", "static").show_files_listing()) } - ); - - server = - if let Some(l) = listenfd.take_tcp_listener(0).unwrap() { - server.listen(l).unwrap() - } else { - server.bind(&format!("0.0.0.0:{}", port)).unwrap() - }; + ) + .bind(&format!("0.0.0.0:{}", port)) + .unwrap(); server.run().await }