mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added banlist check to try_login method
This commit is contained in:
parent
f402df2c56
commit
c3c4b88fe7
@ -26,7 +26,6 @@ use world::util::Sampler;
|
||||
|
||||
use scan_fmt::{scan_fmt, scan_fmt_some};
|
||||
use tracing::error;
|
||||
use crate::auth_provider::AuthProvider;
|
||||
|
||||
pub trait ChatCommandExt {
|
||||
fn execute(&self, server: &mut Server, entity: EcsEntity, args: String);
|
||||
|
@ -53,12 +53,18 @@ impl LoginProvider {
|
||||
&mut self,
|
||||
username_or_token: &str,
|
||||
whitelist: &[String],
|
||||
banlist: &[(String, String)]
|
||||
) -> Result<(String, Uuid), RegisterError> {
|
||||
self
|
||||
// resolve user information
|
||||
.query(username_or_token)
|
||||
// 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);
|
||||
}
|
||||
|
||||
// user can only join if he is admin, the whitelist is empty (everyone can join)
|
||||
// or his name is in the whitelist
|
||||
if !whitelist.is_empty() && !whitelist.contains(&username) {
|
||||
|
@ -89,7 +89,7 @@ impl Sys {
|
||||
token_or_username,
|
||||
} => {
|
||||
let (username, uuid) =
|
||||
match login_provider.try_login(&token_or_username, &settings.whitelist) {
|
||||
match login_provider.try_login(&token_or_username, &settings.whitelist, &settings.banlist) {
|
||||
Err(err) => {
|
||||
client.error_state(RequestStateError::RegisterDenied(err));
|
||||
break Ok(());
|
||||
|
Loading…
Reference in New Issue
Block a user