kubi/kubi-server/src/config.rs

38 lines
930 B
Rust
Raw Normal View History

2023-02-11 17:37:24 -06:00
use shipyard::{AllStoragesView, Unique};
use serde::{Serialize, Deserialize};
use std::{fs, net::SocketAddr};
#[derive(Serialize, Deserialize)]
pub struct ConfigTableServer {
pub address: SocketAddr,
pub max_clients: usize,
2023-02-12 18:53:55 -06:00
pub timeout_ms: u64,
2023-02-13 21:27:27 -06:00
pub password: Option<String>,
2023-02-11 17:37:24 -06:00
}
2023-03-06 21:50:06 -06:00
#[derive(Serialize, Deserialize)]
pub struct ConfigTableWorld {
pub seed: u64,
}
2023-03-08 20:30:37 -06:00
#[derive(Serialize, Deserialize)]
pub struct ConfigTableQuery {
pub name: Option<String>
}
2023-02-11 17:37:24 -06:00
#[derive(Unique, Serialize, Deserialize)]
pub struct ConfigTable {
2023-03-06 21:50:06 -06:00
pub server: ConfigTableServer,
pub world: ConfigTableWorld,
2023-03-08 20:30:37 -06:00
pub query: ConfigTableQuery,
2023-02-11 17:37:24 -06:00
}
pub fn read_config(
storages: AllStoragesView,
) {
log::info!("Reading config...");
let config_str = fs::read_to_string("Server.toml").expect("No config file found");
let config: ConfigTable = toml::from_str(&config_str).expect("Invalid configuration file");
storages.add_unique(config);
}