From 695a8174c89514e697ee3aa874ed9b803bfc5c56 Mon Sep 17 00:00:00 2001 From: alterware Date: Fri, 21 Nov 2025 16:29:45 +0100 Subject: [PATCH] chore: remove dead service --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 - src/cdn.rs | 184 +++----------------------------------------------- src/global.rs | 8 +-- src/http.rs | 21 ------ src/main.rs | 6 -- 7 files changed, 13 insertions(+), 212 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92fd5ba..fe5f4d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "alterware-launcher" -version = "0.11.3" +version = "0.11.4" dependencies = [ "blake3", "colored", diff --git a/Cargo.toml b/Cargo.toml index d898076..cc04421 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alterware-launcher" -version = "0.11.3" +version = "0.11.4" edition = "2021" build = "res/build.rs" diff --git a/README.md b/README.md index ffaf38a..61c6cb3 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,6 @@ - Install or reinstall redistributables - ```--prerelease``` - Update to prerelease version of the launcher -- ```--rate``` - - Rate and display CDN servers - ```--cdn-url``` - ```--offline``` - ```--skip-connectivity-check``` diff --git a/src/cdn.rs b/src/cdn.rs index 2174de6..0cdbf88 100644 --- a/src/cdn.rs +++ b/src/cdn.rs @@ -6,93 +6,19 @@ use std::time::Duration; static CURRENT_CDN: Mutex>> = Mutex::new(None); -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum Region { - Africa, - Asia, - Europe, - NorthAmerica, - Oceania, - SouthAmerica, - Global, - Unknown, -} - -impl Region { - pub fn from_str(region_str: &str) -> Self { - match region_str { - "Africa" => Region::Africa, - "Asia" => Region::Asia, - "Europe" => Region::Europe, - "NorthAmerica" => Region::NorthAmerica, - "Oceania" => Region::Oceania, - "SouthAmerica" => Region::SouthAmerica, - _ => Region::Unknown, - } - } - - pub fn coordinates(&self) -> Option<(f64, f64)> { - match self { - Region::Europe => Some((54.0, 15.0)), - Region::Asia => Some((35.0, 105.0)), - Region::NorthAmerica => Some((45.0, -100.0)), - Region::SouthAmerica => Some((-15.0, -60.0)), - Region::Africa => Some((0.0, 20.0)), - Region::Oceania => Some((-25.0, 140.0)), - Region::Global => None, - Region::Unknown => None, - } - } - - pub fn distance_to(&self, other: Region) -> f64 { - if *self == Region::Global || other == Region::Global { - return 0.0; - } - - if *self == other { - return 0.0; - } - - let (lat1, lon1) = match self.coordinates() { - Some(coords) => coords, - None => return 20000.0, - }; - - let (lat2, lon2) = match other.coordinates() { - Some(coords) => coords, - None => return 20000.0, - }; - - // haversine - let r = 6371.0; - let d_lat = (lat2 - lat1).to_radians(); - let d_lon = (lon2 - lon1).to_radians(); - let lat1_rad = lat1.to_radians(); - let lat2_rad = lat2.to_radians(); - - let a = (d_lat / 2.0).sin().powi(2) - + lat1_rad.cos() * lat2_rad.cos() * (d_lon / 2.0).sin().powi(2); - let c = 2.0 * a.sqrt().atan2((1.0 - a).sqrt()); - - r * c - } -} - #[derive(Clone, Copy, Debug)] pub struct Server { pub host: &'static str, pub rating: u8, pub latency: Option, - pub region: Region, } impl Server { - pub const fn new(host: &'static str, region: Region) -> Self { + pub const fn new(host: &'static str) -> Self { Server { host, rating: 255, latency: None, - region, } } @@ -100,7 +26,7 @@ impl Server { format!("https://{}/", self.host) } - async fn rate(&mut self, asn: u32, user_region: Region, is_initial: bool) { + async fn rate(&mut self, asn: u32, is_initial: bool) { let timeout = if is_initial { Duration::from_millis(1000) } else { @@ -109,16 +35,15 @@ impl Server { match http::rating_request(&self.url(), timeout).await { Ok((latency, is_cloudflare)) => { self.latency = Some(latency); - self.rating = self.calculate_rating(latency, is_cloudflare, asn, user_region); + self.rating = self.calculate_rating(latency, is_cloudflare, asn); info!( - "Server {} rated {} ({}ms, rating: {}, cloudflare: {}, region: {:?})", + "Server {} rated {} ({}ms, rating: {}, cloudflare: {})", self.host, self.rating, latency.as_millis(), self.rating, is_cloudflare, - self.region ); } Err(e) => { @@ -147,13 +72,7 @@ impl Server { rating.clamp(1.0, 255.0) as u8 } - fn calculate_rating( - &self, - latency: std::time::Duration, - is_cloudflare: bool, - asn: u32, - user_region: Region, - ) -> u8 { + fn calculate_rating(&self, latency: std::time::Duration, is_cloudflare: bool, asn: u32) -> u8 { let mut rating = self.rate_latency(latency); // Additional factors for full rating @@ -165,25 +84,6 @@ impl Server { } } - let distance_km = user_region.distance_to(self.region); - let region_multiplier = if self.region == Region::Global { - 1.4 - } else if distance_km == 0.0 { - 1.3 - } else if user_region == Region::Unknown { - 1.0 - } else if distance_km <= 2000.0 { - 1.25 - } else if distance_km <= 5000.0 { - 1.15 - } else if distance_km <= 10000.0 { - 1.05 - } else { - 1.0 - }; - - rating = (rating as f32 * region_multiplier).min(255.0) as u8; - rating } } @@ -198,23 +98,13 @@ impl Hosts { pub async fn new() -> Self { let cdn_hosts = crate::global::CDN_HOSTS.to_vec(); - let mut hosts = Hosts { + let hosts = Hosts { servers: cdn_hosts, active_index: RwLock::new(None), }; - let (asn, region_str) = crate::http::get_location_info().await; - let user_region = Region::from_str(®ion_str); - info!( - "Detected user region as {:?} (region: {})", - user_region, region_str - ); - - hosts.rate(asn, user_region, true).await; - if hosts.servers.iter().all(|server| server.rating == 0) { info!("All CDN servers failed with 1000ms timeout, retrying with 5000ms timeout"); - hosts.rate(asn, user_region, false).await; } hosts @@ -250,11 +140,11 @@ impl Hosts { } /// rate and order all servers, then select the best one - pub async fn rate(&mut self, asn: u32, user_region: Region, is_initial: bool) { + pub async fn rate(&mut self, asn: u32, is_initial: bool) { let rating_futures: Vec<_> = self .servers .iter_mut() - .map(|server| server.rate(asn, user_region, is_initial)) + .map(|server| server.rate(asn, is_initial)) .collect(); join_all(rating_futures).await; @@ -270,61 +160,3 @@ impl Hosts { self.active_url() } } - -/// CDN rating function for --rate flag -pub async fn rate_cdns_and_display() { - use colored::Colorize; - - let (asn, region_str) = crate::http::get_location_info().await; - let user_region = Region::from_str(®ion_str); - - if user_region == Region::Unknown { - println!( - "User region: {} (using Global server preference)", - "Unknown".bright_red() - ); - } else { - println!("User region: {user_region:?}"); - } - - println!("Rating CDNs..."); - - let cdn_hosts = crate::global::CDN_HOSTS.to_vec(); - - let mut hosts = Hosts { - servers: cdn_hosts, - active_index: RwLock::new(None), - }; - - hosts.rate(asn, user_region, true).await; - - if hosts.servers.iter().all(|server| server.rating == 0) { - println!("Retrying with longer timeout..."); - hosts.rate(asn, user_region, false).await; - } - - println!(); - for server in hosts.servers.iter() { - let latency_str = server - .latency - .map_or("timeout".to_string(), |l| format!("{} ms", l.as_millis())); - - println!( - "{}: rating {}, latency {}", - server.host.bright_white(), - server.rating.to_string().bright_cyan(), - latency_str - ); - } - - // Show selected CDN - if hosts.next() { - if let Some(best_url) = hosts.active_url() { - println!(); - println!("Selected: {}", best_url.bright_green()); - } - } else { - println!(); - println!("{}", "No available CDN servers".bright_red()); - } -} diff --git a/src/global.rs b/src/global.rs index f0a89ae..5f11fba 100644 --- a/src/global.rs +++ b/src/global.rs @@ -6,19 +6,17 @@ use std::future::Future; use std::pin::Pin; use std::sync::Mutex; -use crate::cdn::{Hosts, Region, Server}; +use crate::cdn::{Hosts, Server}; pub const GH_OWNER: &str = "alterware"; pub const GH_REPO: &str = "alterware-launcher"; pub const DEFAULT_MASTER: &str = "https://cdn.alterware.ovh"; pub const CDN_HOSTS: [Server; 2] = [ - Server::new("cdn.alterware.ovh", Region::Global), - Server::new("us-cdn.alterware.ovh", Region::NorthAmerica), + Server::new("cdn.alterware.ovh"), + Server::new("us-cdn.alterware.ovh"), ]; -pub const IP2ASN: &str = "https://ip2asn.getserve.rs/v1/as/ip/self"; - pub static USER_AGENT: Lazy = Lazy::new(|| { format!( "AlterWare Launcher v{} on {} | github.com/{}/{}", diff --git a/src/http.rs b/src/http.rs index 2e09c90..a1c675f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,5 +1,4 @@ use reqwest::header::HeaderMap; -use serde_json::Value; use simple_log::*; use std::time::{Duration, Instant}; @@ -81,23 +80,3 @@ pub async fn rating_request( info!("Successfully rated {url} in {latency:?} (cloudflare: {is_cloudflare})"); Ok((latency, is_cloudflare)) } - -/// Retrieve client ASN and region -pub async fn get_location_info() -> (u32, String) { - let response = quick_request(crate::global::IP2ASN).await; - if let Ok(as_data_str) = response { - if let Ok(as_data) = serde_json::from_str::(&as_data_str) { - let as_number = as_data - .get("as_number") - .and_then(|v| v.as_u64()) - .unwrap_or(0) as u32; - let region = as_data - .get("region") - .and_then(|v| v.as_str()) - .unwrap_or("Unknown") - .to_string(); - return (as_number, region); - } - } - (0, "Unknown".to_string()) -} diff --git a/src/main.rs b/src/main.rs index 37ff97c..2ce10c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -627,7 +627,6 @@ async fn main() { println!(" --prerelease: Update to prerelease version of clients and launcher"); println!(" --offline: Run in offline mode"); println!(" --skip-connectivity-check: Don't check connectivity"); - println!(" --rate: Display CDN rating information and exit"); println!("\nExample:\n alterware-launcher.exe iw6 --pass \"-headless\""); return; } @@ -663,11 +662,6 @@ async fn main() { install_path = env::current_dir().unwrap(); } - if arg_bool(&args, "--rate") { - cdn::rate_cdns_and_display().await; - return; - } - let mut cfg = config::load(install_path.join("alterware-launcher.json")); if let Some(cdn_url) = arg_value(&args, "--cdn-url") {