Add config defaults
Anything exposed to the user probably should be robust to shit input
This commit is contained in:
parent
c6976db04c
commit
4182db1506
@ -4,7 +4,7 @@ motd = "For shits and giggles"
|
|||||||
port = 25565
|
port = 25565
|
||||||
|
|
||||||
[world]
|
[world]
|
||||||
world = "world.wrld" # Custom world type, not interchangable
|
world = "world.wrld" # Custom world type, not interchangable with other servers
|
||||||
# Generation parameters, when a world is read these are ignored
|
# Generation parameters, when a world is read these are ignored
|
||||||
size_x = 64
|
size_x = 64
|
||||||
size_y = 32
|
size_y = 32
|
||||||
|
@ -7,7 +7,8 @@ use std::{
|
|||||||
|
|
||||||
use crate::error::AppError;
|
use crate::error::AppError;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Default, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub server: ServerConfig,
|
pub server: ServerConfig,
|
||||||
pub world: WorldConfig,
|
pub world: WorldConfig,
|
||||||
@ -16,13 +17,25 @@ pub struct Config {
|
|||||||
// Hmm hmm hmm hmm... the great, iconic, symbol of nobility. My sibilantic friend, ServerSonfig.
|
// Hmm hmm hmm hmm... the great, iconic, symbol of nobility. My sibilantic friend, ServerSonfig.
|
||||||
// Your hour has passed and
|
// Your hour has passed and
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub motd: String,
|
pub motd: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ServerConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
port: 25565,
|
||||||
|
name: "Default".to_string(),
|
||||||
|
motd: "Default".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct WorldConfig {
|
pub struct WorldConfig {
|
||||||
pub world: String,
|
pub world: String,
|
||||||
pub size_x: i16,
|
pub size_x: i16,
|
||||||
@ -30,6 +43,17 @@ pub struct WorldConfig {
|
|||||||
pub size_z: i16,
|
pub size_z: i16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for WorldConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
world: "world.wrld".to_string(),
|
||||||
|
size_x: 64,
|
||||||
|
size_y: 32,
|
||||||
|
size_z: 64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load() -> Result<Self, AppError> {
|
pub fn load() -> Result<Self, AppError> {
|
||||||
// Load the config file
|
// Load the config file
|
||||||
@ -42,7 +66,7 @@ motd = "For shits and giggles"
|
|||||||
port = 25565
|
port = 25565
|
||||||
|
|
||||||
[world]
|
[world]
|
||||||
world = "world.wrld" # Custom world type, not interchangable
|
world = "world.wrld" # Custom world type, not interchangable with other servers
|
||||||
# Generation parameters, when a world is read these are ignored
|
# Generation parameters, when a world is read these are ignored
|
||||||
size_x = 64
|
size_x = 64
|
||||||
size_y = 32
|
size_y = 32
|
||||||
|
Loading…
Reference in New Issue
Block a user