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:
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run -- -1
|
||||
|
||||
@@ -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:4537".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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run -- -1
|
||||
|
||||
@@ -11,9 +11,9 @@ 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,
|
||||
/// Handle one connection and then exit
|
||||
#[arg(short = '1', long)]
|
||||
pub once: bool,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
|
||||
@@ -18,26 +18,26 @@ async fn main() -> std::io::Result<()> {
|
||||
let args = cli::CliArgs::get();
|
||||
log::debug!("Got cli args {:?}", args);
|
||||
|
||||
let server = polariton_server::Server::new(operations::handler());
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler()));
|
||||
|
||||
let ip_addr: std::net::IpAddr = args.ip.parse().expect("Invalid IP address");
|
||||
|
||||
let listener = net::TcpListener::bind(std::net::SocketAddr::new(ip_addr, args.port)).await?;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
loop {
|
||||
if args.once {
|
||||
log::warn!("Handling first connection and then exiting");
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, &server));
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let (socket, address) = listener.accept().await?;
|
||||
process_socket(socket, address, &server).await;
|
||||
process_socket(socket, address, server).await;
|
||||
Ok(())
|
||||
} else {
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, server.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: &polariton_server::Server<crate::UserTy>) {
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: std::sync::Arc<polariton_server::Server<crate::UserTy>>) {
|
||||
log::debug!("Accepting connection from address {}", address);
|
||||
let enc = match do_connect_handshake(&mut socket).await {
|
||||
Some(x) => x,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run -- -1
|
||||
|
||||
@@ -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:4533".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 {
|
||||
|
||||
@@ -20,16 +20,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, 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run #&> ../data/rc_services_room.log
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run -- -1 #&> ../data/rc_services_room.log
|
||||
|
||||
@@ -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,
|
||||
|
||||
/// Assets root
|
||||
#[arg(long, default_value_t = {"../assets/robocraft".to_string()})]
|
||||
pub assets: String,
|
||||
@@ -22,6 +18,10 @@ pub struct CliArgs {
|
||||
/// User data root
|
||||
#[arg(long, default_value_t = {"../data/robocraft".to_string()})]
|
||||
pub data: String,
|
||||
|
||||
/// Handle one connection and then exit
|
||||
#[arg(short = '1', long)]
|
||||
pub once: bool,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
|
||||
@@ -27,31 +27,31 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
let cubes = persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(persist::user::UserImpl::load(&args.data, &cubes).expect("Bad user data"));
|
||||
let init_ctx = InitConfig {
|
||||
let init_ctx = std::sync::Arc::new(InitConfig {
|
||||
cubes,
|
||||
users,
|
||||
};
|
||||
});
|
||||
|
||||
let server = polariton_server::Server::new(operations::handler(&init_ctx));
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler(&init_ctx)));
|
||||
|
||||
let ip_addr: std::net::IpAddr = args.ip.parse().expect("Invalid IP address");
|
||||
|
||||
let listener = net::TcpListener::bind(std::net::SocketAddr::new(ip_addr, args.port)).await?;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
loop {
|
||||
if args.once {
|
||||
log::warn!("Handling first connection and then exiting");
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, &server, &init_ctx));
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let (socket, address) = listener.accept().await?;
|
||||
process_socket(socket, address, &server, &init_ctx).await;
|
||||
process_socket(socket, address, server, init_ctx).await;
|
||||
Ok(())
|
||||
} else {
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, server.clone(), init_ctx.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: &polariton_server::Server<crate::UserTy>, init_ctx: &InitConfig) {
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: std::sync::Arc<polariton_server::Server<crate::UserTy>>, init_ctx: std::sync::Arc<InitConfig>) {
|
||||
log::debug!("Accepting connection from address {}", address);
|
||||
let enc = match do_connect_handshake(&mut socket).await {
|
||||
Some(x) => x,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run -- -1
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run
|
||||
RUST_BACKTRACE=1 RUST_LOG=debug cargo run -- -1
|
||||
|
||||
@@ -11,9 +11,9 @@ 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,
|
||||
/// Handle one connection and then exit
|
||||
#[arg(short = '1', long)]
|
||||
pub once: bool,
|
||||
}
|
||||
|
||||
impl CliArgs {
|
||||
|
||||
@@ -18,26 +18,26 @@ async fn main() -> std::io::Result<()> {
|
||||
let args = cli::CliArgs::get();
|
||||
log::debug!("Got cli args {:?}", args);
|
||||
|
||||
let server = polariton_server::Server::new(operations::handler());
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler()));
|
||||
|
||||
let ip_addr: std::net::IpAddr = args.ip.parse().expect("Invalid IP address");
|
||||
|
||||
let listener = net::TcpListener::bind(std::net::SocketAddr::new(ip_addr, args.port)).await?;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
loop {
|
||||
if args.once {
|
||||
log::warn!("Handling first connection and then exiting");
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, &server));
|
||||
}
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let (socket, address) = listener.accept().await?;
|
||||
process_socket(socket, address, &server).await;
|
||||
process_socket(socket, address, server).await;
|
||||
Ok(())
|
||||
} else {
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tokio::spawn(process_socket(socket, address, server.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: &polariton_server::Server<crate::UserTy, crate::data::custom::CustomType>) {
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: std::sync::Arc<polariton_server::Server<crate::UserTy, crate::data::custom::CustomType>>) {
|
||||
log::debug!("Accepting connection from address {}", address);
|
||||
let enc = match do_connect_handshake(&mut socket).await {
|
||||
Some(x) => x,
|
||||
|
||||
Reference in New Issue
Block a user