mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Change single connection mode to CLI arg instead of forced in debug mode
This commit is contained in:
@@ -11,10 +11,6 @@ pub struct CliArgs {
|
||||
#[arg(long, default_value_t = {"127.0.0.1".to_string()})]
|
||||
pub ip: String,
|
||||
|
||||
/// Socket read tries before giving up (0 to never give up)
|
||||
#[arg(long, default_value_t = 5)]
|
||||
pub retries: usize,
|
||||
|
||||
/// Domain and port of the game server to send new connections
|
||||
#[arg(long, default_value_t = {"127.0.0.1:4535".to_string()})]
|
||||
pub redirect: String,
|
||||
@@ -22,6 +18,10 @@ pub struct CliArgs {
|
||||
/// Name of game server to send new connections
|
||||
#[arg(long, default_value_t = {"ngram_is_ngnius".to_string()})]
|
||||
pub room_name: String,
|
||||
|
||||
/// Handle one connection and then exit
|
||||
#[arg(short = '1', long)]
|
||||
pub once: bool,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
|
||||
@@ -21,16 +21,16 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
let listener = net::TcpListener::bind(std::net::SocketAddr::new(ip_addr, args.port)).await?;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, op_handler.clone(), redirect_static, room_name_static));
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if args.once {
|
||||
log::warn!("Handling first connection and then exiting");
|
||||
let (socket, address) = listener.accept().await?;
|
||||
process_socket(socket, address, redirect_static, room_name_static).await;
|
||||
Ok(())
|
||||
} else {
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, redirect_static, room_name_static));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user