1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-20 22:57:45 +00:00

Check user-agent in Patch server

This commit is contained in:
Joshua Goins 2025-03-23 07:25:23 -04:00
parent d92f0033a9
commit b3f5500d2f
2 changed files with 30 additions and 8 deletions

View file

@ -61,9 +61,23 @@ fn list_patch_files(dir_path: &str) -> Vec<String> {
.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();

View file

@ -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};