feat: add server whitelist

This commit is contained in:
Songtronix 2020-06-24 17:27:18 +02:00
parent fc48d0ddec
commit f44df23935
9 changed files with 23 additions and 7 deletions

View File

@ -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 <name> [num]`

View File

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

View File

@ -8,6 +8,7 @@ pub enum Error {
ServerTimeout,
ServerShutdown,
TooManyPlayers,
NotOnWhitelist,
AlreadyLoggedIn,
AuthErr(String),
AuthClientError(AuthClientError),

View File

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

View File

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

View File

@ -18,10 +18,11 @@ fn derive_uuid(username: &str) -> Uuid {
pub struct AuthProvider {
accounts: HashMap<Uuid, String>,
auth_server: Option<AuthClient>,
whitelist: Vec<String>,
}
impl AuthProvider {
pub fn new(auth_addr: Option<String>) -> Self {
pub fn new(auth_addr: Option<String>, whitelist: Vec<String>) -> 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))
},

View File

@ -93,9 +93,10 @@ impl Server {
pub fn new(settings: ServerSettings) -> Result<Self, Error> {
let mut state = State::default();
state.ecs_mut().insert(EventBus::<ServerEvent>::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

View File

@ -19,6 +19,7 @@ pub struct ServerSettings {
pub server_description: String,
pub start_time: f64,
pub admins: Vec<String>,
pub whitelist: Vec<String>,
/// 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<FileOpts>,
@ -58,6 +59,7 @@ impl Default for ServerSettings {
.iter()
.map(|n| n.to_string())
.collect(),
whitelist: Vec::new(),
persistence_db_dir: "saves".to_owned(),
}
}

View File

@ -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"),