mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Voxygen and server-cli no longer panic if server creation returns error
The process just exists instead
This commit is contained in:
parent
62005e9031
commit
fd9ec8fbd0
@ -1,5 +1,7 @@
|
||||
use network::{NetworkError, ParticipantError, StreamError};
|
||||
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
NetworkErr(NetworkError),
|
||||
@ -19,3 +21,14 @@ impl From<ParticipantError> for Error {
|
||||
impl From<StreamError> for Error {
|
||||
fn from(err: StreamError) -> Self { Error::StreamErr(err) }
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::NetworkErr(err) => write!(f, "Network Error: {}", err),
|
||||
Self::ParticipantErr(err) => write!(f, "Participant Error: {}", err),
|
||||
Self::StreamErr(err) => write!(f, "Stream Error: {}", err),
|
||||
Self::Other(err) => write!(f, "Error: {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,12 +148,19 @@ impl Server {
|
||||
Ok(vec) => vec,
|
||||
Err(error) => {
|
||||
tracing::warn!(?error, ?file, "Couldn't deserialize banned words file");
|
||||
return Err(Error::Other(error.to_string()));
|
||||
return Err(Error::Other(format!(
|
||||
"Couldn't read banned words file \"{}\"",
|
||||
path.to_string_lossy()
|
||||
)));
|
||||
},
|
||||
},
|
||||
Err(error) => {
|
||||
tracing::warn!(?error, ?path, "couldn't open banned words file");
|
||||
return Err(Error::Other(error.to_string()));
|
||||
tracing::warn!(?error, ?path, "Couldn't open banned words file");
|
||||
return Err(Error::Other(format!(
|
||||
"Couldn't open banned words file \"{}\". Error: {}",
|
||||
path.to_string_lossy(),
|
||||
error
|
||||
)));
|
||||
},
|
||||
};
|
||||
banned_words.append(&mut list);
|
||||
|
@ -50,6 +50,22 @@ impl PlayState for MainMenuState {
|
||||
&crate::i18n::i18n_asset_key(&global_state.settings.language.selected_language),
|
||||
);
|
||||
|
||||
//Poll server creation
|
||||
#[cfg(feature = "singleplayer")]
|
||||
{
|
||||
if let Some(singleplayer) = &global_state.singleplayer {
|
||||
if let Ok(result) = singleplayer.receiver.try_recv() {
|
||||
if let Err(error) = result {
|
||||
tracing::error!(?error, "Could not start server");
|
||||
global_state.singleplayer = None;
|
||||
self.client_init = None;
|
||||
self.main_menu_ui.cancel_connection();
|
||||
self.main_menu_ui.show_info(format!("Error: {:?}", error));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle window events.
|
||||
for event in events {
|
||||
match event {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use client::Client;
|
||||
use common::clock::Clock;
|
||||
use crossbeam::channel::{unbounded, Receiver, Sender, TryRecvError};
|
||||
use server::{Event, Input, Server, ServerSettings};
|
||||
use crossbeam::channel::{bounded, unbounded, Receiver, Sender, TryRecvError};
|
||||
use server::{Error as ServerError, Event, Input, Server, ServerSettings};
|
||||
use std::{
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
@ -23,6 +23,7 @@ enum Msg {
|
||||
pub struct Singleplayer {
|
||||
_server_thread: JoinHandle<()>,
|
||||
sender: Sender<Msg>,
|
||||
pub receiver: Receiver<Result<(), ServerError>>,
|
||||
// Wether the server is stopped or not
|
||||
paused: Arc<AtomicBool>,
|
||||
}
|
||||
@ -47,8 +48,19 @@ impl Singleplayer {
|
||||
let paused = Arc::new(AtomicBool::new(false));
|
||||
let paused1 = paused.clone();
|
||||
|
||||
let (result_sender, result_receiver) = bounded(1);
|
||||
|
||||
let thread = thread::spawn(move || {
|
||||
let server = Server::new(settings2).expect("Failed to create server instance!");
|
||||
let server = match Server::new(settings2) {
|
||||
Ok(server) => {
|
||||
result_sender.send(Ok(())).unwrap();
|
||||
server
|
||||
},
|
||||
Err(error) => {
|
||||
result_sender.send(Err(error)).unwrap();
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
let server = match thread_pool {
|
||||
Some(pool) => server.with_thread_pool(pool),
|
||||
@ -62,6 +74,7 @@ impl Singleplayer {
|
||||
Singleplayer {
|
||||
_server_thread: thread,
|
||||
sender,
|
||||
receiver: result_receiver,
|
||||
paused,
|
||||
},
|
||||
settings,
|
||||
|
Loading…
Reference in New Issue
Block a user