diff --git a/client/src/lib.rs b/client/src/lib.rs index b92f7036dd..5f5e9bd93c 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -50,6 +50,7 @@ use common::{ uid::{Uid, UidAllocator}, vol::RectVolSize, weather::{Weather, WeatherGrid}, + shared_server_config::ServerConstants, }; #[cfg(feature = "tracy")] use common_base::plot; use common_base::{prof_span, span}; @@ -264,6 +265,8 @@ pub struct Client { pending_chunks: HashMap, Instant>, target_time_of_day: Option, + + connected_server_constants: ServerConstants } /// Holds data related to the current players characters, as well as some @@ -355,6 +358,7 @@ impl Client { component_recipe_book, material_stats, ability_map, + server_constants, } = loop { tokio::select! { // Spawn in a blocking thread (leaving the network thread free). This is mostly @@ -744,6 +748,8 @@ impl Client { pending_chunks: HashMap::new(), target_time_of_day: None, + + connected_server_constants: server_constants }) } diff --git a/common/net/src/msg/server.rs b/common/net/src/msg/server.rs index f3434e2352..79e6cb3b2f 100644 --- a/common/net/src/msg/server.rs +++ b/common/net/src/msg/server.rs @@ -17,6 +17,7 @@ use common::{ uid::Uid, uuid::Uuid, weather::WeatherGrid, + shared_server_config::ServerConstants, }; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; @@ -66,6 +67,7 @@ pub enum ServerInit { component_recipe_book: ComponentRecipeBook, material_stats: MaterialStatManifest, ability_map: comp::item::tool::AbilityMap, + server_constants: ServerConstants }, } diff --git a/common/src/shared_server_config.rs b/common/src/shared_server_config.rs index c854011e6c..39ad2a4184 100644 --- a/common/src/shared_server_config.rs +++ b/common/src/shared_server_config.rs @@ -1,4 +1,7 @@ +use serde::{Serialize, Deserialize}; + /// Per-server constant data (configs) that stays the same for the server's life. +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ServerConstants { - day_cycle_coefficient: f64, + pub day_cycle_coefficient: f64, } \ No newline at end of file diff --git a/server/src/lib.rs b/server/src/lib.rs index 774578dd0e..374caf468f 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -82,6 +82,7 @@ use common::{ slowjob::SlowJobPool, terrain::{TerrainChunk, TerrainChunkSize}, vol::RectRasterableVol, + shared_server_config::ServerConstants, }; use common_ecs::run_now; use common_net::{ @@ -205,6 +206,8 @@ pub struct Server { metrics_shutdown: Arc, database_settings: Arc>, disconnect_all_clients_requested: bool, + + server_constants: ServerConstants, } impl Server { @@ -561,6 +564,10 @@ impl Server { #[cfg(not(feature = "worldgen"))] rtsim::init(&mut state); + let server_constants = ServerConstants { + day_cycle_coefficient: 1400.0 / settings.day_length + }; + let this = Self { state, world, @@ -571,6 +578,8 @@ impl Server { metrics_shutdown, database_settings, disconnect_all_clients_requested: false, + + server_constants, }; debug!(?settings, "created veloren server with"); diff --git a/server/src/sys/msg/register.rs b/server/src/sys/msg/register.rs index 046eb85b85..bd73f0e6fd 100644 --- a/server/src/sys/msg/register.rs +++ b/server/src/sys/msg/register.rs @@ -11,6 +11,7 @@ use common::{ recipe::{default_component_recipe_book, default_recipe_book}, resources::TimeOfDay, uid::{Uid, UidAllocator}, + shared_server_config::ServerConstants, }; use common_base::prof_span; use common_ecs::{Job, Origin, Phase, System}; @@ -349,6 +350,9 @@ impl<'a> System<'a> for Sys { component_recipe_book: default_component_recipe_book().cloned(), material_stats: (*read_data.material_stats).clone(), ability_map: (*read_data.ability_map).clone(), + server_constants: ServerConstants { + day_cycle_coefficient: 1400.0 / read_data.settings.day_length + }, })?; debug!("Done initial sync with client.");