diff --git a/src/bin/patch.rs b/src/bin/patch.rs index 17bceda..a12df4e 100644 --- a/src/bin/patch.rs +++ b/src/bin/patch.rs @@ -1,10 +1,10 @@ -use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config, load_motd}; +use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config_env, load_motd}; use log::{info}; use elseware::common::mainloop::patch_mainloop; fn main() { info!("[patch] starting server"); - let patch_config = load_config(); + let patch_config = load_config_env(); let patch_motd = load_motd(); let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str()); let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd); diff --git a/src/patch/patch.rs b/src/patch/patch.rs index 6c18876..b96616e 100644 --- a/src/patch/patch.rs +++ b/src/patch/patch.rs @@ -381,7 +381,7 @@ impl Iterator for SendFileIterator { #[derive(Debug, Deserialize)] pub struct PatchConfig { pub path: String, - pub ip: String, + pub ip: String, // TODO: this does nothing pub port: u16, } @@ -403,11 +403,22 @@ pub fn load_config() -> PatchConfig { config } -pub fn load_motd() -> String { - let mut motd: String = "Welcome to Elseware!".to_string(); +pub fn load_config_env() -> PatchConfig { + let patch_path = std::env::var("PATCHFILE_DIR").unwrap(); + let patch_port = std::env::var("PATCH_PORT").unwrap().parse().unwrap(); + + PatchConfig { + path: patch_path, + ip: "127.0.0.1".into(), + port: patch_port, + } +} +pub fn load_motd() -> String { if let Ok(m) = fs::read_to_string("patch.motd") { - motd = m.clone(); + m + } + else { + "Welcome to Elseware!".to_string() } - motd }