diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b0c435cb..3f8f926702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - M2 attack for bow - Hotbar persistence. - Alpha version Disclaimer +- Server whitelist ### Changed @@ -40,7 +41,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Gliding is now a toggle that can be triggered from the ground - Replaced `log` with `tracing` in all crates - ### Removed - Wield requirement to swap loadout; fixes issue with unable swap loadout outside of combat. @@ -118,7 +118,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added dungeon bosses and rare boss loot - Added 2 sets of armour. One Steel and one Leather. - ### Changed - The /give_item command can now specify the amount of items. Syntax is now `/give_item [num]` diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index cc2da69520..7bfd8c0a7a 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -138,6 +138,7 @@ https://account.veloren.net."#, "main.login.failed_sending_request": "Request to Auth server failed", "main.login.invalid_character": "The selected character is invalid", "main.login.client_crashed": "Client crashed", + "main.login.not_on_whitelist": "You are not on the whitelist. Contact Server Owner if you want to join.", /// End Main screen section diff --git a/client/src/error.rs b/client/src/error.rs index 5dd2c7d5aa..873b1ce2e8 100644 --- a/client/src/error.rs +++ b/client/src/error.rs @@ -8,6 +8,7 @@ pub enum Error { ServerTimeout, ServerShutdown, TooManyPlayers, + NotOnWhitelist, AlreadyLoggedIn, AuthErr(String), AuthClientError(AuthClientError), diff --git a/client/src/lib.rs b/client/src/lib.rs index bfd16b278c..531f8ed826 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -233,6 +233,7 @@ impl Client { RegisterError::AlreadyLoggedIn => Error::AlreadyLoggedIn, RegisterError::AuthError(err) => Error::AuthErr(err), RegisterError::InvalidCharacter => Error::InvalidCharacter, + RegisterError::NotOnWhitelist => Error::NotOnWhitelist, }); }, ServerMsg::StateAnswer(Ok(ClientState::Registered)) => break Ok(()), diff --git a/common/src/msg/server.rs b/common/src/msg/server.rs index 42501f5d7f..a428db25c0 100644 --- a/common/src/msg/server.rs +++ b/common/src/msg/server.rs @@ -101,6 +101,7 @@ pub enum RegisterError { AlreadyLoggedIn, AuthError(String), InvalidCharacter, + NotOnWhitelist, //TODO: InvalidAlias, } diff --git a/server/src/auth_provider.rs b/server/src/auth_provider.rs index d08f8e5b63..9b2c944f61 100644 --- a/server/src/auth_provider.rs +++ b/server/src/auth_provider.rs @@ -18,10 +18,11 @@ fn derive_uuid(username: &str) -> Uuid { pub struct AuthProvider { accounts: HashMap, auth_server: Option, + whitelist: Vec, } impl AuthProvider { - pub fn new(auth_addr: Option) -> Self { + pub fn new(auth_addr: Option, whitelist: Vec) -> Self { let auth_server = match auth_addr { Some(addr) => Some(AuthClient::new(addr)), None => None, @@ -30,6 +31,7 @@ impl AuthProvider { AuthProvider { accounts: HashMap::new(), auth_server, + whitelist, } } @@ -55,8 +57,13 @@ impl AuthProvider { if self.accounts.contains_key(&uuid) { return Err(RegisterError::AlreadyLoggedIn); } - // Log in let username = srv.uuid_to_username(uuid)?; + // Check if player is in whitelist + if self.whitelist.len() > 0 && !self.whitelist.contains(&username) { + return Err(RegisterError::NotOnWhitelist); + } + + // Log in self.accounts.insert(uuid, username.clone()); Ok((username, uuid)) }, diff --git a/server/src/lib.rs b/server/src/lib.rs index db19408fc0..3dddc0c031 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -93,9 +93,10 @@ impl Server { pub fn new(settings: ServerSettings) -> Result { let mut state = State::default(); state.ecs_mut().insert(EventBus::::default()); - state - .ecs_mut() - .insert(AuthProvider::new(settings.auth_server_address.clone())); + state.ecs_mut().insert(AuthProvider::new( + settings.auth_server_address.clone(), + settings.whitelist.clone(), + )); state.ecs_mut().insert(Tick(0)); state.ecs_mut().insert(ChunkGenerator::new()); state diff --git a/server/src/settings.rs b/server/src/settings.rs index 9cb9c60de2..02f6735612 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -19,6 +19,7 @@ pub struct ServerSettings { pub server_description: String, pub start_time: f64, pub admins: Vec, + pub whitelist: Vec, /// When set to None, loads the default map file (if available); otherwise, /// uses the value of the file options to decide how to proceed. pub map_file: Option, @@ -58,6 +59,7 @@ impl Default for ServerSettings { .iter() .map(|n| n.to_string()) .collect(), + whitelist: Vec::new(), persistence_db_dir: "saves".to_owned(), } } diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index 8923194f82..0cdc9b6e17 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -106,6 +106,9 @@ impl PlayState for MainMenuState { client::Error::AlreadyLoggedIn => { localized_strings.get("main.login.already_logged_in").into() }, + client::Error::NotOnWhitelist => { + localized_strings.get("main.login.not_on_whitelist").into() + }, client::Error::Network(e) => format!( "{}: {:?}", localized_strings.get("main.login.network_error"),