feat(bootstrap): implement server region selector and FastFlag network routing
This commit is contained in:
parent
17a7dbb1ec
commit
a4d6cce7f4
3 changed files with 79 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
59
crates/molotov-bootstrap/src/region.rs
Normal file
59
crates/molotov-bootstrap/src/region.rs
Normal file
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
19
crates/molotov-bootstrap/tests/region_test.rs
Normal file
19
crates/molotov-bootstrap/tests/region_test.rs
Normal file
|
|
@ -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())
|
||||
);
|
||||
}
|
||||
Reference in a new issue