mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Apply saves dir override when loading settings, change whitelist to a HashSet, let admins login even if they are not on the whitelist to reflect the comments in login code
This commit is contained in:
parent
83fb26c4f9
commit
ca2bf937e6
@ -1855,7 +1855,7 @@ fn handle_whitelist(
|
||||
server
|
||||
.editable_settings_mut()
|
||||
.whitelist
|
||||
.edit(server.data_dir().as_ref(), |w| w.push(uuid));
|
||||
.edit(server.data_dir().as_ref(), |w| w.insert(uuid));
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandInfo
|
||||
@ -1867,7 +1867,7 @@ fn handle_whitelist(
|
||||
server
|
||||
.editable_settings_mut()
|
||||
.whitelist
|
||||
.edit(server.data_dir().as_ref(), |w| w.retain(|x| x != &uuid));
|
||||
.edit(server.data_dir().as_ref(), |w| w.remove(&uuid));
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandInfo
|
||||
|
@ -116,6 +116,9 @@ impl Server {
|
||||
data_dir: &std::path::Path,
|
||||
) -> Result<Self, Error> {
|
||||
info!("Server is data dir is: {}", data_dir.display());
|
||||
if settings.auth_server_address.is_none() {
|
||||
info!("Authentication is disabled");
|
||||
}
|
||||
|
||||
// persistence_db_dir is relative to data_dir
|
||||
let persistence_db_dir = data_dir.join(&settings.persistence_db_dir);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::settings::BanRecord;
|
||||
use authc::{AuthClient, AuthClientError, AuthToken, Uuid};
|
||||
use common::msg::RegisterError;
|
||||
use hashbrown::HashMap;
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use std::str::FromStr;
|
||||
use tracing::{error, info};
|
||||
|
||||
@ -53,7 +53,8 @@ impl LoginProvider {
|
||||
pub fn try_login(
|
||||
&mut self,
|
||||
username_or_token: &str,
|
||||
whitelist: &[Uuid],
|
||||
admins: &[String],
|
||||
whitelist: &HashSet<Uuid>,
|
||||
banlist: &HashMap<Uuid, BanRecord>,
|
||||
) -> Result<(String, Uuid), RegisterError> {
|
||||
self
|
||||
@ -69,7 +70,7 @@ impl LoginProvider {
|
||||
|
||||
// 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(&uuid) {
|
||||
if !whitelist.is_empty() && !whitelist.contains(&uuid) && !admins.contains(&username) {
|
||||
return Err(RegisterError::NotOnWhitelist);
|
||||
}
|
||||
|
||||
|
@ -14,16 +14,11 @@ mod json_models;
|
||||
mod models;
|
||||
mod schema;
|
||||
|
||||
extern crate diesel;
|
||||
|
||||
use common::comp;
|
||||
use diesel::{connection::SimpleConnection, prelude::*};
|
||||
use diesel_migrations::embed_migrations;
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use tracing::{info, warn};
|
||||
use std::{fs, path::Path};
|
||||
use tracing::info;
|
||||
|
||||
/// A tuple of the components that are persisted to the DB for each character
|
||||
pub type PersistedComponents = (comp::Body, comp::Stats, comp::Inventory, comp::Loadout);
|
||||
@ -49,7 +44,6 @@ impl std::io::Write for TracingOut {
|
||||
|
||||
/// Runs any pending database migrations. This is executed during server startup
|
||||
pub fn run_migrations(db_dir: &Path) -> Result<(), diesel_migrations::RunMigrationsError> {
|
||||
let db_dir = &apply_saves_dir_override(db_dir);
|
||||
let _ = fs::create_dir(format!("{}/", db_dir.display()));
|
||||
|
||||
embedded_migrations::run_with_output(
|
||||
@ -95,7 +89,6 @@ impl<'a> core::ops::Deref for VelorenTransaction<'a> {
|
||||
}
|
||||
|
||||
pub fn establish_connection(db_dir: &Path) -> QueryResult<VelorenConnection> {
|
||||
let db_dir = &apply_saves_dir_override(db_dir);
|
||||
let database_url = format!("{}/db.sqlite", db_dir.display());
|
||||
|
||||
let connection = SqliteConnection::establish(&database_url)
|
||||
@ -119,14 +112,3 @@ pub fn establish_connection(db_dir: &Path) -> QueryResult<VelorenConnection> {
|
||||
|
||||
Ok(VelorenConnection(connection))
|
||||
}
|
||||
|
||||
fn apply_saves_dir_override(db_dir: &Path) -> PathBuf {
|
||||
if let Some(saves_dir) = env::var_os("VELOREN_SAVES_DIR") {
|
||||
let path = PathBuf::from(&saves_dir);
|
||||
if path.exists() || path.parent().map(|x| x.exists()).unwrap_or(false) {
|
||||
return path;
|
||||
}
|
||||
warn!(?saves_dir, "VELOREN_SAVES_DIR points to an invalid path.");
|
||||
}
|
||||
db_dir.to_owned()
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ mod editable;
|
||||
pub use editable::EditableSetting;
|
||||
|
||||
use authc::Uuid;
|
||||
use hashbrown::HashMap;
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use portpicker::pick_unused_port;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
@ -39,7 +39,7 @@ pub struct Settings {
|
||||
/// uses the value of the file options to decide how to proceed.
|
||||
pub map_file: Option<FileOpts>,
|
||||
/// Relative paths are relative to the server data dir
|
||||
pub persistence_db_dir: String,
|
||||
pub persistence_db_dir: PathBuf,
|
||||
pub max_view_distance: Option<u32>,
|
||||
pub banned_words_files: Vec<PathBuf>,
|
||||
pub max_player_group_size: u32,
|
||||
@ -97,6 +97,7 @@ impl Settings {
|
||||
}
|
||||
default_settings
|
||||
}
|
||||
.apply_saves_dir_override()
|
||||
}
|
||||
|
||||
fn save_to_file(&self, path: &Path) -> std::io::Result<()> {
|
||||
@ -149,6 +150,18 @@ impl Settings {
|
||||
path.push(SETTINGS_FILENAME);
|
||||
path
|
||||
}
|
||||
|
||||
fn apply_saves_dir_override(mut self) -> Self {
|
||||
if let Some(saves_dir) = std::env::var_os("VELOREN_SAVES_DIR") {
|
||||
let path = PathBuf::from(&saves_dir);
|
||||
if path.exists() || path.parent().map(|x| x.exists()).unwrap_or(false) {
|
||||
self.persistence_db_dir = path;
|
||||
} else {
|
||||
warn!(?saves_dir, "VELOREN_SAVES_DIR points to an invalid path.");
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn with_config_dir(path: &Path) -> PathBuf {
|
||||
@ -165,7 +178,7 @@ pub struct BanRecord {
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(transparent)]
|
||||
pub struct Whitelist(Vec<Uuid>);
|
||||
pub struct Whitelist(HashSet<Uuid>);
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(transparent)]
|
||||
pub struct Banlist(HashMap<Uuid, BanRecord>);
|
||||
@ -215,7 +228,7 @@ impl EditableSetting for ServerDescription {
|
||||
}
|
||||
|
||||
impl Deref for Whitelist {
|
||||
type Target = Vec<Uuid>;
|
||||
type Target = HashSet<Uuid>;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ impl Sys {
|
||||
} => {
|
||||
let (username, uuid) = match login_provider.try_login(
|
||||
&token_or_username,
|
||||
&settings.admins,
|
||||
&*editable_settings.whitelist,
|
||||
&*editable_settings.banlist,
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user