added fallback setup server

This commit is contained in:
PrintedScript 2023-10-05 22:05:27 +08:00
parent 3caf9df527
commit ce068d9807
3 changed files with 28 additions and 14 deletions

2
Cargo.lock generated
View File

@ -1261,7 +1261,7 @@ dependencies = [
[[package]] [[package]]
name = "syntax_bootstrapper" name = "syntax_bootstrapper"
version = "1.1.0" version = "1.1.2"
dependencies = [ dependencies = [
"chrono", "chrono",
"colored", "colored",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "syntax_bootstrapper" name = "syntax_bootstrapper"
version = "1.1.0" version = "1.1.2"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -130,7 +130,8 @@ async fn main() {
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
let base_url : &str = "www.syntax.eco"; let base_url : &str = "www.syntax.eco";
let setup_url : &str = "setup.syntax.eco"; let mut setup_url : &str = "setup.syntax.eco";
let fallback_setup_url : &str = "setup.syntax.eco.s3.amazonaws.com";
let mut bootstrapper_filename :&str = "SyntaxPlayerLauncher.exe"; let mut bootstrapper_filename :&str = "SyntaxPlayerLauncher.exe";
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
{ {
@ -180,19 +181,32 @@ async fn main() {
.unwrap(); .unwrap();
debug(format!("Setup Server: {} | Base Server: {}", setup_url.bright_blue(), base_url.bright_blue()).as_str()); debug(format!("Setup Server: {} | Base Server: {}", setup_url.bright_blue(), base_url.bright_blue()).as_str());
debug("Fetching latest client version from setup server"); debug("Fetching latest client version from setup server");
let latest_client_version : String; let latest_client_version : String;
let latest_client_version_response = http_get(&http_client ,&format!("https://{}/version", setup_url)).await; let latest_client_version_response = http_get(&http_client ,&format!("http://{}/version", setup_url)).await;
match latest_client_version_response { match latest_client_version_response {
Ok(latest_client_version_result) => { Ok(latest_client_version_result) => {
debug(&format!("Latest Client Version: {}", latest_client_version_result.bright_blue())); debug(&format!("Latest Client Version: {}", latest_client_version_result.bright_blue()));
latest_client_version = latest_client_version_result; latest_client_version = latest_client_version_result;
}, },
Err(e) => { Err(e) => {
error(&format!("Failed to fetch latest client version from setup server: {}, are you connected to the internet?", e)); error(&format!("Failed to fetch latest client version from setup server: {}, attempting to fallback to {}", e, fallback_setup_url));
std::thread::sleep(std::time::Duration::from_secs(10)); let fallback_client_version_response = http_get(&http_client ,&format!("http://{}/version", fallback_setup_url)).await;
std::process::exit(0); match fallback_client_version_response {
Ok(fallback_client_version_result) => {
debug(&format!("Latest Client Version: {}", fallback_client_version_result.bright_blue()));
latest_client_version = fallback_client_version_result;
setup_url = fallback_setup_url;
},
Err(e) => {
error(&format!("Failed to fetch latest client version from fallback setup server: {}, are you connected to the internet?", e));
std::thread::sleep(std::time::Duration::from_secs(10));
std::process::exit(0);
}
}
} }
} }
// Wait for the latest client version to be fetched // Wait for the latest client version to be fetched
info(&format!("Latest Client Version: {}", latest_client_version.cyan().underline())); info(&format!("Latest Client Version: {}", latest_client_version.cyan().underline()));
@ -221,7 +235,7 @@ async fn main() {
if !latest_bootstrapper_path.exists() { if !latest_bootstrapper_path.exists() {
info("Downloading the latest bootstrapper and restarting"); info("Downloading the latest bootstrapper and restarting");
// Download the latest bootstrapper // Download the latest bootstrapper
download_file(&http_client, &format!("https://{}/{}-{}", setup_url, latest_client_version, bootstrapper_filename), &latest_bootstrapper_path).await; download_file(&http_client, &format!("http://{}/{}-{}", setup_url, latest_client_version, bootstrapper_filename), &latest_bootstrapper_path).await;
} }
// Run the latest bootstrapper ( with the same arguments passed to us ) and exit // Run the latest bootstrapper ( with the same arguments passed to us ) and exit
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -263,7 +277,7 @@ async fn main() {
} }
} }
let VersionURLPrefix = format!("https://{}/{}-", setup_url, latest_client_version); let VersionURLPrefix = format!("http://{}/{}-", setup_url, latest_client_version);
let SyntaxAppZip : PathBuf = download_file_prefix(&http_client, format!("{}SyntaxApp.zip", VersionURLPrefix).as_str(), &temp_downloads_directory).await; let SyntaxAppZip : PathBuf = download_file_prefix(&http_client, format!("{}SyntaxApp.zip", VersionURLPrefix).as_str(), &temp_downloads_directory).await;
let NPSyntaxProxyZip : PathBuf = download_file_prefix(&http_client, format!("{}NPSyntaxProxy.zip", VersionURLPrefix).as_str(), &temp_downloads_directory).await; let NPSyntaxProxyZip : PathBuf = download_file_prefix(&http_client, format!("{}NPSyntaxProxy.zip", VersionURLPrefix).as_str(), &temp_downloads_directory).await;
let SyntaxProxyZip : PathBuf = download_file_prefix(&http_client, format!("{}SyntaxProxy.zip", VersionURLPrefix).as_str(), &temp_downloads_directory).await; let SyntaxProxyZip : PathBuf = download_file_prefix(&http_client, format!("{}SyntaxProxy.zip", VersionURLPrefix).as_str(), &temp_downloads_directory).await;
@ -419,18 +433,18 @@ x-scheme-handler/syntax-player=syntax-player.desktop
} }
// Parse the arguments passed to the bootstrapper // Parse the arguments passed to the bootstrapper
// Looks something like "syntax-player://1+launchmode:play+gameinfo:TICKET+placelauncherurl:https://www.syntax.eco/Game/placelauncher.ashx?placeId=660&t=TICKET+k:l" // Looks something like "syntax-player://1+launchmode:play+gameinfo:TICKET+placelauncherurl:http://www.syntax.eco/Game/placelauncher.ashx?placeId=660&t=TICKET+k:l"
debug(&format!("Arguments Passed: {}", args.join(" ").bright_blue())); debug(&format!("Arguments Passed: {}", args.join(" ").bright_blue()));
if args.len() == 1 { if args.len() == 1 {
// Just open the website // Just open the website
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
std::process::Command::new("cmd").arg("/c").arg("start").arg("https://www.syntax.eco/games").spawn().unwrap(); std::process::Command::new("cmd").arg("/c").arg("start").arg("http://www.syntax.eco/games").spawn().unwrap();
std::process::exit(0); std::process::exit(0);
} }
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
{ {
std::process::Command::new("xdg-open").arg("https://www.syntax.eco/games").spawn().unwrap(); std::process::Command::new("xdg-open").arg("http://www.syntax.eco/games").spawn().unwrap();
std::process::exit(0); std::process::exit(0);
} }
} }
@ -506,7 +520,7 @@ x-scheme-handler/syntax-player=syntax-player.desktop
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
let mut command = std::process::Command::new(client_executable_path); let mut command = std::process::Command::new(client_executable_path);
command.args(&["--play","--authenticationUrl", format!("https://{}/Login/Negotiate.ashx", base_url).as_str(), "--authenticationTicket", authentication_ticket.as_str(), "--joinScriptUrl", format!("{}",join_script.as_str()).as_str()]); command.args(&["--play","--authenticationUrl", format!("http://{}/Login/Negotiate.ashx", base_url).as_str(), "--authenticationTicket", authentication_ticket.as_str(), "--joinScriptUrl", format!("{}",join_script.as_str()).as_str()]);
command.spawn().unwrap(); command.spawn().unwrap();
std::thread::sleep(std::time::Duration::from_secs(5)); std::thread::sleep(std::time::Duration::from_secs(5));
std::process::exit(0); std::process::exit(0);
@ -515,7 +529,7 @@ x-scheme-handler/syntax-player=syntax-player.desktop
{ {
// We have to launch the game through wine // We have to launch the game through wine
let mut command = std::process::Command::new(custom_wine); let mut command = std::process::Command::new(custom_wine);
command.args(&[client_executable_path.to_str().unwrap(), "--play","--authenticationUrl", format!("https://{}/Login/Negotiate.ashx", base_url).as_str(), "--authenticationTicket", authentication_ticket.as_str(), "--joinScriptUrl", format!("{}",join_script.as_str()).as_str()]); command.args(&[client_executable_path.to_str().unwrap(), "--play","--authenticationUrl", format!("http://{}/Login/Negotiate.ashx", base_url).as_str(), "--authenticationTicket", authentication_ticket.as_str(), "--joinScriptUrl", format!("{}",join_script.as_str()).as_str()]);
// We must wait for the game to exit before exiting the bootstrapper // We must wait for the game to exit before exiting the bootstrapper
let mut child = command.spawn().unwrap(); let mut child = command.spawn().unwrap();
child.wait().unwrap(); child.wait().unwrap();