feat(auth): localisation of authentication errors

This commit is contained in:
Songtronix 2020-02-02 09:05:58 +01:00 committed by Marcel Märtens
parent a04c1b1d1d
commit d2e12fd166
3 changed files with 62 additions and 30 deletions

View File

@ -65,6 +65,8 @@ VoxygenLocalization(
"common.disclaimer": "Disclaimer",
"common.cancel": "Cancel",
"common.none": "None",
"common.error": "Error",
"common.fatal_error": "Fatal Error",
// Message when connection to the server is lost
"common.connection_lost": r#"Connection lost!
@ -121,7 +123,17 @@ to play on auth-enabled servers.
You can create an account over at
https://account.veloren.net."#,
"main.login.server_not_found": "Server not found",
"main.login.authentication_error": "Auth error on server",
"main.login.server_full": "Server is full",
"main.login.untrusted_auth_server": "Auth server not trusted",
"main.login.outdated_client_or_server": "ServerWentMad: Probably versions are incompatible, check for updates.",
"main.login.timeout": "Timeout: Server did not respond in time. (Overloaded or network issues).",
"main.login.server_shut_down": "Server shut down",
"main.login.already_logged_in": "You are already logged into the server.",
"main.login.network_error": "Network error",
"main.login.failed_sending_request": "Request to Auth server failed",
"main.login.client_crashed": "Client crashed",
/// End Main screen section

View File

@ -6,7 +6,7 @@ use crate::{
singleplayer::Singleplayer, window::Event, Direction, GlobalState, PlayState, PlayStateResult,
};
use client_init::{ClientInit, Error as InitError, Msg as InitMsg};
use common::{clock::Clock, comp};
use common::{assets::load_expect, clock::Clock, comp};
use log::{error, warn};
#[cfg(feature = "singleplayer")]
use std::time::Duration;
@ -27,8 +27,6 @@ impl MainMenuState {
const DEFAULT_PORT: u16 = 14004;
static LOGIN_FAILED_MSG: &str = "If you are having issues signing in. Please note that you now need an account to play on auth-enabled servers.\nYou can create an account over at https://account.veloren.net.";
impl PlayState for MainMenuState {
fn play(&mut self, _: Direction, global_state: &mut GlobalState) -> PlayStateResult {
// Set up an fps clock.
@ -45,6 +43,10 @@ impl PlayState for MainMenuState {
// Reset singleplayer server if it was running already
global_state.singleplayer = None;
let localized_strings = load_expect::<crate::i18n::VoxygenLocalization>(
&crate::i18n::i18n_asset_key(&global_state.settings.language.selected_language),
);
loop {
// Handle window events.
for event in global_state.window.fetch_events(&mut global_state.settings) {
@ -77,39 +79,57 @@ impl PlayState for MainMenuState {
global_state.info_message = Some({
let err = match err {
InitError::BadAddress(_) | InitError::NoAddress => {
"Server not found".into()
localized_strings.get("main.login.server_not_found").into()
},
InitError::ClientError(err) => match err {
client::Error::AuthErr(e) => format!("Auth error on server: {}", e),
client::Error::TooManyPlayers => "Server is full".into(),
client::Error::AuthServerNotTrusted => {
"Auth server not trusted".into()
client::Error::AuthErr(e) => format!(
"{}: {}",
localized_strings.get("main.login.authentication_error"),
e
),
client::Error::TooManyPlayers => {
localized_strings.get("main.login.server_full").into()
},
client::Error::ServerWentMad => "ServerWentMad: Probably versions \
are incompatible, check for \
updates."
client::Error::AuthServerNotTrusted => localized_strings
.get("main.login.untrusted_auth_server")
.into(),
client::Error::ServerTimeout => "Timeout: Server did not respond \
in time. (Overloaded or network \
issues)."
client::Error::ServerWentMad => localized_strings
.get("main.login.outdated_client_or_server")
.into(),
client::Error::ServerShutdown => "Server shut down".into(),
client::Error::ServerTimeout => {
localized_strings.get("main.login.timeout").into()
},
client::Error::ServerShutdown => {
localized_strings.get("main.login.server_shut_down").into()
},
client::Error::AlreadyLoggedIn => {
"You are already logged into the server.".into()
localized_strings.get("main.login.already_logged_in").into()
},
client::Error::Network(e) => format!(
"{}: {:?}",
localized_strings.get("main.login.network_error"),
e
),
client::Error::Other(e) => {
format!("{}: {}", localized_strings.get("common.error"), e)
},
client::Error::Network(e) => format!("Network error: {:?}", e),
client::Error::Other(e) => format!("Error: {}", e),
client::Error::AuthClientError(e) => match e {
client::AuthClientError::JsonError(e) => {
format!("Fatal error: {}", e)
},
client::AuthClientError::RequestError(_) => {
LOGIN_FAILED_MSG.into()
},
client::AuthClientError::JsonError(e) => format!(
"{}: {}",
localized_strings.get("common.fatal_error"),
e
),
client::AuthClientError::RequestError(_) => format!(
"{}: {}",
localized_strings.get("main.login.failed_sending_request"),
e
),
client::AuthClientError::ServerError(_, e) => format!("{}", e),
},
},
InitError::ClientCrashed => "Client crashed".into(),
InitError::ClientCrashed => {
localized_strings.get("main.login.client_crashed").into()
},
};
// Log error for possible additional use later or incase that the error
// displayed is cut of.

View File

@ -364,16 +364,16 @@ impl MainMenuUi {
.hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press)
.label_y(Relative::Scalar(2.0))
.label("Add")
.label_font_id(self.fonts.cyri.conrod_id)
.label_font_size(self.fonts.cyri.scale(15))
.label("Add") // TODO: localize
.label_font_id(self.fonts.cyri)
.label_font_size(15)
.label_color(TEXT_COLOR)
.set(self.ids.button_add_auth_trust, ui_widgets)
.was_clicked()
{
events.push(Event::AuthServerTrust(auth_server.clone(), true));
change_popup = Some(Some(PopupData {
msg: "Connecting...".to_string(),
msg: localized_strings.get("main.connecting").into(),
popup_type: PopupType::ConnectionInfo,
}));
}