Added banlist check to try_login method

This commit is contained in:
tylerlowrey 2020-07-30 22:07:03 -04:00 committed by Joshua Yanovski
parent f402df2c56
commit c3c4b88fe7
3 changed files with 7 additions and 2 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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(());