From 28b27866dbd23f9a0eee677b1cc6dfef2be37f43 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 22 Apr 2025 16:00:10 -0400 Subject: [PATCH] Serve a launcher page under launcher.ffxiv.localhost This can eventually be put into a retail launcher, but it doesn't do much yet. --- .github/workflows/main.yml | 1 + Cargo.toml | 3 ++ resources/Caddyfile | 6 +++- scripts/run.sh | 1 + src/bin/kawari-launcher.rs | 42 +++++++++++++++++++++++ src/config.rs | 30 ++++++++++++++++ templates/launcher.html | 70 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/bin/kawari-launcher.rs create mode 100644 templates/launcher.html diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b83d9d3..d833a1f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,6 +74,7 @@ jobs: target/release/kawari-patch* target/release/kawari-web* target/release/kawari-world* + target/release/kawari-launcher* !target/release/*.d resources/ !resources/tests diff --git a/Cargo.toml b/Cargo.toml index ac54a86..15567dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,9 @@ name = "kawari-lobby" name = "kawari-world" required-features = ["oodle"] +[[bin]] +name = "kawari-launcher" + [profile.release] lto = true strip = true diff --git a/resources/Caddyfile b/resources/Caddyfile index 64d37c9..4bb50cf 100644 --- a/resources/Caddyfile +++ b/resources/Caddyfile @@ -10,6 +10,10 @@ ffxiv.localhost:80 { reverse_proxy :5801 } +launcher.ffxiv.localhost:80 { + reverse_proxy :5802 +} + frontier.ffxiv.localhost:80 { reverse_proxy :5857 } @@ -24,4 +28,4 @@ patch-gamever.ffxiv.localhost:80 { ffxiv-login.square.localhost:80 { reverse_proxy :6700 -} \ No newline at end of file +} diff --git a/scripts/run.sh b/scripts/run.sh index 234020f..8bb51fd 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -9,4 +9,5 @@ cargo run -q --package kawari --features oodle --bin kawari-patch & cargo run -q --package kawari --features oodle --bin kawari-web & cargo run -q --package kawari --features oodle --bin kawari-lobby & cargo run -q --package kawari --features oodle --bin kawari-world & +cargo run -q --package kawari --features oodle --bin kawari-launcher & wait diff --git a/src/bin/kawari-launcher.rs b/src/bin/kawari-launcher.rs new file mode 100644 index 0000000..68d31c3 --- /dev/null +++ b/src/bin/kawari-launcher.rs @@ -0,0 +1,42 @@ +use axum::response::Html; +use axum::{Router, routing::get}; +use kawari::config::get_config; +use minijinja::Environment; +use minijinja::context; + +fn setup_default_environment() -> Environment<'static> { + let mut env = Environment::new(); + env.add_template( + "launcher.html", + include_str!("../../templates/launcher.html"), + ) + .unwrap(); + + env +} + +async fn root() -> Html { + let config = get_config(); + + let environment = setup_default_environment(); + let template = environment.get_template("launcher.html").unwrap(); + Html( + template + .render(context! { login_server => config.login.server_name }) + .unwrap(), + ) +} + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + + let app = Router::new().route("/v700", get(root)); + + let config = get_config(); + + let addr = config.launcher.get_socketaddr(); + tracing::info!("Server started on {addr}"); + let listener = tokio::net::TcpListener::bind(addr).await.unwrap(); + axum::serve(listener, app).await.unwrap(); +} diff --git a/src/config.rs b/src/config.rs index e140b03..b9fe867 100644 --- a/src/config.rs +++ b/src/config.rs @@ -263,6 +263,32 @@ impl WorldConfig { } } +/// Configuration for the launcher server. +#[derive(Serialize, Deserialize)] +pub struct LauncherConfig { + pub port: u16, + pub listen_address: String, +} + +impl Default for LauncherConfig { + fn default() -> Self { + Self { + port: 5802, + listen_address: "127.0.0.1".to_string(), + } + } +} + +impl LauncherConfig { + /// Returns the configured IP address & port as a `SocketAddr`. + pub fn get_socketaddr(&self) -> SocketAddr { + SocketAddr::from(( + IpAddr::from_str(&self.listen_address).expect("Invalid IP address format in config!"), + self.port, + )) + } +} + /// Global and all-encompassing config. /// Settings that affect all servers belong here. #[derive(Serialize, Deserialize)] @@ -294,6 +320,9 @@ pub struct Config { #[serde(default)] pub world: WorldConfig, + #[serde(default)] + pub launcher: LauncherConfig, + /// Enable various packet debug functions. This will clutter your working directory! #[serde(default)] pub packet_debugging: bool, @@ -311,6 +340,7 @@ impl Default for Config { patch: PatchConfig::default(), web: WebConfig::default(), world: WorldConfig::default(), + launcher: LauncherConfig::default(), packet_debugging: false, } } diff --git a/templates/launcher.html b/templates/launcher.html new file mode 100644 index 0000000..8100a25 --- /dev/null +++ b/templates/launcher.html @@ -0,0 +1,70 @@ + + + + + + Kawari Launcher + + + +

Welcome to Kawari!

+ + + + + + + + + + + + + +

meh

+ + + +