From 2de1239e589006c52bc1f3e048d2f587e2f66d61 Mon Sep 17 00:00:00 2001 From: ricardoofnl Date: Mon, 29 Jun 2026 11:54:08 +0000 Subject: [PATCH 1/2] Resolve CLI hostname to IPv4 to fix hyphenated host truncation --- src-tauri/src/commands.rs | 9 +++++++-- src-tauri/src/main.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 19369ceb..773a8887 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -78,8 +78,8 @@ pub fn get_samp_favorite_list() -> String { samp::get_samp_favorite_list() } -#[tauri::command] -pub fn resolve_hostname(hostname: String) -> std::result::Result { +// resolves a hostname to its first ipv4 address +pub fn resolve_hostname_to_ipv4(hostname: &str) -> std::result::Result { use std::net::{IpAddr, ToSocketAddrs}; if hostname.is_empty() { @@ -100,6 +100,11 @@ pub fn resolve_hostname(hostname: String) -> std::result::Result Err(format!("No IPv4 address found for hostname '{}'", hostname)) } +#[tauri::command] +pub fn resolve_hostname(hostname: String) -> std::result::Result { + resolve_hostname_to_ipv4(&hostname) +} + #[tauri::command] pub fn is_process_alive(pid: u32) -> bool { use windows_sys::Win32::Foundation::{CloseHandle, HANDLE}; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a0c29f60..db44461a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -130,9 +130,17 @@ async fn handle_cli_args() -> Result<()> { &omp_client_path }; + // resolve hostname to ipv4 so the game does not truncate hyphenated hosts + let host = args.host.as_ref().unwrap(); + let resolved_host = + commands::resolve_hostname_to_ipv4(host).unwrap_or_else(|e| { + info!("Failed to resolve hostname '{}', using raw value: {}", host, e); + host.clone() + }); + run_samp( args.name.as_ref().unwrap(), - args.host.as_ref().unwrap(), + &resolved_host, args.port.unwrap(), gamepath, &format!("{}/{}", gamepath, SAMP_DLL), From ec24a7111a6b0b39222168c0c2f5ef7a613a5f1a Mon Sep 17 00:00:00 2001 From: ricardoofnl Date: Mon, 29 Jun 2026 16:24:14 +0000 Subject: [PATCH 2/2] Move resolve_hostname_to_ipv4 to helpers.rs --- src-tauri/src/commands.rs | 24 +----------------------- src-tauri/src/helpers.rs | 22 ++++++++++++++++++++++ src-tauri/src/main.rs | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 773a8887..ba38dbbf 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -78,31 +78,9 @@ pub fn get_samp_favorite_list() -> String { samp::get_samp_favorite_list() } -// resolves a hostname to its first ipv4 address -pub fn resolve_hostname_to_ipv4(hostname: &str) -> std::result::Result { - use std::net::{IpAddr, ToSocketAddrs}; - - if hostname.is_empty() { - return Err("Hostname cannot be empty".to_string()); - } - - let addr = format!("{}:80", hostname); - let addrs = addr - .to_socket_addrs() - .map_err(|e| format!("Failed to resolve hostname '{}': {}", hostname, e))?; - - for ip in addrs { - if let IpAddr::V4(ipv4) = ip.ip() { - return Ok(ipv4.to_string()); - } - } - - Err(format!("No IPv4 address found for hostname '{}'", hostname)) -} - #[tauri::command] pub fn resolve_hostname(hostname: String) -> std::result::Result { - resolve_hostname_to_ipv4(&hostname) + helpers::resolve_hostname_to_ipv4(&hostname) } #[tauri::command] diff --git a/src-tauri/src/helpers.rs b/src-tauri/src/helpers.rs index 10a1d906..4aadfd6f 100644 --- a/src-tauri/src/helpers.rs +++ b/src-tauri/src/helpers.rs @@ -81,6 +81,28 @@ pub fn decode_buffer(buf: Vec) -> (String, String) { (buff_output, actual_encoding.name().to_string()) } +// resolves a hostname to its first ipv4 address +pub fn resolve_hostname_to_ipv4(hostname: &str) -> std::result::Result { + use std::net::{IpAddr, ToSocketAddrs}; + + if hostname.is_empty() { + return Err("Hostname cannot be empty".to_string()); + } + + let addr = format!("{}:80", hostname); + let addrs = addr + .to_socket_addrs() + .map_err(|e| format!("Failed to resolve hostname '{}': {}", hostname, e))?; + + for ip in addrs { + if let IpAddr::V4(ipv4) = ip.ip() { + return Ok(ipv4.to_string()); + } + } + + Err(format!("No IPv4 address found for hostname '{}'", hostname)) +} + pub fn copy_files(src: impl AsRef, dest: impl AsRef) -> crate::errors::Result<()> { let files = fs::read_dir(src).map_err(|e| crate::errors::LauncherError::from(e))?; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index db44461a..def58481 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -133,7 +133,7 @@ async fn handle_cli_args() -> Result<()> { // resolve hostname to ipv4 so the game does not truncate hyphenated hosts let host = args.host.as_ref().unwrap(); let resolved_host = - commands::resolve_hostname_to_ipv4(host).unwrap_or_else(|e| { + helpers::resolve_hostname_to_ipv4(host).unwrap_or_else(|e| { info!("Failed to resolve hostname '{}', using raw value: {}", host, e); host.clone() });