2025-05-03 18:49:39 -04:00
|
|
|
use axum::extract::Query;
|
2025-03-17 17:31:22 -04:00
|
|
|
use axum::response::Html;
|
|
|
|
use axum::{Router, routing::get};
|
2025-03-08 21:54:03 -05:00
|
|
|
use kawari::config::get_config;
|
2025-03-31 22:03:33 -04:00
|
|
|
use minijinja::Environment;
|
2025-03-08 21:54:03 -05:00
|
|
|
use minijinja::context;
|
2025-03-08 13:27:41 -05:00
|
|
|
use serde::{Deserialize, Serialize};
|
2025-05-03 11:56:27 -04:00
|
|
|
use tower_http::services::ServeDir;
|
2024-05-11 14:02:55 -04:00
|
|
|
|
2025-03-31 22:03:33 -04:00
|
|
|
fn setup_default_environment() -> Environment<'static> {
|
|
|
|
let mut env = Environment::new();
|
2025-05-03 11:56:27 -04:00
|
|
|
env.add_template_owned(
|
|
|
|
"layout.html",
|
|
|
|
std::fs::read_to_string("resources/templates/layout.html")
|
|
|
|
.expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2025-05-03 12:40:11 -04:00
|
|
|
env.add_template_owned(
|
|
|
|
"web_base.html",
|
|
|
|
std::fs::read_to_string("resources/templates/web_base.html")
|
|
|
|
.expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2025-05-03 11:12:56 -04:00
|
|
|
env.add_template_owned(
|
|
|
|
"web.html",
|
|
|
|
std::fs::read_to_string("resources/templates/web.html").expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
env.add_template_owned(
|
2025-03-31 22:03:33 -04:00
|
|
|
"worldstatus.html",
|
2025-05-03 11:12:56 -04:00
|
|
|
std::fs::read_to_string("resources/templates/worldstatus.html")
|
|
|
|
.expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
env.add_template_owned(
|
|
|
|
"account.html",
|
|
|
|
std::fs::read_to_string("resources/templates/account.html")
|
|
|
|
.expect("Failed to find template!"),
|
2025-03-31 22:03:33 -04:00
|
|
|
)
|
|
|
|
.unwrap();
|
2025-05-03 18:49:39 -04:00
|
|
|
env.add_template_owned(
|
|
|
|
"setup.html",
|
|
|
|
std::fs::read_to_string("resources/templates/setup.html")
|
|
|
|
.expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
env.add_template_owned(
|
|
|
|
"launchertweaks.toml",
|
|
|
|
std::fs::read_to_string("resources/templates/launchertweaks.toml")
|
|
|
|
.expect("Failed to find template!"),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2025-03-31 22:03:33 -04:00
|
|
|
|
|
|
|
env
|
|
|
|
}
|
|
|
|
|
2024-05-11 14:02:55 -04:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
struct GateStatus {
|
|
|
|
status: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn root() -> Html<String> {
|
2025-04-05 22:40:44 -04:00
|
|
|
let config = get_config();
|
2024-05-11 14:10:49 -04:00
|
|
|
|
|
|
|
let environment = setup_default_environment();
|
2025-04-05 22:40:44 -04:00
|
|
|
let template = environment.get_template("web.html").unwrap();
|
|
|
|
Html(
|
|
|
|
template
|
|
|
|
.render(context! { login_server => config.login.server_name })
|
|
|
|
.unwrap(),
|
|
|
|
)
|
2024-06-29 14:14:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn world_status() -> Html<String> {
|
|
|
|
let config = get_config();
|
|
|
|
|
|
|
|
let environment = setup_default_environment();
|
|
|
|
let template = environment.get_template("worldstatus.html").unwrap();
|
2025-03-08 13:27:41 -05:00
|
|
|
Html(
|
|
|
|
template
|
2025-05-06 16:09:05 -04:00
|
|
|
.render(context! { login_server => config.login.server_name, login_open => config.frontier.login_open, worlds_open => config.frontier.worlds_open })
|
2025-03-08 13:27:41 -05:00
|
|
|
.unwrap(),
|
|
|
|
)
|
2024-05-11 14:10:49 -04:00
|
|
|
}
|
|
|
|
|
2025-05-03 18:49:39 -04:00
|
|
|
async fn setup() -> Html<String> {
|
2025-05-06 16:09:05 -04:00
|
|
|
let config = get_config();
|
|
|
|
|
2025-05-03 18:49:39 -04:00
|
|
|
let environment = setup_default_environment();
|
|
|
|
let template = environment.get_template("setup.html").unwrap();
|
2025-05-06 16:09:05 -04:00
|
|
|
Html(
|
|
|
|
template
|
|
|
|
.render(context! { login_server => config.login.server_name })
|
|
|
|
.unwrap(),
|
|
|
|
)
|
2025-05-03 18:49:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[allow(dead_code)]
|
|
|
|
struct Params {
|
|
|
|
r#type: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn launcher_config(Query(params): Query<Params>) -> String {
|
|
|
|
let config = get_config();
|
|
|
|
|
|
|
|
let environment = setup_default_environment();
|
|
|
|
let template = environment.get_template("launchertweaks.toml").unwrap();
|
|
|
|
template
|
2025-05-05 21:03:47 -04:00
|
|
|
.render(context! { launcher_url => config.launcher.server_name, enable_webview2 => params.r#type != "webview2", game_patch_server => config.patch.game_server_name, boot_patch_server => config.patch.boot_server_name, lobby_port => config.lobby.port })
|
2025-05-03 18:49:39 -04:00
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-05-11 14:02:55 -04:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
|
|
|
|
let app = Router::new()
|
|
|
|
.route("/", get(root))
|
2025-05-03 11:56:27 -04:00
|
|
|
.route("/worldstatus", get(world_status))
|
2025-05-03 18:49:39 -04:00
|
|
|
.route("/setup", get(setup))
|
|
|
|
.route("/launcherconfig", get(launcher_config))
|
2025-05-03 11:56:27 -04:00
|
|
|
.nest_service("/static", ServeDir::new("resources/static"));
|
2024-05-11 14:02:55 -04:00
|
|
|
|
2025-03-22 16:47:21 -04:00
|
|
|
let config = get_config();
|
|
|
|
|
|
|
|
let addr = config.web.get_socketaddr();
|
2025-03-29 20:05:20 -04:00
|
|
|
tracing::info!("Server started on {addr}");
|
2025-03-22 21:44:28 -04:00
|
|
|
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
|
|
|
axum::serve(listener, app).await.unwrap();
|
2025-03-08 13:27:41 -05:00
|
|
|
}
|