This commit is contained in:
Michael Wain 2025-03-18 18:42:03 +03:00
parent a467cc6bad
commit 2596e1c283
5 changed files with 32 additions and 15 deletions

View File

@ -27,12 +27,13 @@ pub struct LauncherConfig {
pub show_snapshots: bool,
pub ram_amount: u32,
pub enable_blur: bool,
pub allow_http: bool,
servers: Vec<LauncherServer>
}
impl Default for LauncherConfig {
fn default() -> Self {
Self { is_portable: Default::default(), user_name: Default::default(), java_path: "java".to_string(), show_alpha: true, show_beta: true, show_snapshots: false, ram_amount: 1024, servers: Default::default(), enable_blur: Default::default() }
Self { is_portable: Default::default(), user_name: Default::default(), java_path: "java".to_string(), show_alpha: true, show_beta: true, show_snapshots: false, ram_amount: 1024, servers: Default::default(), enable_blur: Default::default(), allow_http: Default::default() }
}
}

View File

@ -97,7 +97,7 @@ impl Launcher {
println!("Server information: {}:{} session={}", domain, server_port, session_server_port);
match minecraft::session::try_signup(domain.clone(), session_server_port, username.clone(), password.clone()).await {
match minecraft::session::try_signup(domain.clone(), session_server_port, username.clone(), password.clone(), self.config.allow_http).await {
Ok(status) => match status {
SignUpResponse::ServerError => (false, "Internal server error"),
SignUpResponse::BadCredentials => (false, "Username or password is not valid"),
@ -170,9 +170,14 @@ impl Launcher {
v
}
pub async fn launch_instance(&self, instance_name: String, mut username: String, mut uuid: String, mut token: String, sender: UnboundedSender<String>, special_server: Option<&LauncherServer> ) {
pub async fn launch_instance(&self, instance_name: String, sender: UnboundedSender<String>, special_server: Option<&LauncherServer> ) {
let mut username = self.config.user_name();
let mut uuid = util::random_string(32);
let mut token = util::random_string(32);
if let Some(server) = special_server {
username = server.credentials.username.clone();
username = &server.credentials.username;
uuid = server.credentials.uuid.clone();
token = server.credentials.password.clone();
}
@ -237,7 +242,7 @@ impl Launcher {
let mut patched_auth = self.config.launcher_dir();
patched_auth.push("libraries");
patched_auth.push(library.to_pathbuf_file(true));
let _ = nicotine::patch_jar(libs.to_str().unwrap(), patched_auth.to_str().unwrap(), &["http://", &server.domain, ":", &server.session_server_port.to_string(), "/api/"].concat());
let _ = nicotine::patch_jar(libs.to_str().unwrap(), patched_auth.to_str().unwrap(), &[if self.config.allow_http { "http://" } else { "https://" }, &server.domain, ":", &server.session_server_port.to_string(), "/api/"].concat());
libraries_cmd.push([patched_auth.to_str().unwrap(), ";"].concat());
println!("{:?}", patched_auth.to_str().unwrap());
continue;
@ -258,7 +263,7 @@ impl Launcher {
let mut assets_dir = self.config.launcher_dir();
assets_dir.push("assets");
cmd.args(["--username", &username, "--version", &instance_name, "--gameDir", game_dir.to_str().unwrap(), "--assetsDir", assets_dir.to_str().unwrap(), "--assetIndex", &config.assetIndex.id, "--uuid", &uuid, "--accessToken", &token, "--userProperties", "{}", "--userType", "mojang", "--width", "925", "--height", "530"]);
cmd.args(["--username", username, "--version", &instance_name, "--gameDir", game_dir.to_str().unwrap(), "--assetsDir", assets_dir.to_str().unwrap(), "--assetIndex", &config.assetIndex.id, "--uuid", &uuid, "--accessToken", &token, "--userProperties", "{}", "--userType", "mojang", "--width", "925", "--height", "530"]);
if let Some(server) = special_server {
cmd.arg("--server");
cmd.arg(&server.domain);

View File

@ -178,7 +178,7 @@ async fn main() {
let instance_name = params.unwrap().params[0].clone();
logs_rec.close();
(lx, logs_rec) = mpsc::unbounded_channel();
launcher.launch_instance(instance_name, launcher.config.user_name().to_string(), util::random_string(32), util::random_string(32), lx.clone(), None).await;
launcher.launch_instance(instance_name, lx.clone(), None).await;
}
"run_server_instance" => {
let params = params.unwrap().params;
@ -188,7 +188,7 @@ async fn main() {
logs_rec.close();
(lx, logs_rec) = mpsc::unbounded_channel();
let s = launcher.config.servers().iter().find(|s| s.domain == domain && s.credentials.username == nickname);
launcher.launch_instance(instance_name, launcher.config.user_name().to_string(), util::random_string(32), util::random_string(32), lx.clone(), s).await;
launcher.launch_instance(instance_name, lx.clone(), s).await;
}
"locate_java" => {
if let Ok(java_path) = java_locator::locate_file("java.exe") {
@ -204,7 +204,7 @@ async fn main() {
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["add_server_response".to_string(), status.to_string(), msg.to_string()] }).unwrap()));
}
"fetch_settings" => {
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["fetch_settings_response".to_string(), launcher.config.show_alpha.to_string(), launcher.config.show_beta.to_string(), launcher.config.show_snapshots.to_string(), launcher.config.java_path.clone(), launcher.config.ram_amount.to_string(), launcher.config.enable_blur.to_string()] }).unwrap()));
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["fetch_settings_response".to_string(), launcher.config.show_alpha.to_string(), launcher.config.show_beta.to_string(), launcher.config.show_snapshots.to_string(), launcher.config.java_path.clone(), launcher.config.ram_amount.to_string(), launcher.config.enable_blur.to_string(), launcher.config.allow_http.to_string()] }).unwrap()));
}
"save_bg" => {
let params = &params.unwrap().params;
@ -227,6 +227,7 @@ async fn main() {
launcher.config.show_beta = params[1].parse().unwrap();
launcher.config.show_snapshots = params[2].parse().unwrap();
launcher.config.enable_blur = params[5].parse().unwrap();
launcher.config.allow_http = params[6].parse().unwrap();
launcher.save_config();
}
"open_file" => {

View File

@ -179,9 +179,9 @@ pub mod session {
uuid: String
}
pub async fn try_signup(server_domain: String, port: u16, username: String, password: String) -> Result<SignUpResponse, Box<dyn Error + Send + Sync>> {
pub async fn try_signup(server_domain: String, port: u16, username: String, password: String, allow_http: bool) -> Result<SignUpResponse, Box<dyn Error + Send + Sync>> {
let request = SignUpRequest { username, password };
let mut r = surf::post(["http://".to_string(), server_domain, ":".to_string(), port.to_string(), "/api/register".to_string()].concat())
let mut r = surf::post([if allow_http { "http://".to_string() } else { "https://".to_string() }, server_domain, ":".to_string(), port.to_string(), "/api/register".to_string()].concat())
.body_json(&request)
.unwrap()
.await?;

View File

@ -268,6 +268,13 @@
<span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Show snapshots</span>
</label>
</div>
<div class="mt-4 flex justify-between items-center">
<label class="inline-flex items-center cursor-pointer">
<input id="allow-http" type="checkbox" value="" class="sr-only peer">
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-green-300 dark:peer-focus:ring-green-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-green-600 dark:peer-checked:bg-green-600"></div>
<span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Allow http (debug)</span>
</label>
</div>
</div>
<div id="appearance-settings" class="settings-tab mt-4 hidden">
@ -509,7 +516,8 @@
let java_path = $("#java-path").val();
let ram_input = $("#ram-input").val();
let enable_blur = $("#enable-blur").prop('checked');
$.post({url: "update_settings", data: JSON.stringify({ params: [show_alpha+"", show_beta+"", show_snapshots+"", java_path, ram_input+"", enable_blur+""] }) }, processParams);
let allow_http = $("#allow-http").prop('checked');
$.post({url: "update_settings", data: JSON.stringify({ params: [show_alpha+"", show_beta+"", show_snapshots+"", java_path, ram_input+"", enable_blur+"", allow_http+""] }) }, processParams);
showPopup("Saved!");
}
@ -519,7 +527,8 @@
$("#show-snapshots").prop('checked', (params[2] === 'true'));
$("#java-path").val(params[3]);
$("#ram-input").val(params[4]);
$("#enable-blur").prop('checked', (params[5] == 'true'));
$("#enable-blur").prop('checked', (params[5] === 'true'));
$("#allow-http").prop('checked', (params[6] === 'true'));
if( params[5] == 'true' ) {
enableBlur();
}
@ -594,9 +603,9 @@
}
function runServerConnection(domain, nickname) {
showSection(undefined, "instances");
chosenDomain = domain;
chosenNickname = nickname;
showSection(undefined, "instances");
showInstancesSection();
}
@ -669,7 +678,8 @@
}
function showSection(obj, section) {
chosenDomain = undefined;
chosenNickname = undefined;
$(".menu-btn").each(function(i, d) {
$(d).removeClass('bg-green-50');
$(d).addClass('text-gray-500');