Add PerPlayer server flag for BattleMode

This commit is contained in:
juliancoffee 2021-08-27 17:08:18 +03:00
parent 6b0d016418
commit f01309dfc2
2 changed files with 17 additions and 3 deletions

View File

@ -40,6 +40,12 @@ pub struct X509FilePair {
pub key: PathBuf,
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub enum ServerBattleMode {
Global(BattleMode),
PerPlayer { default: BattleMode },
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
@ -49,7 +55,7 @@ pub struct Settings {
pub quic_files: Option<X509FilePair>,
pub max_players: usize,
pub world_seed: u32,
pub battle_mode: BattleMode,
pub battle_mode: ServerBattleMode,
pub server_name: String,
pub start_time: f64,
/// When set to None, loads the default map file (if available); otherwise,
@ -79,7 +85,7 @@ impl Default for Settings {
world_seed: DEFAULT_WORLD_SEED,
server_name: "Veloren Alpha".into(),
max_players: 100,
battle_mode: BattleMode::PvP,
battle_mode: ServerBattleMode::Global(BattleMode::PvP),
start_time: 9.0 * 3600.0,
map_file: None,
max_view_distance: Some(65),

View File

@ -2,6 +2,7 @@ use crate::{
client::Client,
login_provider::{LoginProvider, PendingLogin},
metrics::PlayerMetrics,
settings::ServerBattleMode,
EditableSettings, Settings,
};
use common::{
@ -173,7 +174,14 @@ impl<'a> System<'a> for Sys {
return Ok(());
}
let player = Player::new(username, read_data.settings.battle_mode, uuid);
let battle_mode = match read_data.settings.battle_mode {
ServerBattleMode::Global(mode) => mode,
// FIXME:
// Should this use just default battle_mode
// or should we take it from last change?
ServerBattleMode::PerPlayer { default: mode } => mode,
};
let player = Player::new(username, battle_mode, uuid);
let admin = read_data.editable_settings.admins.get(&uuid);
if !player.is_valid() {