diff --git a/src/bin/kawari-admin.rs b/src/bin/kawari-admin.rs index 248168d..583dd18 100644 --- a/src/bin/kawari-admin.rs +++ b/src/bin/kawari-admin.rs @@ -8,15 +8,7 @@ use axum::{ use serde::{Deserialize, Serialize}; use axum::response::{Html, Redirect}; use axum::routing::post; -use kawari::config::Config; - -fn get_config() -> Config { - if let Ok(data) = std::fs::read_to_string("config.json") { - serde_json::from_str(&data).expect("Failed to parse") - } else { - Config::default() - } -} +use kawari::config::{Config, get_config}; #[derive(Debug, Clone, Serialize, Deserialize)] struct GateStatus { diff --git a/src/bin/kawari-patch.rs b/src/bin/kawari-patch.rs index f9078b9..ffc34ce 100644 --- a/src/bin/kawari-patch.rs +++ b/src/bin/kawari-patch.rs @@ -5,22 +5,31 @@ use axum::extract::Query; use axum::response::Html; use axum::routing::post; use serde::{Deserialize, Serialize}; -use kawari::config::Config; +use kawari::config::{Config, get_config}; use axum::extract::Path; use axum::response::IntoResponse; -use axum::http::HeaderMap; +use axum::http::{HeaderMap, StatusCode}; + +async fn verify_session(Path((platform, game_version, sid)): Path<(String, String, String)>) -> impl IntoResponse { + let config = get_config(); + if !config.supports_platform(&platform) { + return StatusCode::INTERNAL_SERVER_ERROR.into_response(); + } -async fn verify_session(Path((game_version, sid)): Path<(String, String)>) -> impl IntoResponse { let mut headers = HeaderMap::new(); headers.insert("X-Patch-Unique-Id", sid.parse().unwrap()); - (headers) + (headers).into_response() } -async fn verify_boot(Path(boot_version): Path) -> impl IntoResponse { - let mut headers = HeaderMap::new(); +async fn verify_boot(Path((platform, boot_version)): Path<(String, String)>) -> impl IntoResponse { + let config = get_config(); + if !config.supports_platform(&platform) { + return StatusCode::INTERNAL_SERVER_ERROR.into_response(); + } - (headers) + let mut headers = HeaderMap::new(); + (headers).into_response() } #[tokio::main] @@ -28,8 +37,8 @@ async fn main() { tracing_subscriber::fmt::init(); let app = Router::new() - .route("/http/win32/ffxivneo_release_game/:game_version/:sid", post(verify_session)) - .route("/http/win32/ffxivneo_release_boot/:boot_version", get(verify_boot)); + .route("/http/:platform/ffxivneo_release_game/:game_version/:sid", post(verify_session)) + .route("/http/:platform/ffxivneo_release_boot/:boot_version", get(verify_boot)); let addr = SocketAddr::from(([127, 0, 0, 1], 6900)); tracing::info!("Patch server started on {}", addr); diff --git a/src/config.rs b/src/config.rs index 166c80d..f89e815 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,13 +2,36 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] pub struct Config { - pub gate_open: bool + #[serde(default)] + pub gate_open: bool, + + #[serde(default = "default_supported_platforms")] + pub supported_platforms: Vec, } impl Default for Config { fn default() -> Self { Self { gate_open: false, + supported_platforms: default_supported_platforms() } } +} + +impl Config { + pub fn supports_platform(&self, platform: &String) -> bool { + self.supported_platforms.contains(platform) + } +} + +fn default_supported_platforms() -> Vec { + vec!["win32".to_string()] +} + +pub fn get_config() -> Config { + if let Ok(data) = std::fs::read_to_string("config.json") { + serde_json::from_str(&data).expect("Failed to parse") + } else { + Config::default() + } } \ No newline at end of file