conduit_cli/core/io/server/
config.rs1use serde::{Deserialize, Serialize};
2use crate::core::error::{CoreError, CoreResult};
3
4#[derive(Serialize, Deserialize, Debug, Clone)]
5pub struct ServerConfig {
6 pub server: ServerSettings,
7 pub spawning: SpawningSettings,
8 pub network: NetworkSettings,
9 pub access: AccessSettings,
10 pub gateway: GatewaySettings,
11 pub resource_pack: ResourcePackSettings,
12 pub performance: PerformanceSettings,
13 pub web: WebSettings,
14}
15
16#[derive(Serialize, Deserialize, Debug, Clone)]
17pub struct ServerSettings {
18 pub name: String,
19 pub level_type: String,
20 pub seed: String,
21 pub generate_structures: bool,
22 pub allow_nether: bool,
23 pub hardcore: bool,
24 pub difficulty: String,
25 pub gamemode: String,
26 pub force_gamemode: bool,
27 pub pvp: bool,
28}
29
30#[derive(Serialize, Deserialize, Debug, Clone)]
31pub struct SpawningSettings {
32 pub monsters: bool,
33 pub animals: bool,
34 pub npcs: bool,
35 pub spawn_protection: u32,
36}
37
38#[derive(Serialize, Deserialize, Debug, Clone)]
39pub struct NetworkSettings {
40 pub port: u16,
41 pub internal_port: u16,
42 pub max_players: u32,
43 pub online_mode: bool,
44 pub prevent_proxy_connections: bool,
45 pub enforce_secure_profile: bool,
46 pub compression_threshold: i32,
47 pub tunnel_type: String,
48 pub motd: String,
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone)]
52pub struct AccessSettings {
53 pub whitelist: bool,
54 pub op_permission_level: u8,
55 pub function_permission_level: u8,
56 pub player_idle_timeout: u32,
57 pub enable_command_block: bool,
58}
59
60#[derive(Serialize, Deserialize, Debug, Clone)]
61pub struct GatewaySettings {
62 pub enabled: bool,
63 pub auto_sleep: bool,
64 pub auto_wakeup: bool,
65 pub trigger: String,
66 pub sleeping_motd: String,
67}
68
69#[derive(Serialize, Deserialize, Debug, Clone)]
70pub struct ResourcePackSettings {
71 pub url: String,
72 pub hash: String,
73 pub required: bool,
74}
75
76#[derive(Serialize, Deserialize, Debug, Clone)]
77pub struct PerformanceSettings {
78 pub view_distance: u32,
79 pub simulation_distance: u32,
80 pub entity_range: u32,
81 pub sync_chunk_writes: bool,
82 pub max_tick_time: u64,
83 pub min_ram: String,
84 pub max_ram: String,
85 pub jvm_args: Vec<String>,
86}
87
88#[derive(Serialize, Deserialize, Debug, Clone)]
89pub struct WebSettings {
90 pub enabled: bool,
91 pub bind: String,
92}
93
94impl ServerConfig {
95 pub fn load<P: AsRef<std::path::Path>>(path: P) -> CoreResult<Self> {
96 let content = std::fs::read_to_string(path)
97 .map_err(|_| CoreError::RuntimeError("Could not find config.toml".into()))?;
98 let config: ServerConfig = toml::from_str(&content)
99 .map_err(|e| CoreError::RuntimeError(format!("Error in config.toml: {}", e)))?;
100 Ok(config)
101 }
102
103 pub fn save<P: AsRef<std::path::Path>>(&self, path: P) -> CoreResult<()> {
104 let content = toml::to_string_pretty(self)
105 .map_err(|e| CoreError::RuntimeError(e.to_string()))?;
106 std::fs::write(path, content)?;
107 Ok(())
108 }
109}