mirror of
				https://gitea.farpn.net/w1cdn/mwtchahrd.git
				synced 2025-11-04 05:46:36 -06:00 
			
		
		
		
	Add defaults for UDP arguments to not get in the way.
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -9,6 +9,7 @@ use std::net::TcpStream;
 | 
			
		||||
use std::thread::sleep;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
use std::net::UdpSocket;
 | 
			
		||||
use std::net::Ipv4Addr;
 | 
			
		||||
 | 
			
		||||
/// Validate that the provided port string can be parsed into a u16 and is nonzero.
 | 
			
		||||
fn validate_port(port: &str) -> Result<u16, String> {
 | 
			
		||||
@@ -49,16 +50,12 @@ struct Cli {
 | 
			
		||||
    #[arg(short = 'u', long, default_value_t = false)]
 | 
			
		||||
    ui_only: bool,
 | 
			
		||||
    
 | 
			
		||||
    // Enable UDP
 | 
			
		||||
    #[arg(short = 'm', long, default_value_t = false)]
 | 
			
		||||
    udp: bool,
 | 
			
		||||
    
 | 
			
		||||
    // Send UDP to what IP address (e.g. 127.0.0.1)
 | 
			
		||||
    #[arg(short = 'b', long)]
 | 
			
		||||
    #[arg(short = 'b', long, default_value_t = std::net::IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)))]
 | 
			
		||||
    uip: std::net::IpAddr,
 | 
			
		||||
    
 | 
			
		||||
    // Send UDP to what port (e.g. 8000)
 | 
			
		||||
    #[arg(short = 'k', long, value_parser = validate_port)]
 | 
			
		||||
    #[arg(short = 'k', long, value_parser = validate_port, default_value_t = 55555)]
 | 
			
		||||
    uport: u16,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -426,10 +423,10 @@ fn main() -> Result<()> {
 | 
			
		||||
    let uaddr = format!("{}:{}", cli.uip, cli.uport);
 | 
			
		||||
    let reconnect_delay_ms = 5000;
 | 
			
		||||
    
 | 
			
		||||
    if cli.udp {
 | 
			
		||||
    if cli.uport != 55555 {
 | 
			
		||||
        // Bind the client socket to any available address and port
 | 
			
		||||
        let socket = UdpSocket::bind("0.0.0.0:0")?;
 | 
			
		||||
        println!("UDP client started");
 | 
			
		||||
        println!("UDP client started at {}:{}", cli.uip, cli.uport);
 | 
			
		||||
        // Send a message to the server
 | 
			
		||||
        let message = "UDP client connected";
 | 
			
		||||
        socket.send_to(message.as_bytes(), uaddr)?;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user