diff --git a/src/main.rs b/src/main.rs index d1c86b8..57e7e52 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,11 @@ use std::{ env::args, path::PathBuf, collections::VecDeque, + sync::mpsc::{ + channel, + Sender, + }, + thread, }; use irc_proto::command::{ CapSubCommand, @@ -134,41 +139,7 @@ fn handle_message(message: Message) -> Option { return None } -fn main() { - let mut server_conf_flag = false; - let mut config_path = None; - let mut server_conf_path = None; - for arg in args().skip(1) { - match arg.as_str() { - "-s" => server_conf_flag = true, - "-h" => { - println!("Usage: mention2mail [config file] [-s server config directory]"); - }, - _ => if server_conf_flag { - server_conf_path = Some(arg); - } else { - config_path = Some(arg); - } - } - } - - let config; - - match config_path { - Some(p) => config = config::get_main_config(PathBuf::from(p)) - .expect("Could not get config"), - None => config = config::get_main_config(PathBuf::from("/etc/Mention2Mail/config.toml")) - .expect("Could not get default config in /etc/Mention2Mail/default.toml"), - } - - let mut server_configs; - - match server_conf_path { - Some(p) => server_configs = config::get_server_configs(config, PathBuf::from(p)) - .expect("Could not get server config."), - None => (), - } - +fn handle_server(config: Value, tx: Sender<[String; 4]>) { let mut stream = connect::connect_irc(&config).unwrap(); let mut message_queue = get_irc_identify_messages(&config).unwrap(); @@ -225,3 +196,47 @@ fn main() { } } +fn main() { + let mut server_conf_flag = false; + let mut config_path = None; + let mut server_conf_path = None; + for arg in args().skip(1) { + match arg.as_str() { + "-s" => server_conf_flag = true, + "-h" => { + println!("Usage: mention2mail [config file] [-s server config directory]"); + }, + _ => if server_conf_flag { + server_conf_path = Some(arg); + } else { + config_path = Some(arg); + } + } + } + + let config; + + match config_path { + Some(p) => config = config::get_main_config(PathBuf::from(p)) + .expect("Could not get config"), + None => config = config::get_main_config(PathBuf::from("/etc/Mention2Mail/config.toml")) + .expect("Could not get default config in /etc/Mention2Mail/default.toml"), + } + + let mut server_configs; + + match server_conf_path { + Some(p) => server_configs = config::get_server_configs(config, PathBuf::from(p)) + .expect("Could not get server config."), + None => (), + } + + let (tx,rx) = channel(); + + for s_conf in server_configs { + // TODO: create channel and spawn server threads + handle_server(s_conf, tx.clone()); + } + +} +