mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
feat: add server whitelist
This commit is contained in:
parent
fc48d0ddec
commit
f44df23935
@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- M2 attack for bow
|
- M2 attack for bow
|
||||||
- Hotbar persistence.
|
- Hotbar persistence.
|
||||||
- Alpha version Disclaimer
|
- Alpha version Disclaimer
|
||||||
|
- Server whitelist
|
||||||
|
|
||||||
### Changed
|
### 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
|
- Gliding is now a toggle that can be triggered from the ground
|
||||||
- Replaced `log` with `tracing` in all crates
|
- Replaced `log` with `tracing` in all crates
|
||||||
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
- Wield requirement to swap loadout; fixes issue with unable swap loadout outside of combat.
|
- 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 dungeon bosses and rare boss loot
|
||||||
- Added 2 sets of armour. One Steel and one Leather.
|
- Added 2 sets of armour. One Steel and one Leather.
|
||||||
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- The /give_item command can now specify the amount of items. Syntax is now `/give_item <name> [num]`
|
- The /give_item command can now specify the amount of items. Syntax is now `/give_item <name> [num]`
|
||||||
|
@ -138,6 +138,7 @@ https://account.veloren.net."#,
|
|||||||
"main.login.failed_sending_request": "Request to Auth server failed",
|
"main.login.failed_sending_request": "Request to Auth server failed",
|
||||||
"main.login.invalid_character": "The selected character is invalid",
|
"main.login.invalid_character": "The selected character is invalid",
|
||||||
"main.login.client_crashed": "Client crashed",
|
"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
|
/// End Main screen section
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ pub enum Error {
|
|||||||
ServerTimeout,
|
ServerTimeout,
|
||||||
ServerShutdown,
|
ServerShutdown,
|
||||||
TooManyPlayers,
|
TooManyPlayers,
|
||||||
|
NotOnWhitelist,
|
||||||
AlreadyLoggedIn,
|
AlreadyLoggedIn,
|
||||||
AuthErr(String),
|
AuthErr(String),
|
||||||
AuthClientError(AuthClientError),
|
AuthClientError(AuthClientError),
|
||||||
|
@ -233,6 +233,7 @@ impl Client {
|
|||||||
RegisterError::AlreadyLoggedIn => Error::AlreadyLoggedIn,
|
RegisterError::AlreadyLoggedIn => Error::AlreadyLoggedIn,
|
||||||
RegisterError::AuthError(err) => Error::AuthErr(err),
|
RegisterError::AuthError(err) => Error::AuthErr(err),
|
||||||
RegisterError::InvalidCharacter => Error::InvalidCharacter,
|
RegisterError::InvalidCharacter => Error::InvalidCharacter,
|
||||||
|
RegisterError::NotOnWhitelist => Error::NotOnWhitelist,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
ServerMsg::StateAnswer(Ok(ClientState::Registered)) => break Ok(()),
|
ServerMsg::StateAnswer(Ok(ClientState::Registered)) => break Ok(()),
|
||||||
|
@ -101,6 +101,7 @@ pub enum RegisterError {
|
|||||||
AlreadyLoggedIn,
|
AlreadyLoggedIn,
|
||||||
AuthError(String),
|
AuthError(String),
|
||||||
InvalidCharacter,
|
InvalidCharacter,
|
||||||
|
NotOnWhitelist,
|
||||||
//TODO: InvalidAlias,
|
//TODO: InvalidAlias,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,11 @@ fn derive_uuid(username: &str) -> Uuid {
|
|||||||
pub struct AuthProvider {
|
pub struct AuthProvider {
|
||||||
accounts: HashMap<Uuid, String>,
|
accounts: HashMap<Uuid, String>,
|
||||||
auth_server: Option<AuthClient>,
|
auth_server: Option<AuthClient>,
|
||||||
|
whitelist: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuthProvider {
|
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 {
|
let auth_server = match auth_addr {
|
||||||
Some(addr) => Some(AuthClient::new(addr)),
|
Some(addr) => Some(AuthClient::new(addr)),
|
||||||
None => None,
|
None => None,
|
||||||
@ -30,6 +31,7 @@ impl AuthProvider {
|
|||||||
AuthProvider {
|
AuthProvider {
|
||||||
accounts: HashMap::new(),
|
accounts: HashMap::new(),
|
||||||
auth_server,
|
auth_server,
|
||||||
|
whitelist,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +57,13 @@ impl AuthProvider {
|
|||||||
if self.accounts.contains_key(&uuid) {
|
if self.accounts.contains_key(&uuid) {
|
||||||
return Err(RegisterError::AlreadyLoggedIn);
|
return Err(RegisterError::AlreadyLoggedIn);
|
||||||
}
|
}
|
||||||
// Log in
|
|
||||||
let username = srv.uuid_to_username(uuid)?;
|
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());
|
self.accounts.insert(uuid, username.clone());
|
||||||
Ok((username, uuid))
|
Ok((username, uuid))
|
||||||
},
|
},
|
||||||
|
@ -93,9 +93,10 @@ impl Server {
|
|||||||
pub fn new(settings: ServerSettings) -> Result<Self, Error> {
|
pub fn new(settings: ServerSettings) -> Result<Self, Error> {
|
||||||
let mut state = State::default();
|
let mut state = State::default();
|
||||||
state.ecs_mut().insert(EventBus::<ServerEvent>::default());
|
state.ecs_mut().insert(EventBus::<ServerEvent>::default());
|
||||||
state
|
state.ecs_mut().insert(AuthProvider::new(
|
||||||
.ecs_mut()
|
settings.auth_server_address.clone(),
|
||||||
.insert(AuthProvider::new(settings.auth_server_address.clone()));
|
settings.whitelist.clone(),
|
||||||
|
));
|
||||||
state.ecs_mut().insert(Tick(0));
|
state.ecs_mut().insert(Tick(0));
|
||||||
state.ecs_mut().insert(ChunkGenerator::new());
|
state.ecs_mut().insert(ChunkGenerator::new());
|
||||||
state
|
state
|
||||||
|
@ -19,6 +19,7 @@ pub struct ServerSettings {
|
|||||||
pub server_description: String,
|
pub server_description: String,
|
||||||
pub start_time: f64,
|
pub start_time: f64,
|
||||||
pub admins: Vec<String>,
|
pub admins: Vec<String>,
|
||||||
|
pub whitelist: Vec<String>,
|
||||||
/// When set to None, loads the default map file (if available); otherwise,
|
/// When set to None, loads the default map file (if available); otherwise,
|
||||||
/// uses the value of the file options to decide how to proceed.
|
/// uses the value of the file options to decide how to proceed.
|
||||||
pub map_file: Option<FileOpts>,
|
pub map_file: Option<FileOpts>,
|
||||||
@ -58,6 +59,7 @@ impl Default for ServerSettings {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|n| n.to_string())
|
.map(|n| n.to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
|
whitelist: Vec::new(),
|
||||||
persistence_db_dir: "saves".to_owned(),
|
persistence_db_dir: "saves".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,9 @@ impl PlayState for MainMenuState {
|
|||||||
client::Error::AlreadyLoggedIn => {
|
client::Error::AlreadyLoggedIn => {
|
||||||
localized_strings.get("main.login.already_logged_in").into()
|
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!(
|
client::Error::Network(e) => format!(
|
||||||
"{}: {:?}",
|
"{}: {:?}",
|
||||||
localized_strings.get("main.login.network_error"),
|
localized_strings.get("main.login.network_error"),
|
||||||
|
Loading…
Reference in New Issue
Block a user