diff --git a/src/bin/kawari-patch.rs b/src/bin/kawari-patch.rs index 92a6290..a9ba9b4 100644 --- a/src/bin/kawari-patch.rs +++ b/src/bin/kawari-patch.rs @@ -61,9 +61,23 @@ fn list_patch_files(dir_path: &str) -> Vec { .collect() } +/// Check if it's a valid patch client connecting +fn check_valid_patch_client(headers: &HeaderMap) -> bool { + let Some(user_agent) = headers.get("User-Agent") else { + return false; + }; + + user_agent == "FFXIV PATCH CLIENT" +} + async fn verify_session( - Path((platform, _, sid)): Path<(String, String, String)>, + headers: HeaderMap, + Path((platform, channel, game_version, sid)): Path<(String, String, String, String)>, ) -> impl IntoResponse { + if !check_valid_patch_client(&headers) { + return StatusCode::INTERNAL_SERVER_ERROR.into_response(); + } + let config = get_config(); if !config.supports_platform(&platform) { return StatusCode::INTERNAL_SERVER_ERROR.into_response(); @@ -75,8 +89,15 @@ async fn verify_session( (headers).into_response() } -async fn verify_boot(Path((platform, boot_version)): Path<(String, String)>) -> impl IntoResponse { - tracing::info!("Verifying boot components..."); +async fn verify_boot( + headers: HeaderMap, + Path((platform, channel, boot_version)): Path<(String, String, String)>, +) -> impl IntoResponse { + if !check_valid_patch_client(&headers) { + return StatusCode::INTERNAL_SERVER_ERROR.into_response(); + } + + tracing::info!("Verifying boot components for {platform} {channel} {boot_version}..."); let config = get_config(); if !config.supports_platform(&platform) { @@ -123,13 +144,13 @@ async fn main() { let app = Router::new() .route( - "/http/{platform}/ffxivneo_release_game/{game_version}/{sid}", + "/http/{platform}/{channel}/{game_version}/{sid}", post(verify_session), ) .route( - "/http/{platform}/ffxivneo_release_boot/{*boot_version}", + "/http/{platform}/{channel}/{boot_version}", get(verify_boot), - ); // NOTE: for future programmers, this is a wildcard because axum hates the /version/?time=blah format. + ); let config = get_config(); diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 1b31cfc..138e7eb 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use kawari::common::custom_ipc::{CustomIpcData, CustomIpcSegment, CustomIpcType}; use kawari::common::timestamp_secs; -use kawari::common::{determine_initial_starting_zone, get_citystate, get_world_name, Position}; +use kawari::common::{Position, determine_initial_starting_zone, get_citystate, get_world_name}; use kawari::config::get_config; use kawari::lobby::CharaMake; use kawari::oodle::OodleNetwork; @@ -17,7 +17,8 @@ use kawari::world::ipc::{ use kawari::world::{ ChatHandler, Zone, ZoneConnection, ipc::{ - ActorControlCategory, ActorControlSelf, PlayerEntry, PlayerSetup, PlayerSpawn, PlayerStats, SocialList, + ActorControlCategory, ActorControlSelf, PlayerEntry, PlayerSetup, PlayerSpawn, PlayerStats, + SocialList, }, }; use kawari::world::{PlayerData, WorldDatabase};