chiark / gitweb /
much EH
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Aug 2020 12:16:04 +0000 (13:16 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Aug 2020 12:16:04 +0000 (13:16 +0100)
server.toml [new file with mode: 0644]
src/bin/otter.rs
src/bin/server.rs
src/global.rs

diff --git a/server.toml b/server.toml
new file mode 100644 (file)
index 0000000..628406d
--- /dev/null
@@ -0,0 +1 @@
+save_directory = "/home/ian/Rustup/Game/server/save"
index dff3f85acfcd54664db79c86d5bed9249a232241..1eaa972d6ec6be8c734c55b794c9a6aae8654239 100644 (file)
@@ -240,7 +240,7 @@ mod create_table {
       f.read_to_string(&mut buf).context("read")?;
       let spec : TableSpec = toml::de::from_str(&buf).context("parse")?;
       <Result<_,AE>>::Ok(spec)
-    })().context("game spec toml").with_context(|| args.file.to_owned())?;
+    })().with_context(|| args.file.to_owned()).context("read game spec")?;
 
     let _chan = connect(&ma)?;
 
index 88e7b9cb691f66512e5c3452451ef8cae68ef46f..e014a764f06650bd6c0e9bdc49814ab6c1e57230 100644 (file)
@@ -68,8 +68,19 @@ fn resource(leaf : CheckedResourceLeaf) -> io::Result<NamedFile> {
   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 = toml::de::from_str(&buf)?;
+    set_config(config);
+  };
+
   xxx_global_setup().expect("global setup failed");
 
   let cl = CommandListener::new()?;
index 82cd5ae1dc98def8c4adfd4992d768190ab5074e..6cd882da4304709cb950c8531069f796247e49ce 100644 (file)
@@ -811,11 +811,13 @@ pub fn config() -> Arc<ServerConfig> {
   GLOBAL.config.read().unwrap().clone()
 }
 
+pub fn set_config(config: ServerConfig) {
+  *GLOBAL.config.write().unwrap() = Arc::new(config)
+}
+
 impl Default for ServerConfig {
   fn default() -> ServerConfig {
-    ServerConfig {
-      save_directory: DEFAULT_SAVE_DIRECTORY.to_owned(),
-    }
+    toml::de::from_str("").expect("parse empty string as ServerConfig")
   }
 }