configs/
lib.rs

1pub mod abilities;
2pub mod ads_settings;
3pub mod afk_rewards;
4pub mod buffs;
5pub mod cheats;
6pub mod config;
7pub mod events;
8pub mod fighting;
9pub mod game_config;
10pub mod game_settings;
11pub mod matchmaking;
12pub mod pets;
13pub mod reports;
14pub mod statue;
15pub mod tests_game_config;
16pub mod tutorial;
17pub mod validated_types;
18pub mod vassals;
19
20pub use config::Config;
21
22use arc_swap::ArcSwap;
23use std::sync::{
24    Arc,
25    atomic::{AtomicU64, Ordering},
26};
27
28#[derive(Clone, Debug)]
29pub struct SharedGameConfig {
30    inner: Arc<ArcSwap<game_config::GameConfig>>,
31    version: Arc<AtomicU64>,
32}
33
34impl SharedGameConfig {
35    pub fn new(config: game_config::GameConfig) -> Self {
36        Self {
37            inner: Arc::new(ArcSwap::from_pointee(config)),
38            version: Arc::new(AtomicU64::new(0)),
39        }
40    }
41
42    pub fn get(&self) -> Arc<game_config::GameConfig> {
43        self.inner.load_full()
44    }
45
46    pub fn version(&self) -> u64 {
47        self.version.load(Ordering::Relaxed)
48    }
49
50    pub fn update(&self, new_config: game_config::GameConfig) {
51        self.inner.store(Arc::new(new_config));
52        self.version.fetch_add(1, Ordering::Relaxed);
53    }
54}