mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Improved singleplayer error handling
Former-commit-id: 0e33493bbb588ab0cd5278ec92b5859712446f4b
This commit is contained in:
parent
e5db851f30
commit
df9b64355a
@ -15,6 +15,7 @@ pub enum Error {
|
||||
NoAddress,
|
||||
// Parsing/host name resolution successful but could not connect
|
||||
ConnectionFailed(ClientError),
|
||||
ClientCrashed,
|
||||
}
|
||||
|
||||
// Used to asynchronusly parse the server address, resolve host names, and create the client (which involves establishing a connection to the server)
|
||||
@ -31,7 +32,7 @@ impl ClientInit {
|
||||
let handle = Some(thread::spawn(move || {
|
||||
// Sleep the thread to wait for the single-player server to start up
|
||||
if wait {
|
||||
thread::sleep(Duration::from_millis(250));
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
}
|
||||
// Parses ip address or resolves hostname
|
||||
// Note: if you use an ipv6 address the number after the last colon will be used as the port unless you use [] around the address
|
||||
@ -85,7 +86,7 @@ impl ClientInit {
|
||||
match self.rx.try_recv() {
|
||||
Ok(result) => Some(result),
|
||||
Err(TryRecvError::Empty) => None,
|
||||
Err(TryRecvError::Disconnected) => panic!("Thread panicked or already finished"),
|
||||
Err(TryRecvError::Disconnected) => Some(Err(Error::ClientCrashed)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ impl PlayState for MainMenuState {
|
||||
match err {
|
||||
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
||||
InitError::ConnectionFailed(_) => "Connection failed",
|
||||
InitError::ClientCrashed => "Client crashed",
|
||||
}
|
||||
.to_string(),
|
||||
);
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::net::SocketAddr;
|
||||
use log::warn;
|
||||
use common::comp;
|
||||
use crate::{
|
||||
menu::char_selection::CharSelectionState, singleplayer::Singleplayer, Direction, GlobalState,
|
||||
@ -40,8 +41,11 @@ impl PlayState for StartSingleplayerState {
|
||||
let client = loop {
|
||||
match client_init.poll() {
|
||||
Some(Ok(client)) => break client,
|
||||
// Should always work
|
||||
Some(Err(err)) => {},
|
||||
// An error occured!
|
||||
Some(Err(err)) => {
|
||||
warn!("Failed to start singleplayer server: {:?}", err);
|
||||
return PlayStateResult::Pop;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user