Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,7 @@ pub fn get_samp_favorite_list() -> String {

#[tauri::command]
pub fn resolve_hostname(hostname: String) -> std::result::Result<String, String> {
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))
helpers::resolve_hostname_to_ipv4(&hostname)
}

#[tauri::command]
Expand Down
22 changes: 22 additions & 0 deletions src-tauri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ pub fn decode_buffer(buf: Vec<u8>) -> (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<String, String> {
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<Path>, dest: impl AsRef<Path>) -> crate::errors::Result<()> {
let files = fs::read_dir(src).map_err(|e| crate::errors::LauncherError::from(e))?;

Expand Down
10 changes: 9 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
helpers::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),
Expand Down
Loading