From a4d6cce7f43950ec79ff844933067f92e1d09b1c Mon Sep 17 00:00:00 2001 From: oiupoyt Date: Thu, 1 Oct 2026 22:43:51 +0530 Subject: [PATCH] feat(bootstrap): implement server region selector and FastFlag network routing --- crates/molotov-bootstrap/src/lib.rs | 1 + crates/molotov-bootstrap/src/region.rs | 59 +++++++++++++++++++ crates/molotov-bootstrap/tests/region_test.rs | 19 ++++++ 3 files changed, 79 insertions(+) create mode 100644 crates/molotov-bootstrap/src/region.rs create mode 100644 crates/molotov-bootstrap/tests/region_test.rs diff --git a/crates/molotov-bootstrap/src/lib.rs b/crates/molotov-bootstrap/src/lib.rs index 4c4f196..ac0930e 100644 --- a/crates/molotov-bootstrap/src/lib.rs +++ b/crates/molotov-bootstrap/src/lib.rs @@ -5,5 +5,6 @@ pub mod cleaner; pub mod error; pub mod fflags; pub mod mods; +pub mod region; pub mod sandbox; pub mod watchdog; diff --git a/crates/molotov-bootstrap/src/region.rs b/crates/molotov-bootstrap/src/region.rs new file mode 100644 index 0000000..51c6b56 --- /dev/null +++ b/crates/molotov-bootstrap/src/region.rs @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +use crate::fflags::{FastFlagManager, FlagValue}; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum ServerRegion { + #[default] + Auto, + USEast, + USWest, + Europe, + Asia, + Australia, + SouthAmerica, +} + +impl ServerRegion { + pub fn from_code(code: &str) -> Self { + let clean = code.trim().to_lowercase(); + match clean.as_str() { + "us-east" | "useast" | "virginia" => ServerRegion::USEast, + "us-west" | "uswest" | "california" => ServerRegion::USWest, + "eu" | "europe" | "frankfurt" | "london" => ServerRegion::Europe, + "asia" | "tokyo" | "singapore" => ServerRegion::Asia, + "aus" | "australia" | "sydney" => ServerRegion::Australia, + "sa" | "south-america" | "brazil" => ServerRegion::SouthAmerica, + _ => ServerRegion::Auto, + } + } + + pub fn display_name(&self) -> &'static str { + match self { + ServerRegion::Auto => "Auto / Default", + ServerRegion::USEast => "US East (Virginia)", + ServerRegion::USWest => "US West (California)", + ServerRegion::Europe => "Europe (Frankfurt / London)", + ServerRegion::Asia => "Asia (Tokyo / Singapore)", + ServerRegion::Australia => "Australia (Sydney)", + ServerRegion::SouthAmerica => "South America (São Paulo)", + } + } + + pub fn region_identifier(&self) -> Option<&'static str> { + match self { + ServerRegion::Auto => None, + ServerRegion::USEast => Some("us-east-1"), + ServerRegion::USWest => Some("us-west-1"), + ServerRegion::Europe => Some("eu-central-1"), + ServerRegion::Asia => Some("ap-northeast-1"), + ServerRegion::Australia => Some("ap-southeast-2"), + ServerRegion::SouthAmerica => Some("sa-east-1"), + } + } + + pub fn apply_to_fflags(&self, manager: &mut FastFlagManager) { + if let Some(id) = self.region_identifier() { + manager.set_flag("FStringPreferredGameRegion", FlagValue::Text(id.to_string())); + } + } +} diff --git a/crates/molotov-bootstrap/tests/region_test.rs b/crates/molotov-bootstrap/tests/region_test.rs new file mode 100644 index 0000000..9dc96f5 --- /dev/null +++ b/crates/molotov-bootstrap/tests/region_test.rs @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +use molotov_bootstrap::fflags::FastFlagManager; +use molotov_bootstrap::region::ServerRegion; + +#[test] +fn test_server_region_parsing_and_flags() { + assert_eq!(ServerRegion::from_code("eu"), ServerRegion::Europe); + assert_eq!(ServerRegion::from_code("us-east"), ServerRegion::USEast); + assert_eq!(ServerRegion::from_code("invalid_garbage"), ServerRegion::Auto); + + let mut manager = FastFlagManager::new(); + ServerRegion::Europe.apply_to_fflags(&mut manager); + + // Verify flag was applied + assert_eq!( + manager.active_profile().flags.get("FStringPreferredGameRegion").map(|v| format!("{:?}", v)), + Some("Text(\"eu-central-1\")".to_string()) + ); +}