Prevent proxy from crashing when can't connect by ip.

This commit is contained in:
IQuant 2024-09-28 12:17:05 +03:00
parent b822c656b4
commit 1267b0e87c
6 changed files with 48 additions and 0 deletions

View file

@ -127,3 +127,8 @@ Shift-hue = Shift hue
Show-debug-info = Show debug info Show-debug-info = Show debug info
hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players. hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players.
hint_ping = [Middle mouse button or right thumb stick] spawns a ping hint_ping = [Middle mouse button or right thumb stick] spawns a ping
## IP Connect
ip_could_not_connect = Could not connect
ip_wait_for_connection = Connecting to ip...

View file

@ -127,3 +127,8 @@ Shift-hue = Shift hue
Show-debug-info = Show debug info Show-debug-info = Show debug info
hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players. hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players.
hint_ping = [Middle mouse button or right thumb stick] spawns a ping hint_ping = [Middle mouse button or right thumb stick] spawns a ping
## IP Connect
ip_could_not_connect = Could not connect
ip_wait_for_connection = Connecting to ip...

View file

@ -110,3 +110,8 @@ Shift-hue = Shift hue
Show-debug-info = Show debug info Show-debug-info = Show debug info
hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players. hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players.
hint_ping = [Middle mouse button or right thumb stick] spawns a ping hint_ping = [Middle mouse button or right thumb stick] spawns a ping
## IP Connect
ip_could_not_connect = Could not connect
ip_wait_for_connection = Connecting to ip...

View file

@ -127,3 +127,8 @@ Shift-hue = Shift hue
Show-debug-info = Show debug info Show-debug-info = Show debug info
hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players. hint_spectate = Use [',' or d-pad-left] and ['.' or d-pad-right] keys to spectate over other players.
hint_ping = [Middle mouse button or right thumb stick] spawns a ping hint_ping = [Middle mouse button or right thumb stick] spawns a ping
## IP Connect
ip_could_not_connect = Could not connect
ip_wait_for_connection = Connecting to ip...

View file

@ -23,6 +23,7 @@ use self_update::SelfUpdateManager;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
fmt::Display, fmt::Display,
mem,
net::SocketAddr, net::SocketAddr,
ops::Deref, ops::Deref,
sync::{atomic::Ordering, Arc}, sync::{atomic::Ordering, Arc},
@ -119,6 +120,9 @@ impl Drop for NetManStopOnDrop {
enum AppState { enum AppState {
Connect, Connect,
ModManager, ModManager,
TangledConnecting {
peer: tangled::Peer,
},
Netman { Netman {
netman: NetManStopOnDrop, netman: NetManStopOnDrop,
noita_launcher: NoitaLauncher, noita_launcher: NoitaLauncher,
@ -425,6 +429,10 @@ impl App {
fn start_connect(&mut self, addr: SocketAddr) { fn start_connect(&mut self, addr: SocketAddr) {
let peer = Peer::connect(addr, None).unwrap(); let peer = Peer::connect(addr, None).unwrap();
self.state = AppState::TangledConnecting { peer };
}
fn start_connect_step_2(&mut self, peer: Peer) {
let netman = net::NetManager::new(PeerVariant::Tangled(peer), self.get_netman_init()); let netman = net::NetManager::new(PeerVariant::Tangled(peer), self.get_netman_init());
self.change_state_to_netman(netman, player_path(self.modmanager_settings.mod_path())); self.change_state_to_netman(netman, player_path(self.modmanager_settings.mod_path()));
} }
@ -1077,6 +1085,25 @@ impl eframe::App for App {
}); });
}); });
} }
AppState::TangledConnecting { peer } => {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label(tr("ip_wait_for_connection"));
});
if peer.state() == tangled::PeerState::Disconnected {
self.state = AppState::Error {
message: tr("ip_could_not_connect"),
};
return;
}
if peer.my_id().is_some() {
let AppState::TangledConnecting { peer } =
mem::replace(&mut self.state, AppState::Connect)
else {
unreachable!();
};
self.start_connect_step_2(peer);
}
}
}; };
} }

View file

@ -397,6 +397,7 @@ impl ConnectionManager {
.send(InternalEvent::Connected(host_conn.remote_id)) .send(InternalEvent::Connected(host_conn.remote_id))
.expect("channel to be open"); .expect("channel to be open");
self.host_conn = Some(host_conn); self.host_conn = Some(host_conn);
self.shared.peer_state.store(PeerState::Connected);
} }
Err(err) => { Err(err) => {
error!("Could not connect to host: {}", err); error!("Could not connect to host: {}", err);