Added ban message with reason when banned user attempts to login to server

This commit is contained in:
tylerlowrey 2020-07-30 23:34:35 -04:00 committed by Joshua Yanovski
parent f171e4e870
commit fee79720ee
6 changed files with 14 additions and 2 deletions

View File

@ -141,6 +141,7 @@ https://account.veloren.net."#,
"main.login.invalid_character": "The selected character is invalid",
"main.login.client_crashed": "Client crashed",
"main.login.not_on_whitelist": "You need a Whitelist entry by an Admin to join",
"main.login.banned": "You have been banned with the following reason",
/// End Main screen section

View File

@ -16,6 +16,7 @@ pub enum Error {
AuthErr(String),
AuthClientError(AuthClientError),
AuthServerNotTrusted,
Banned(String),
/// Persisted character data is invalid or missing
InvalidCharacter,
//TODO: InvalidAlias,

View File

@ -455,6 +455,7 @@ impl Client {
RegisterError::AuthError(err) => Error::AuthErr(err),
RegisterError::InvalidCharacter => Error::InvalidCharacter,
RegisterError::NotOnWhitelist => Error::NotOnWhitelist,
RegisterError::Banned(reason) => Error::Banned(reason),
});
},
ServerMsg::StateAnswer(Ok(ClientState::Registered)) => break Ok(()),

View File

@ -260,6 +260,7 @@ pub enum RequestStateError {
pub enum RegisterError {
AlreadyLoggedIn,
AuthError(String),
Banned(String),
InvalidCharacter,
NotOnWhitelist,
//TODO: InvalidAlias,

View File

@ -61,8 +61,9 @@ impl LoginProvider {
// if found, check name against whitelist or if user is admin
.and_then(|(username, uuid)| {
// user cannot join if they are listed on the banlist
if banlist.len() > 0 && banlist.iter().any(|x| x.0.eq_ignore_ascii_case(&username)) {
return Err(RegisterError::NotOnWhitelist);
if let Some(ban_record) = banlist.iter().find(|x| x.0.eq_ignore_ascii_case(&username)) {
// Pull reason string out of ban record and send a copy of it
return Err(RegisterError::Banned(ban_record.1.clone()));
}
// user can only join if he is admin, the whitelist is empty (everyone can join)

View File

@ -125,6 +125,13 @@ impl PlayState for MainMenuState {
client::Error::NotOnWhitelist => {
localized_strings.get("main.login.not_on_whitelist").into()
},
client::Error::Banned(reason) => {
format!(
"{}: {}",
localized_strings.get("main.login.banned"),
reason
)
},
client::Error::InvalidCharacter => {
localized_strings.get("main.login.invalid_character").into()
},