1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-07-10 16:07:45 +00:00

Unify version and file checking behind one config parameter

And make it affect the patch server as well, if you really want to
use an unsupported version.
This commit is contained in:
Joshua Goins 2025-07-04 11:56:12 -04:00
parent 70c423e48f
commit 7ccd132129
3 changed files with 108 additions and 84 deletions

View file

@ -224,7 +224,7 @@ async fn main() {
let config = get_config(); let config = get_config();
// The lobby server does its own version check as well, but it can be turned off if desired. // The lobby server does its own version check as well, but it can be turned off if desired.
if config.lobby.do_version_checks if config.enforce_validity_checks
&& !do_game_version_check(version_info) && !do_game_version_check(version_info)
{ {
// "A version update is required." // "A version update is required."

View file

@ -88,7 +88,10 @@ async fn verify_session(
return StatusCode::INTERNAL_SERVER_ERROR.into_response(); return StatusCode::INTERNAL_SERVER_ERROR.into_response();
} }
tracing::info!("Verifying game components for {platform} {channel} {game_version} {body}..."); if config.enforce_validity_checks {
tracing::info!(
"Verifying game components for {platform} {channel} {game_version} {body}..."
);
let body_parts: Vec<&str> = body.split('\n').collect(); let body_parts: Vec<&str> = body.split('\n').collect();
@ -115,12 +118,16 @@ async fn verify_session(
// Their version is too new // Their version is too new
if game_version > SUPPORTED_GAME_VERSION { if game_version > SUPPORTED_GAME_VERSION {
tracing::warn!("{game_version} is above supported game version {SUPPORTED_GAME_VERSION}!"); tracing::warn!(
"{game_version} is above supported game version {SUPPORTED_GAME_VERSION}!"
);
return StatusCode::INTERNAL_SERVER_ERROR.into_response(); return StatusCode::INTERNAL_SERVER_ERROR.into_response();
} }
if game_version < SUPPORTED_GAME_VERSION { if game_version < SUPPORTED_GAME_VERSION {
tracing::warn!("{game_version} is below supported game version {SUPPORTED_GAME_VERSION}!"); tracing::warn!(
"{game_version} is below supported game version {SUPPORTED_GAME_VERSION}!"
);
return StatusCode::INTERNAL_SERVER_ERROR.into_response(); return StatusCode::INTERNAL_SERVER_ERROR.into_response();
} }
@ -131,6 +138,7 @@ async fn verify_session(
return (headers).into_response(); return (headers).into_response();
} }
}
let mut headers = HeaderMap::new(); let mut headers = HeaderMap::new();
headers.insert("X-Patch-Unique-Id", sid.parse().unwrap()); headers.insert("X-Patch-Unique-Id", sid.parse().unwrap());
@ -147,6 +155,12 @@ async fn verify_boot(
return StatusCode::INTERNAL_SERVER_ERROR.into_response(); return StatusCode::INTERNAL_SERVER_ERROR.into_response();
} }
let config = get_config();
if !config.supports_platform(&platform) {
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
}
if config.enforce_validity_checks {
tracing::info!("Verifying boot components for {platform} {channel} {boot_version}..."); tracing::info!("Verifying boot components for {platform} {channel} {boot_version}...");
let config = get_config(); let config = get_config();
@ -166,7 +180,9 @@ async fn verify_boot(
// Their version is too new // Their version is too new
if boot_version > SUPPORTED_BOOT_VERSION { if boot_version > SUPPORTED_BOOT_VERSION {
tracing::warn!("{boot_version} is above supported boot version {SUPPORTED_BOOT_VERSION}!"); tracing::warn!(
"{boot_version} is above supported boot version {SUPPORTED_BOOT_VERSION}!"
);
return StatusCode::INTERNAL_SERVER_ERROR.into_response(); return StatusCode::INTERNAL_SERVER_ERROR.into_response();
} }
@ -208,6 +224,7 @@ async fn verify_boot(
let patch_list_str = patch_list.to_string(PatchListType::Boot); let patch_list_str = patch_list.to_string(PatchListType::Boot);
return patch_list_str.into_response(); return patch_list_str.into_response();
} }
}
let headers = HeaderMap::new(); let headers = HeaderMap::new();
(headers).into_response() (headers).into_response()

View file

@ -66,7 +66,6 @@ impl FrontierConfig {
pub struct LobbyConfig { pub struct LobbyConfig {
pub port: u16, pub port: u16,
pub listen_address: String, pub listen_address: String,
pub do_version_checks: bool,
} }
impl Default for LobbyConfig { impl Default for LobbyConfig {
@ -74,7 +73,6 @@ impl Default for LobbyConfig {
Self { Self {
port: 7000, port: 7000,
listen_address: "0.0.0.0".to_string(), listen_address: "0.0.0.0".to_string(),
do_version_checks: true,
} }
} }
} }
@ -401,6 +399,10 @@ pub struct Config {
/// Enable various packet debug functions. This will clutter your working directory! /// Enable various packet debug functions. This will clutter your working directory!
#[serde(default)] #[serde(default)]
pub packet_debugging: bool, pub packet_debugging: bool,
/// Enable various validity checks for version and file hashes that emulate retail.
#[serde(default = "Config::default_enforce_validity_checks")]
pub enforce_validity_checks: bool,
} }
impl Default for Config { impl Default for Config {
@ -418,6 +420,7 @@ impl Default for Config {
launcher: LauncherConfig::default(), launcher: LauncherConfig::default(),
save_data_bank: SaveDataBankConfig::default(), save_data_bank: SaveDataBankConfig::default(),
packet_debugging: false, packet_debugging: false,
enforce_validity_checks: Self::default_enforce_validity_checks(),
} }
} }
} }
@ -426,6 +429,10 @@ impl Config {
pub fn supports_platform(&self, platform: &String) -> bool { pub fn supports_platform(&self, platform: &String) -> bool {
self.supported_platforms.contains(platform) self.supported_platforms.contains(platform)
} }
fn default_enforce_validity_checks() -> bool {
true
}
} }
fn default_supported_platforms() -> Vec<String> { fn default_supported_platforms() -> Vec<String> {