1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-08 17:37:46 +00:00

Add supported platforms config option

This commit is contained in:
Joshua Goins 2024-05-11 13:41:00 -04:00
parent 73679a35fe
commit 7d2765a2b6
3 changed files with 43 additions and 19 deletions

View file

@ -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 {

View file

@ -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<String>) -> 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);

View file

@ -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<String>,
}
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<String> {
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()
}
}