Add a message to know if the server is running or not.
[valheim_web.git] / backend / src / main.rs
index 99bebc3..d2607fd 100644 (file)
@@ -12,6 +12,8 @@ use ron::{ de::from_reader, ser::{ to_string_pretty, PrettyConfig } };
 use serde::{ Deserialize, Serialize };
 
 mod consts;
+mod tests;
+mod valheim_controller;
 
 #[derive(Template)]
 #[template(path = "main.html")]
@@ -28,7 +30,9 @@ pub struct Request {
 async fn main_page(/*key_shared: web::Data<Mutex<String>>,*/ query: Query<Request>) -> impl Responder {
     //let key = key_shared.lock().unwrap();
 
-    let m = String::from("hello");
+    let m = 
+        if valheim_controller::is_valheim_running() { String::from("Valheim server is up and running") } else { String::from("Valheim server is down :(") };
+
     MainTemplate { sentence: m }
 }
 
@@ -94,7 +98,7 @@ async fn main() -> std::io::Result<()> {
 fn process_args() -> bool {
     fn print_usage() {
         println!("Usage:");
-        println!(" {} [--help]", get_exe_name());
+        println!(" {} [--help] [--status]", get_exe_name());
     }
 
     let args: Vec<String> = args().collect();
@@ -102,6 +106,9 @@ fn process_args() -> bool {
     if args.iter().any(|arg| arg == "--help") {
         print_usage();
         return true
+    } else if args.iter().any(|arg| arg == "--status") {
+        valheim_controller::is_valheim_running();
+        return true
     }
 
     false