2019-04-14 23:28:29 +00:00
|
|
|
mod client_init;
|
2020-12-04 05:38:26 +00:00
|
|
|
mod scene;
|
2019-10-27 07:11:18 +00:00
|
|
|
mod ui;
|
2019-01-02 22:08:13 +00:00
|
|
|
|
2019-03-17 17:52:54 +00:00
|
|
|
use super::char_selection::CharSelectionState;
|
2019-10-27 07:11:18 +00:00
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
use crate::singleplayer::Singleplayer;
|
2019-10-18 20:05:37 +00:00
|
|
|
use crate::{
|
2021-07-04 09:47:18 +00:00
|
|
|
i18n::LocalizationHandle,
|
|
|
|
render::{Drawer, GlobalsBindGroup},
|
|
|
|
settings::Settings,
|
|
|
|
window::Event,
|
|
|
|
Direction, GlobalState, PlayState, PlayStateResult,
|
2019-10-18 20:05:37 +00:00
|
|
|
};
|
2021-04-22 17:27:38 +00:00
|
|
|
use client::{
|
2021-05-17 17:32:26 +00:00
|
|
|
addr::ConnectionArgs,
|
2021-04-22 17:27:38 +00:00
|
|
|
error::{InitProtocolError, NetworkConnectError, NetworkError},
|
2021-04-26 01:30:17 +00:00
|
|
|
Client, ServerInfo,
|
2021-04-22 17:27:38 +00:00
|
|
|
};
|
2021-05-17 17:32:26 +00:00
|
|
|
use client_init::{ClientInit, Error as InitError, Msg as InitMsg};
|
2021-04-24 14:39:35 +00:00
|
|
|
use common::comp;
|
2021-03-08 22:40:02 +00:00
|
|
|
use common_base::span;
|
2020-12-04 05:38:26 +00:00
|
|
|
use scene::Scene;
|
2021-05-17 17:32:26 +00:00
|
|
|
use std::sync::Arc;
|
2021-02-19 09:55:43 +00:00
|
|
|
use tokio::runtime;
|
2020-08-30 22:32:26 +00:00
|
|
|
use tracing::error;
|
2019-03-17 17:52:54 +00:00
|
|
|
use ui::{Event as MainMenuEvent, MainMenuUi};
|
2019-01-02 21:25:01 +00:00
|
|
|
|
2021-04-26 01:30:17 +00:00
|
|
|
// TODO: show status messages for waiting on server creation, client init, and
|
|
|
|
// pipeline creation (we can show progress of pipeline creation)
|
|
|
|
enum InitState {
|
|
|
|
None,
|
|
|
|
// Waiting on the client initialization
|
|
|
|
Client(ClientInit),
|
|
|
|
// Client initialized but still waiting on Renderer pipeline creation
|
2021-04-27 00:12:44 +00:00
|
|
|
Pipeline(Box<Client>),
|
2021-04-26 01:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl InitState {
|
|
|
|
fn client(&self) -> Option<&ClientInit> {
|
|
|
|
if let Self::Client(client_init) = &self {
|
|
|
|
Some(client_init)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:28:16 +00:00
|
|
|
pub struct MainMenuState {
|
|
|
|
main_menu_ui: MainMenuUi,
|
2021-04-26 01:30:17 +00:00
|
|
|
init: InitState,
|
2020-12-04 05:38:26 +00:00
|
|
|
scene: Scene,
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
2019-01-02 21:25:01 +00:00
|
|
|
|
2019-03-04 07:28:16 +00:00
|
|
|
impl MainMenuState {
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Create a new `MainMenuState`.
|
2019-04-18 17:40:29 +00:00
|
|
|
pub fn new(global_state: &mut GlobalState) -> Self {
|
2019-01-30 12:11:34 +00:00
|
|
|
Self {
|
2019-04-18 17:40:29 +00:00
|
|
|
main_menu_ui: MainMenuUi::new(global_state),
|
2021-04-26 01:30:17 +00:00
|
|
|
init: InitState::None,
|
2020-12-04 05:38:26 +00:00
|
|
|
scene: Scene::new(global_state.window.renderer_mut()),
|
2019-01-30 12:11:34 +00:00
|
|
|
}
|
2019-01-02 21:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 07:28:16 +00:00
|
|
|
impl PlayState for MainMenuState {
|
2019-10-27 07:11:18 +00:00
|
|
|
fn enter(&mut self, global_state: &mut GlobalState, _: Direction) {
|
2019-10-04 17:31:24 +00:00
|
|
|
// Kick off title music
|
2020-03-31 18:12:49 +00:00
|
|
|
if global_state.settings.audio.output.is_enabled() && global_state.audio.music_enabled() {
|
2020-02-15 21:30:44 +00:00
|
|
|
global_state.audio.play_title_music();
|
2019-10-17 07:10:24 +00:00
|
|
|
}
|
2019-10-04 17:31:24 +00:00
|
|
|
|
2019-10-18 20:05:37 +00:00
|
|
|
// Reset singleplayer server if it was running already
|
2019-10-27 07:11:18 +00:00
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
{
|
|
|
|
global_state.singleplayer = None;
|
|
|
|
}
|
2020-11-13 03:06:57 +00:00
|
|
|
|
|
|
|
// Updated localization in case the selected language was changed
|
2020-12-13 01:09:57 +00:00
|
|
|
self.main_menu_ui
|
|
|
|
.update_language(global_state.i18n, &global_state.settings);
|
2020-11-14 01:16:42 +00:00
|
|
|
// Set scale mode in case it was change
|
|
|
|
self.main_menu_ui
|
2021-03-12 19:09:25 +00:00
|
|
|
.set_scale_mode(global_state.settings.interface.ui_scale);
|
2019-10-27 07:11:18 +00:00
|
|
|
}
|
2019-10-18 20:05:37 +00:00
|
|
|
|
2020-11-13 04:39:47 +00:00
|
|
|
#[allow(clippy::single_match)] // TODO: remove when event match has multiple arms
|
2019-10-27 07:11:18 +00:00
|
|
|
fn tick(&mut self, global_state: &mut GlobalState, events: Vec<Event>) -> PlayStateResult {
|
2020-09-07 04:59:16 +00:00
|
|
|
span!(_guard, "tick", "<MainMenuState as PlayState>::tick");
|
2020-02-02 08:05:58 +00:00
|
|
|
|
2020-10-26 04:15:30 +00:00
|
|
|
// Poll server creation
|
2020-07-21 09:59:00 +00:00
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
{
|
|
|
|
if let Some(singleplayer) = &global_state.singleplayer {
|
2021-02-19 09:55:43 +00:00
|
|
|
match singleplayer.receiver.try_recv() {
|
|
|
|
Ok(Ok(runtime)) => {
|
2020-10-26 04:15:30 +00:00
|
|
|
// Attempt login after the server is finished initializing
|
|
|
|
attempt_login(
|
|
|
|
&mut global_state.info_message,
|
|
|
|
"singleplayer".to_owned(),
|
|
|
|
"".to_owned(),
|
2021-05-17 17:32:26 +00:00
|
|
|
ConnectionArgs::Mpsc(14004),
|
2021-04-26 01:30:17 +00:00
|
|
|
&mut self.init,
|
2021-02-19 09:55:43 +00:00
|
|
|
Some(runtime),
|
2020-10-26 04:15:30 +00:00
|
|
|
);
|
2021-02-19 09:55:43 +00:00
|
|
|
},
|
|
|
|
Ok(Err(e)) => {
|
|
|
|
error!(?e, "Could not start server");
|
|
|
|
global_state.singleplayer = None;
|
2021-04-26 01:30:17 +00:00
|
|
|
self.init = InitState::None;
|
2021-02-19 09:55:43 +00:00
|
|
|
self.main_menu_ui.cancel_connection();
|
|
|
|
self.main_menu_ui.show_info(format!("Error: {:?}", e));
|
|
|
|
},
|
|
|
|
Err(_) => (),
|
2020-07-21 09:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Handle window events.
|
|
|
|
for event in events {
|
2020-11-13 04:39:47 +00:00
|
|
|
// Pass all events to the ui first.
|
|
|
|
if self.main_menu_ui.handle_event(event.clone()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
match event {
|
|
|
|
Event::Close => return PlayStateResult::Shutdown,
|
|
|
|
// Ignore all other events.
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Poll client creation.
|
2021-04-26 01:30:17 +00:00
|
|
|
match self.init.client().and_then(|init| init.poll()) {
|
2019-10-27 07:11:18 +00:00
|
|
|
Some(InitMsg::Done(Ok(mut client))) => {
|
|
|
|
// Register voxygen components / resources
|
|
|
|
crate::ecs::init(client.state_mut().ecs_mut());
|
2021-04-27 00:12:44 +00:00
|
|
|
self.init = InitState::Pipeline(Box::new(client));
|
2019-10-27 07:11:18 +00:00
|
|
|
},
|
2021-05-17 17:32:26 +00:00
|
|
|
Some(InitMsg::Done(Err(e))) => {
|
2021-04-26 01:30:17 +00:00
|
|
|
self.init = InitState::None;
|
2021-06-16 06:23:13 +00:00
|
|
|
error!(?e, "Client Init failed raw error");
|
2021-05-17 17:32:26 +00:00
|
|
|
let e = get_client_msg_error(e, &global_state.i18n);
|
|
|
|
// Log error for possible additional use later or incase that the error
|
|
|
|
// displayed is cut of.
|
|
|
|
error!(?e, "Client Init failed");
|
|
|
|
global_state.info_message = Some(e);
|
2019-10-27 07:11:18 +00:00
|
|
|
},
|
|
|
|
Some(InitMsg::IsAuthTrusted(auth_server)) => {
|
|
|
|
if global_state
|
|
|
|
.settings
|
|
|
|
.networking
|
|
|
|
.trusted_auth_servers
|
|
|
|
.contains(&auth_server)
|
|
|
|
{
|
|
|
|
// Can't fail since we just polled it, it must be Some
|
2021-04-26 01:30:17 +00:00
|
|
|
self.init.client().unwrap().auth_trust(auth_server, true);
|
2019-10-27 07:11:18 +00:00
|
|
|
} else {
|
|
|
|
// Show warning that auth server is not trusted and prompt for approval
|
|
|
|
self.main_menu_ui.auth_trust_prompt(auth_server);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
None => {},
|
|
|
|
}
|
2019-05-18 20:10:02 +00:00
|
|
|
|
2021-04-26 01:30:17 +00:00
|
|
|
// Tick the client to keep the connection alive if we are waiting on pipelines
|
|
|
|
let localized_strings = &global_state.i18n.read();
|
|
|
|
if let InitState::Pipeline(client) = &mut self.init {
|
|
|
|
match client.tick(
|
|
|
|
comp::ControllerInputs::default(),
|
|
|
|
global_state.clock.dt(),
|
|
|
|
|_| {},
|
|
|
|
) {
|
|
|
|
Ok(events) => {
|
|
|
|
for event in events {
|
|
|
|
match event {
|
|
|
|
client::Event::SetViewDistance(vd) => {
|
|
|
|
global_state.settings.graphics.view_distance = vd;
|
|
|
|
global_state.settings.save_to_file_warn();
|
|
|
|
},
|
|
|
|
client::Event::Disconnect => {
|
|
|
|
global_state.info_message = Some(
|
|
|
|
localized_strings
|
|
|
|
.get("main.login.server_shut_down")
|
|
|
|
.to_owned(),
|
|
|
|
);
|
|
|
|
self.init = InitState::None;
|
|
|
|
},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
global_state.info_message =
|
|
|
|
Some(localized_strings.get("common.connection_lost").to_owned());
|
|
|
|
error!(?err, "[main menu] Failed to tick the client");
|
|
|
|
self.init = InitState::None;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Poll renderer pipeline creation
|
|
|
|
if let InitState::Pipeline(..) = &self.init {
|
|
|
|
// If not complete go to char select screen
|
|
|
|
if global_state
|
|
|
|
.window
|
|
|
|
.renderer()
|
|
|
|
.pipeline_creation_status()
|
|
|
|
.is_none()
|
|
|
|
{
|
|
|
|
// Always succeeds since we check above
|
|
|
|
if let InitState::Pipeline(client) =
|
|
|
|
core::mem::replace(&mut self.init, InitState::None)
|
|
|
|
{
|
|
|
|
self.main_menu_ui.connected();
|
|
|
|
return PlayStateResult::Push(Box::new(CharSelectionState::new(
|
|
|
|
global_state,
|
2021-04-27 00:12:44 +00:00
|
|
|
std::rc::Rc::new(std::cell::RefCell::new(*client)),
|
2021-04-26 01:30:17 +00:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
// Maintain the UI.
|
|
|
|
for event in self
|
|
|
|
.main_menu_ui
|
2020-11-10 12:30:01 +00:00
|
|
|
.maintain(global_state, global_state.clock.dt())
|
2019-10-27 07:11:18 +00:00
|
|
|
{
|
|
|
|
match event {
|
|
|
|
MainMenuEvent::LoginAttempt {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
server_address,
|
|
|
|
} => {
|
2020-06-06 04:37:29 +00:00
|
|
|
let mut net_settings = &mut global_state.settings.networking;
|
2021-05-17 17:32:26 +00:00
|
|
|
let use_quic = net_settings.use_quic;
|
2020-06-06 04:37:29 +00:00
|
|
|
net_settings.username = username.clone();
|
2020-08-30 22:32:26 +00:00
|
|
|
net_settings.default_server = server_address.clone();
|
2020-06-06 04:37:29 +00:00
|
|
|
if !net_settings.servers.contains(&server_address) {
|
|
|
|
net_settings.servers.push(server_address.clone());
|
|
|
|
}
|
2020-08-30 22:32:26 +00:00
|
|
|
global_state.settings.save_to_file_warn();
|
2020-06-06 04:37:29 +00:00
|
|
|
|
2021-05-17 17:32:26 +00:00
|
|
|
let connection_args = if use_quic {
|
|
|
|
ConnectionArgs::Quic {
|
|
|
|
hostname: server_address,
|
|
|
|
prefer_ipv6: false,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ConnectionArgs::Tcp {
|
|
|
|
hostname: server_address,
|
|
|
|
prefer_ipv6: false,
|
|
|
|
}
|
|
|
|
};
|
2019-10-27 07:11:18 +00:00
|
|
|
attempt_login(
|
2020-10-26 04:15:30 +00:00
|
|
|
&mut global_state.info_message,
|
2019-04-14 23:28:29 +00:00
|
|
|
username,
|
2019-08-07 19:42:44 +00:00
|
|
|
password,
|
2021-05-17 17:32:26 +00:00
|
|
|
connection_args,
|
2021-04-26 01:30:17 +00:00
|
|
|
&mut self.init,
|
2021-02-19 09:55:43 +00:00
|
|
|
None,
|
2019-10-27 07:11:18 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
MainMenuEvent::CancelLoginAttempt => {
|
2021-04-26 01:30:17 +00:00
|
|
|
// init contains InitState::Client(ClientInit), which spawns a thread which
|
|
|
|
// contains a TcpStream::connect() call This call is
|
|
|
|
// blocking TODO fix when the network rework happens
|
2019-09-15 20:41:47 +00:00
|
|
|
#[cfg(feature = "singleplayer")]
|
2019-10-27 07:11:18 +00:00
|
|
|
{
|
|
|
|
global_state.singleplayer = None;
|
|
|
|
}
|
2021-04-26 01:30:17 +00:00
|
|
|
self.init = InitState::None;
|
2019-10-27 07:11:18 +00:00
|
|
|
self.main_menu_ui.cancel_connection();
|
|
|
|
},
|
2020-07-20 14:07:08 +00:00
|
|
|
MainMenuEvent::ChangeLanguage(new_language) => {
|
|
|
|
global_state.settings.language.selected_language =
|
|
|
|
new_language.language_identifier;
|
2021-05-07 11:24:37 +00:00
|
|
|
global_state.i18n = LocalizationHandle::load_expect(
|
2020-07-20 14:07:08 +00:00
|
|
|
&global_state.settings.language.selected_language,
|
2021-05-07 11:24:37 +00:00
|
|
|
);
|
2020-12-12 22:14:24 +00:00
|
|
|
global_state.i18n.read().log_missing_entries();
|
2021-04-24 14:39:35 +00:00
|
|
|
global_state
|
|
|
|
.i18n
|
|
|
|
.set_english_fallback(global_state.settings.language.use_english_fallback);
|
2020-12-13 01:09:57 +00:00
|
|
|
self.main_menu_ui
|
|
|
|
.update_language(global_state.i18n, &global_state.settings);
|
2020-07-20 14:07:08 +00:00
|
|
|
},
|
2019-10-27 07:11:18 +00:00
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
MainMenuEvent::StartSingleplayer => {
|
2021-02-19 09:55:43 +00:00
|
|
|
let singleplayer = Singleplayer::new();
|
2019-01-30 12:11:34 +00:00
|
|
|
|
2020-02-08 03:26:17 +00:00
|
|
|
global_state.singleplayer = Some(singleplayer);
|
2019-10-27 07:11:18 +00:00
|
|
|
},
|
|
|
|
MainMenuEvent::Quit => return PlayStateResult::Shutdown,
|
2020-11-01 21:42:07 +00:00
|
|
|
// Note: Keeping in case we re-add the disclaimer
|
2020-06-05 06:21:23 +00:00
|
|
|
/*MainMenuEvent::DisclaimerAccepted => {
|
2019-10-27 07:11:18 +00:00
|
|
|
global_state.settings.show_disclaimer = false
|
|
|
|
},*/
|
|
|
|
MainMenuEvent::AuthServerTrust(auth_server, trust) => {
|
|
|
|
if trust {
|
|
|
|
global_state
|
|
|
|
.settings
|
|
|
|
.networking
|
|
|
|
.trusted_auth_servers
|
|
|
|
.insert(auth_server.clone());
|
|
|
|
global_state.settings.save_to_file_warn();
|
|
|
|
}
|
2021-04-26 01:30:17 +00:00
|
|
|
self.init
|
|
|
|
.client()
|
2019-10-27 07:11:18 +00:00
|
|
|
.map(|init| init.auth_trust(auth_server, trust));
|
|
|
|
},
|
2019-10-18 11:24:18 +00:00
|
|
|
}
|
2019-10-27 07:11:18 +00:00
|
|
|
}
|
2019-10-18 11:24:18 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
if let Some(info) = global_state.info_message.take() {
|
|
|
|
self.main_menu_ui.show_info(info);
|
2019-01-02 21:25:01 +00:00
|
|
|
}
|
2019-10-27 07:11:18 +00:00
|
|
|
|
|
|
|
PlayStateResult::Continue
|
2019-01-02 21:25:01 +00:00
|
|
|
}
|
2019-01-11 23:18:34 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
fn name(&self) -> &'static str { "Title" }
|
2019-10-27 07:11:18 +00:00
|
|
|
|
2021-06-05 12:55:58 +00:00
|
|
|
fn capped_fps(&self) -> bool { true }
|
|
|
|
|
2021-07-04 09:47:18 +00:00
|
|
|
fn globals_bind_group(&self) -> &GlobalsBindGroup { self.scene.global_bind_group() }
|
2020-12-04 05:38:26 +00:00
|
|
|
|
2021-07-04 09:47:18 +00:00
|
|
|
fn render<'a>(&'a self, drawer: &mut Drawer<'a>, _: &Settings) {
|
2019-10-27 07:11:18 +00:00
|
|
|
// Draw the UI to the screen.
|
2021-07-04 09:47:18 +00:00
|
|
|
let mut third_pass = drawer.third_pass();
|
|
|
|
if let Some(mut ui_drawer) = third_pass.draw_ui() {
|
2021-04-25 15:25:32 +00:00
|
|
|
self.main_menu_ui.render(&mut ui_drawer);
|
|
|
|
};
|
2019-10-27 07:11:18 +00:00
|
|
|
}
|
2021-07-04 09:47:18 +00:00
|
|
|
|
|
|
|
fn egui_enabled(&self) -> bool { false }
|
2019-01-02 21:25:01 +00:00
|
|
|
}
|
2019-10-18 20:05:37 +00:00
|
|
|
|
2021-06-16 06:23:13 +00:00
|
|
|
fn get_client_msg_error(
|
|
|
|
error: client_init::Error,
|
|
|
|
localized_strings: &LocalizationHandle,
|
|
|
|
) -> String {
|
2021-05-17 17:32:26 +00:00
|
|
|
let localization = localized_strings.read();
|
|
|
|
|
|
|
|
// When a network error is received and there is a mismatch between the client
|
|
|
|
// and server version it is almost definitely due to this mismatch rather than
|
|
|
|
// a true networking error.
|
2021-06-16 06:23:13 +00:00
|
|
|
let net_error = |error: String, mismatched_server_info: Option<ServerInfo>| -> String {
|
2021-05-17 17:32:26 +00:00
|
|
|
if let Some(server_info) = mismatched_server_info {
|
|
|
|
format!(
|
2021-06-16 06:23:13 +00:00
|
|
|
"{} {}: {} ({}) {}: {} ({})",
|
2021-05-17 17:32:26 +00:00
|
|
|
localization.get("main.login.network_wrong_version"),
|
|
|
|
localization.get("main.login.client_version"),
|
2021-06-16 06:23:13 +00:00
|
|
|
&*common::util::GIT_HASH,
|
|
|
|
&*common::util::GIT_DATE,
|
2021-05-17 17:32:26 +00:00
|
|
|
localization.get("main.login.server_version"),
|
2021-06-16 06:23:13 +00:00
|
|
|
server_info.git_hash,
|
|
|
|
server_info.git_date,
|
2021-05-17 17:32:26 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"{}: {}",
|
|
|
|
localization.get("main.login.network_error"),
|
|
|
|
error
|
|
|
|
)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
use client::Error;
|
2021-06-16 06:23:13 +00:00
|
|
|
match error {
|
2021-05-17 17:32:26 +00:00
|
|
|
InitError::ClientError {
|
|
|
|
error,
|
|
|
|
mismatched_server_info,
|
|
|
|
} => match error {
|
|
|
|
Error::SpecsErr(e) => {
|
|
|
|
format!("{}: {}", localization.get("main.login.internal_error"), e)
|
|
|
|
},
|
|
|
|
Error::AuthErr(e) => format!(
|
|
|
|
"{}: {}",
|
|
|
|
localization.get("main.login.authentication_error"),
|
|
|
|
e
|
|
|
|
),
|
|
|
|
Error::Kicked(e) => e,
|
|
|
|
Error::TooManyPlayers => localization.get("main.login.server_full").into(),
|
|
|
|
Error::AuthServerNotTrusted => {
|
|
|
|
localization.get("main.login.untrusted_auth_server").into()
|
|
|
|
},
|
|
|
|
Error::ServerTimeout => localization.get("main.login.timeout").into(),
|
|
|
|
Error::ServerShutdown => localization.get("main.login.server_shut_down").into(),
|
|
|
|
Error::NotOnWhitelist => localization.get("main.login.not_on_whitelist").into(),
|
|
|
|
Error::Banned(reason) => {
|
|
|
|
format!("{}: {}", localization.get("main.login.banned"), reason)
|
|
|
|
},
|
|
|
|
Error::InvalidCharacter => localization.get("main.login.invalid_character").into(),
|
|
|
|
Error::NetworkErr(NetworkError::ConnectFailed(NetworkConnectError::Handshake(
|
|
|
|
InitProtocolError::WrongVersion(_),
|
2021-06-16 06:23:13 +00:00
|
|
|
))) => net_error(
|
2021-05-17 17:32:26 +00:00
|
|
|
localization
|
|
|
|
.get("main.login.network_wrong_version")
|
|
|
|
.to_owned(),
|
|
|
|
mismatched_server_info,
|
|
|
|
),
|
2021-06-16 06:23:13 +00:00
|
|
|
Error::NetworkErr(e) => net_error(e.to_string(), mismatched_server_info),
|
|
|
|
Error::ParticipantErr(e) => net_error(e.to_string(), mismatched_server_info),
|
|
|
|
Error::StreamErr(e) => net_error(e.to_string(), mismatched_server_info),
|
2021-05-17 17:32:26 +00:00
|
|
|
Error::HostnameLookupFailed(e) => {
|
|
|
|
format!("{}: {}", localization.get("main.login.server_not_found"), e)
|
|
|
|
},
|
|
|
|
Error::Other(e) => {
|
|
|
|
format!("{}: {}", localization.get("common.error"), e)
|
|
|
|
},
|
|
|
|
Error::AuthClientError(e) => match e {
|
|
|
|
// TODO: remove parentheses
|
|
|
|
client::AuthClientError::RequestError(e) => format!(
|
|
|
|
"{}: {}",
|
|
|
|
localization.get("main.login.failed_sending_request"),
|
|
|
|
e
|
|
|
|
),
|
|
|
|
client::AuthClientError::JsonError(e) => format!(
|
|
|
|
"{}: {}",
|
|
|
|
localization.get("main.login.failed_sending_request"),
|
|
|
|
e
|
|
|
|
),
|
|
|
|
client::AuthClientError::InsecureSchema => {
|
|
|
|
localization.get("main.login.insecure_auth_scheme").into()
|
|
|
|
},
|
2021-06-16 06:23:13 +00:00
|
|
|
client::AuthClientError::ServerError(_, e) => String::from_utf8_lossy(&e).into(),
|
2021-05-17 17:32:26 +00:00
|
|
|
},
|
|
|
|
Error::AuthServerUrlInvalid(e) => {
|
|
|
|
format!(
|
|
|
|
"{}: https://{}",
|
|
|
|
localization.get("main.login.failed_auth_server_url_invalid"),
|
|
|
|
e
|
|
|
|
)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitError::ClientCrashed => localization.get("main.login.client_crashed").into(),
|
2021-06-16 06:51:09 +00:00
|
|
|
InitError::ServerNotFound => localization.get("main.login.server_not_found").into(),
|
2021-04-22 17:27:38 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-17 17:32:26 +00:00
|
|
|
|
2019-10-18 20:05:37 +00:00
|
|
|
fn attempt_login(
|
2020-10-26 04:15:30 +00:00
|
|
|
info_message: &mut Option<String>,
|
2019-10-18 20:05:37 +00:00
|
|
|
username: String,
|
|
|
|
password: String,
|
2021-05-17 17:32:26 +00:00
|
|
|
connection_args: ConnectionArgs,
|
2021-04-26 01:30:17 +00:00
|
|
|
init: &mut InitState,
|
2021-02-19 09:55:43 +00:00
|
|
|
runtime: Option<Arc<runtime::Runtime>>,
|
2019-10-18 20:05:37 +00:00
|
|
|
) {
|
2021-04-01 14:37:13 +00:00
|
|
|
if let Err(err) = comp::Player::alias_validate(&username) {
|
|
|
|
*info_message = Some(err.to_string());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't try to connect if there is already a connection in progress.
|
2021-04-26 01:30:17 +00:00
|
|
|
if let InitState::None = init {
|
|
|
|
*init = InitState::Client(ClientInit::new(
|
2021-04-01 14:37:13 +00:00
|
|
|
connection_args,
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
runtime,
|
|
|
|
));
|
2019-10-18 20:05:37 +00:00
|
|
|
}
|
|
|
|
}
|