chore: split executable into lib and main
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
#![feature(let_chains)]
|
||||
use anyhow::Result;
|
||||
|
||||
mod net;
|
||||
mod util;
|
||||
|
||||
use net::gateway::Gateway;
|
||||
|
||||
pub async fn start_gameserver() -> Result<()> {
|
||||
let mut gateway = Gateway::new("0.0.0.0", 23301).await?;
|
||||
Box::pin(gateway.listen()).await
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! log_error {
|
||||
($e:expr) => {
|
||||
if let Err(e) = $e {
|
||||
tracing::error!(error.message = %format!("{}", &e), "{:?}", e);
|
||||
}
|
||||
};
|
||||
($context:expr, $e:expr $(,)?) => {
|
||||
if let Err(e) = $e {
|
||||
let e = format!("{:?}", ::anyhow::anyhow!(e).context($context));
|
||||
tracing::error!(error.message = %format!("{}", &e), "{:?}", e);
|
||||
}
|
||||
};
|
||||
($ok_context:expr, $err_context:expr, $e:expr $(,)?) => {
|
||||
if let Err(e) = $e {
|
||||
let e = format!("{:?}", ::anyhow::anyhow!(e).context($err_context));
|
||||
tracing::error!(error.message = %format!("{}", &e), "{:?}", e);
|
||||
} else {
|
||||
tracing::info!($ok_context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_tracing() {
|
||||
#[cfg(target_os = "windows")]
|
||||
ansi_term::enable_ansi_support().unwrap();
|
||||
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
#![feature(let_chains)]
|
||||
use anyhow::Result;
|
||||
|
||||
mod logging;
|
||||
mod net;
|
||||
mod util;
|
||||
pub fn init_tracing() {
|
||||
#[cfg(target_os = "windows")]
|
||||
ansi_term::enable_ansi_support().unwrap();
|
||||
|
||||
use logging::init_tracing;
|
||||
use net::gateway::Gateway;
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
init_tracing();
|
||||
let mut gateway = Gateway::new("0.0.0.0", 23301).await?;
|
||||
Box::pin(gateway.listen()).await
|
||||
gameserver::start_gameserver().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user