diff options
| author | tom barrett <spalf0@gmail.com> | 2018-06-08 02:29:35 -0500 | 
|---|---|---|
| committer | tom barrett <spalf0@gmail.com> | 2018-06-08 02:29:35 -0500 | 
| commit | 01fee8c1a2449a0d086a8bde42de1d61dbdc9231 (patch) | |
| tree | b19311f55a2ca8222e4533efe72dc4b158f53193 /src | |
| parent | 11b51897dda7609b5a22a490bfb8cd2c269b5969 (diff) | |
-ability to have login data / server info come in from config file
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/client.rs | 45 | 
1 files changed, 37 insertions, 8 deletions
| diff --git a/src/bin/client.rs b/src/bin/client.rs index f9aa038..24a87b8 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -1,7 +1,12 @@  extern crate space; +extern crate toml;  extern crate serde_json; +#[macro_use] +extern crate serde_derive; +  use std::io; +use std::fs::File;  use std::io::BufReader;  use std::io::prelude::*;  use std::net::TcpStream; @@ -13,19 +18,43 @@ use space::client::refinery::client_refinery;  use space::client::dashboard::client_dashboard;  use space::client::navigation::client_navigation; +#[derive(Debug, Deserialize)] +struct Config { +    username    : Option<String>, +    password    : Option<String>, +    server      : Option<String>, +} +  fn main() { +    let send; +    let server;      let mut name = String::new(); -    println!("Ship Name:"); -    io::stdin().read_line(&mut name).expect("Failed"); -    name = name.replace("\n", ""); -    let mut password = String::new(); -    println!("Password:"); -    io::stdin().read_line(&mut password).expect("Failed"); +    match File::open(".space") { +        Ok(mut config_file) => { +            let mut config_string = String::new(); +            config_file.read_to_string(&mut config_string).unwrap(); +            let config : Config = toml::from_str(&config_string).unwrap(); -    let send = name.clone() + ":" + &password; +            server = config.server.unwrap(); +            name = config.username.unwrap(); +            send = name.clone() + ":" + &config.password.unwrap() + "\n"; +        }, +        Err(_err) => { +            println!("Ship Name:"); +            io::stdin().read_line(&mut name).expect("Failed"); +            name = name.replace("\n", ""); + +            let mut password = String::new(); +            println!("Password:"); +            io::stdin().read_line(&mut password).expect("Failed"); + +            server = "localhost:6000".to_string(); +            send = name.clone() + ":" + &password; +        }, +    } -    let mut stream = TcpStream::connect("localhost:6000").unwrap(); +    let mut stream = TcpStream::connect(&server).unwrap();      let mut buff_r = BufReader::new(stream.try_clone().unwrap());      stream.write(send.as_bytes()).unwrap(); | 
