NamedFile::open(format!("{}/{}", template_dir, leaf.safe))
}
-const DEFAULT_CONFIG_FILENAME : &str = "server.toml";
-
#[throws(StartupError)]
fn main() {
- {
- let config_filename = env::args().nth(1)
- .unwrap_or(DEFAULT_CONFIG_FILENAME.to_owned());
- let mut buf = String::new();
- File::open(config_filename)?.read_to_string(&mut buf)?;
- let config : ServerConfigSpec = toml::de::from_str(&buf)?;
- let config = config.try_into()?;
- set_config(config);
- };
+ let config_filename = env::args().nth(1);
+ ServerConfig::read(config_filename.as_ref().map(String::as_str))?;
load_games()?;
// ========== server config ==========
+const DEFAULT_CONFIG_FILENAME : &str = "server.toml";
+
const DEFAULT_SAVE_DIRECTORY : &str = "save";
pub const DEFAULT_COMMAND_SOCKET : &str = "command.socket"; // in save dir
// ^ xxx should not be pub
GLOBAL.config.read().unwrap().clone()
}
-pub fn set_config(config: ServerConfig) {
+fn set_config(config: ServerConfig) {
*GLOBAL.config.write().unwrap() = Arc::new(config)
}
+impl ServerConfig {
+ #[throws(StartupError)]
+ pub fn read(config_filename: Option<&str>) {
+ let config_filename = config_filename
+ .unwrap_or_else(|| DEFAULT_CONFIG_FILENAME);
+ let mut buf = String::new();
+ File::open(config_filename)?.read_to_string(&mut buf)?;
+ let config : ServerConfigSpec = toml::de::from_str(&buf)?;
+ let config = config.try_into()?;
+ set_config(config);
+ }
+}
+
impl Default for ServerConfig {
fn default() -> ServerConfig {
let spec : ServerConfigSpec = toml::de::from_str("")