more iw4x

This commit is contained in:
2025-06-10 23:34:53 +02:00
parent cde077ba76
commit 1b6ac98444
3 changed files with 48 additions and 35 deletions

View File

@@ -1,4 +1,3 @@
use crate::global::CDN_HOSTS;
use crate::http;
use futures::future::join_all;
use simple_log::*;
@@ -196,9 +195,15 @@ pub struct Hosts {
impl Hosts {
/// create new rated hosts instance
pub async fn new() -> Self {
pub async fn new(use_iw4x_cdns: bool) -> Self {
let cdn_hosts = if use_iw4x_cdns {
crate::global::IW4X_CDN_HOSTS.to_vec()
} else {
crate::global::CDN_HOSTS.to_vec()
};
let mut hosts = Hosts {
servers: CDN_HOSTS.to_vec(),
servers: cdn_hosts,
active_index: RwLock::new(None),
};
@@ -271,7 +276,7 @@ impl Hosts {
}
/// CDN rating function for --rate flag
pub async fn rate_cdns_and_display() {
pub async fn rate_cdns_and_display(use_iw4x_cdns: bool) {
use colored::Colorize;
let (asn, region_str) = crate::http::get_location_info().await;
@@ -285,10 +290,17 @@ pub async fn rate_cdns_and_display() {
} else {
println!("User region: {:?}", user_region);
}
println!("Rating CDNs...");
let cdn_hosts = if use_iw4x_cdns {
crate::global::IW4X_CDN_HOSTS.to_vec()
} else {
crate::global::CDN_HOSTS.to_vec()
};
let mut hosts = Hosts {
servers: CDN_HOSTS.to_vec(),
servers: cdn_hosts,
active_index: RwLock::new(None),
};

View File

@@ -14,10 +14,14 @@ pub const GH_IW4X_OWNER: &str = "iw4x";
pub const GH_IW4X_REPO: &str = "iw4x-client";
pub const DEFAULT_MASTER: &str = "https://cdn.alterware.ovh";
pub const CDN_HOSTS: [Server; 3] = [
pub const CDN_HOSTS: [Server; 2] = [
Server::new("cdn.alterware.ovh", Region::Global),
Server::new("us-cdn.alterware.ovh", Region::NorthAmerica),
];
pub const IW4X_CDN_HOSTS: [Server; 2] = [
Server::new("cdn.iw4x.dev", Region::Europe),
Server::new("cf-cdn.iw4x.dev", Region::Global),
];
pub const IP2ASN: &str = "https://ip2asn.getserve.rs/v1/as/ip/self";
@@ -83,10 +87,12 @@ pub static PREFIXES: Lazy<HashMap<&'static str, PrintPrefix>> = Lazy::new(|| {
])
});
pub async fn check_connectivity_and_rate_cdns() -> Pin<Box<dyn Future<Output = bool> + Send>> {
pub async fn check_connectivity_and_rate_cdns(
use_iw4x_cdns: bool,
) -> Pin<Box<dyn Future<Output = bool> + Send>> {
Box::pin(async move {
crate::println_info!("Initializing CDN rating system...");
let hosts = Hosts::new().await;
let hosts = Hosts::new(use_iw4x_cdns).await;
let best_cdn = hosts.get_master_url();
if let Some(cdn_url) = best_cdn {
@@ -129,7 +135,7 @@ pub fn check_connectivity(
}
}
} else {
check_connectivity_and_rate_cdns().await.await
check_connectivity_and_rate_cdns(false).await.await
}
})
}

View File

@@ -693,11 +693,6 @@ async fn main() {
return;
}
if arg_bool(&args, "--rate") {
cdn::rate_cdns_and_display().await;
return;
}
let install_path: PathBuf;
if let Some(path) = arg_value(&args, "--path") {
install_path = PathBuf::from(path);
@@ -709,6 +704,24 @@ async fn main() {
install_path = env::current_dir().unwrap();
}
let mut is_iw4x = false;
if args.len() > 1 && args[1] == "iw4x" {
is_iw4x = true;
} else {
let iw4x_reference_files = ["iw4mp.exe", "iw4sp.exe", "iw4x.exe"];
for ref_file in iw4x_reference_files.iter() {
if install_path.join(ref_file).exists() {
is_iw4x = true;
break;
}
}
}
if arg_bool(&args, "--rate") {
cdn::rate_cdns_and_display(is_iw4x).await;
return;
}
let mut cfg = config::load(install_path.join("alterware-launcher.json"));
if let Some(cdn_url) = arg_value(&args, "--cdn-url") {
@@ -737,7 +750,9 @@ async fn main() {
if initial_cdn.is_some() {
cfg.offline = !global::check_connectivity(initial_cdn).await;
} else {
cfg.offline = !global::check_connectivity_and_rate_cdns().await.await;
cfg.offline = !global::check_connectivity_and_rate_cdns(is_iw4x)
.await
.await;
}
}
@@ -872,26 +887,6 @@ async fn main() {
std::process::exit(0);
}
let mut is_iw4x = false;
if args.len() > 1 && args[1] == "iw4x" {
is_iw4x = true;
} else {
let iw4x_reference_files = ["iw4mp.exe", "iw4sp.exe", "iw4x.exe"];
for ref_file in iw4x_reference_files.iter() {
if install_path.join(ref_file).exists() {
is_iw4x = true;
break;
}
}
}
if is_iw4x {
let iw4x_cdn = "https://cdn.iw4x.dev";
*MASTER_URL.lock().unwrap() = iw4x_cdn.to_string();
crate::println_info!("Using IW4x CDN: {}", iw4x_cdn);
}
let games_json =
http_async::get_body_string(format!("{}/games.json", MASTER_URL.lock().unwrap()).as_str())
.await