From a7da14c109c0d4eae893a84a9b10ea9eae62f7e5 Mon Sep 17 00:00:00 2001 From: xeon Date: Thu, 25 Jul 2024 12:36:22 +0300 Subject: [PATCH] don't panic if readline lib fails to initialize fixes startup crash on non-standard TTYs --- nap_gameserver/src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nap_gameserver/src/main.rs b/nap_gameserver/src/main.rs index a42ef39..40ce9b6 100644 --- a/nap_gameserver/src/main.rs +++ b/nap_gameserver/src/main.rs @@ -25,9 +25,9 @@ pub struct ServerState { async fn main() -> Result<(), Box> { splash::print("GameServer"); - let (rl, out) = Readline::new(String::from(">> ")).unwrap(); + let rl = Readline::new(String::from(">> ")).ok(); + init_tracing(rl.as_ref().map(|(_, out)| out.clone())); - init_tracing(Some(out.clone())); tracing::info!("don't forget to visit https://discord.xeondev.com/"); let config = load_or_create_config::("nap_gameserver.toml"); @@ -44,7 +44,10 @@ async fn main() -> Result<(), Box> { }); let command_mgr = CommandManager::new(state.clone()); - tokio::spawn(async move { command_mgr.run(rl, out).await }); + + if let Some((rl, out)) = rl { + tokio::spawn(async move { command_mgr.run(rl, out).await }); + } net::listen(state).await }