From e5e3349fb6978920740d5c5041cc96fb1e688e9c Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 27 Aug 2021 17:08:18 +0300 Subject: [PATCH] Add PerPlayer server flag for BattleMode --- server/src/settings.rs | 10 ++++++++-- server/src/sys/msg/register.rs | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/src/settings.rs b/server/src/settings.rs index 5c17adb5e1..7e45e3d668 100644 --- a/server/src/settings.rs +++ b/server/src/settings.rs @@ -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, 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), diff --git a/server/src/sys/msg/register.rs b/server/src/sys/msg/register.rs index 816640be05..a2a5b3cbf9 100644 --- a/server/src/sys/msg/register.rs +++ b/server/src/sys/msg/register.rs @@ -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() {