mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-04 15:27:48 +00:00
chore: remove dead service
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -19,7 +19,7 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.11.3"
|
version = "0.11.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake3",
|
"blake3",
|
||||||
"colored",
|
"colored",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "alterware-launcher"
|
name = "alterware-launcher"
|
||||||
version = "0.11.3"
|
version = "0.11.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "res/build.rs"
|
build = "res/build.rs"
|
||||||
|
|
||||||
|
|||||||
@@ -146,8 +146,6 @@
|
|||||||
- Install or reinstall redistributables
|
- Install or reinstall redistributables
|
||||||
- ```--prerelease```
|
- ```--prerelease```
|
||||||
- Update to prerelease version of the launcher
|
- Update to prerelease version of the launcher
|
||||||
- ```--rate```
|
|
||||||
- Rate and display CDN servers
|
|
||||||
- ```--cdn-url```
|
- ```--cdn-url```
|
||||||
- ```--offline```
|
- ```--offline```
|
||||||
- ```--skip-connectivity-check```
|
- ```--skip-connectivity-check```
|
||||||
|
|||||||
184
src/cdn.rs
184
src/cdn.rs
@@ -6,93 +6,19 @@ use std::time::Duration;
|
|||||||
|
|
||||||
static CURRENT_CDN: Mutex<Option<Arc<Server>>> = Mutex::new(None);
|
static CURRENT_CDN: Mutex<Option<Arc<Server>>> = 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)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
pub host: &'static str,
|
pub host: &'static str,
|
||||||
pub rating: u8,
|
pub rating: u8,
|
||||||
pub latency: Option<std::time::Duration>,
|
pub latency: Option<std::time::Duration>,
|
||||||
pub region: Region,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
pub const fn new(host: &'static str, region: Region) -> Self {
|
pub const fn new(host: &'static str) -> Self {
|
||||||
Server {
|
Server {
|
||||||
host,
|
host,
|
||||||
rating: 255,
|
rating: 255,
|
||||||
latency: None,
|
latency: None,
|
||||||
region,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +26,7 @@ impl Server {
|
|||||||
format!("https://{}/", self.host)
|
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 {
|
let timeout = if is_initial {
|
||||||
Duration::from_millis(1000)
|
Duration::from_millis(1000)
|
||||||
} else {
|
} else {
|
||||||
@@ -109,16 +35,15 @@ impl Server {
|
|||||||
match http::rating_request(&self.url(), timeout).await {
|
match http::rating_request(&self.url(), timeout).await {
|
||||||
Ok((latency, is_cloudflare)) => {
|
Ok((latency, is_cloudflare)) => {
|
||||||
self.latency = Some(latency);
|
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!(
|
info!(
|
||||||
"Server {} rated {} ({}ms, rating: {}, cloudflare: {}, region: {:?})",
|
"Server {} rated {} ({}ms, rating: {}, cloudflare: {})",
|
||||||
self.host,
|
self.host,
|
||||||
self.rating,
|
self.rating,
|
||||||
latency.as_millis(),
|
latency.as_millis(),
|
||||||
self.rating,
|
self.rating,
|
||||||
is_cloudflare,
|
is_cloudflare,
|
||||||
self.region
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -147,13 +72,7 @@ impl Server {
|
|||||||
rating.clamp(1.0, 255.0) as u8
|
rating.clamp(1.0, 255.0) as u8
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_rating(
|
fn calculate_rating(&self, latency: std::time::Duration, is_cloudflare: bool, asn: u32) -> u8 {
|
||||||
&self,
|
|
||||||
latency: std::time::Duration,
|
|
||||||
is_cloudflare: bool,
|
|
||||||
asn: u32,
|
|
||||||
user_region: Region,
|
|
||||||
) -> u8 {
|
|
||||||
let mut rating = self.rate_latency(latency);
|
let mut rating = self.rate_latency(latency);
|
||||||
|
|
||||||
// Additional factors for full rating
|
// 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
|
rating
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,23 +98,13 @@ impl Hosts {
|
|||||||
pub async fn new() -> Self {
|
pub async fn new() -> Self {
|
||||||
let cdn_hosts = crate::global::CDN_HOSTS.to_vec();
|
let cdn_hosts = crate::global::CDN_HOSTS.to_vec();
|
||||||
|
|
||||||
let mut hosts = Hosts {
|
let hosts = Hosts {
|
||||||
servers: cdn_hosts,
|
servers: cdn_hosts,
|
||||||
active_index: RwLock::new(None),
|
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) {
|
if hosts.servers.iter().all(|server| server.rating == 0) {
|
||||||
info!("All CDN servers failed with 1000ms timeout, retrying with 5000ms timeout");
|
info!("All CDN servers failed with 1000ms timeout, retrying with 5000ms timeout");
|
||||||
hosts.rate(asn, user_region, false).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hosts
|
hosts
|
||||||
@@ -250,11 +140,11 @@ impl Hosts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// rate and order all servers, then select the best one
|
/// 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
|
let rating_futures: Vec<_> = self
|
||||||
.servers
|
.servers
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|server| server.rate(asn, user_region, is_initial))
|
.map(|server| server.rate(asn, is_initial))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
join_all(rating_futures).await;
|
join_all(rating_futures).await;
|
||||||
@@ -270,61 +160,3 @@ impl Hosts {
|
|||||||
self.active_url()
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,19 +6,17 @@ use std::future::Future;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use crate::cdn::{Hosts, Region, Server};
|
use crate::cdn::{Hosts, Server};
|
||||||
|
|
||||||
pub const GH_OWNER: &str = "alterware";
|
pub const GH_OWNER: &str = "alterware";
|
||||||
pub const GH_REPO: &str = "alterware-launcher";
|
pub const GH_REPO: &str = "alterware-launcher";
|
||||||
pub const DEFAULT_MASTER: &str = "https://cdn.alterware.ovh";
|
pub const DEFAULT_MASTER: &str = "https://cdn.alterware.ovh";
|
||||||
|
|
||||||
pub const CDN_HOSTS: [Server; 2] = [
|
pub const CDN_HOSTS: [Server; 2] = [
|
||||||
Server::new("cdn.alterware.ovh", Region::Global),
|
Server::new("cdn.alterware.ovh"),
|
||||||
Server::new("us-cdn.alterware.ovh", Region::NorthAmerica),
|
Server::new("us-cdn.alterware.ovh"),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const IP2ASN: &str = "https://ip2asn.getserve.rs/v1/as/ip/self";
|
|
||||||
|
|
||||||
pub static USER_AGENT: Lazy<String> = Lazy::new(|| {
|
pub static USER_AGENT: Lazy<String> = Lazy::new(|| {
|
||||||
format!(
|
format!(
|
||||||
"AlterWare Launcher v{} on {} | github.com/{}/{}",
|
"AlterWare Launcher v{} on {} | github.com/{}/{}",
|
||||||
|
|||||||
21
src/http.rs
21
src/http.rs
@@ -1,5 +1,4 @@
|
|||||||
use reqwest::header::HeaderMap;
|
use reqwest::header::HeaderMap;
|
||||||
use serde_json::Value;
|
|
||||||
use simple_log::*;
|
use simple_log::*;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
@@ -81,23 +80,3 @@ pub async fn rating_request(
|
|||||||
info!("Successfully rated {url} in {latency:?} (cloudflare: {is_cloudflare})");
|
info!("Successfully rated {url} in {latency:?} (cloudflare: {is_cloudflare})");
|
||||||
Ok((latency, 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::<Value>(&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())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -627,7 +627,6 @@ async fn main() {
|
|||||||
println!(" --prerelease: Update to prerelease version of clients and launcher");
|
println!(" --prerelease: Update to prerelease version of clients and launcher");
|
||||||
println!(" --offline: Run in offline mode");
|
println!(" --offline: Run in offline mode");
|
||||||
println!(" --skip-connectivity-check: Don't check connectivity");
|
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\"");
|
println!("\nExample:\n alterware-launcher.exe iw6 --pass \"-headless\"");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -663,11 +662,6 @@ async fn main() {
|
|||||||
install_path = env::current_dir().unwrap();
|
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"));
|
let mut cfg = config::load(install_path.join("alterware-launcher.json"));
|
||||||
|
|
||||||
if let Some(cdn_url) = arg_value(&args, "--cdn-url") {
|
if let Some(cdn_url) = arg_value(&args, "--cdn-url") {
|
||||||
|
|||||||
Reference in New Issue
Block a user