summaryrefslogtreecommitdiff
path: root/src/bin/client.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
committertom barrett <spalf0@gmail.com>2019-02-03 05:45:35 -0600
commit46fa862e04bc43311ba79ef3db70abf9014b9104 (patch)
tree3507873ec788af1f1e0885bbb676dbb4a373d48e /src/bin/client.rs
parent828f0d83dcb258a8e5efd55a7775592c6e5f77bc (diff)
bringing to 2018
Diffstat (limited to 'src/bin/client.rs')
-rw-r--r--src/bin/client.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/bin/client.rs b/src/bin/client.rs
index 3353e87..e452492 100644
--- a/src/bin/client.rs
+++ b/src/bin/client.rs
@@ -1,29 +1,29 @@
+extern crate serde_json;
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;
use std::io::prelude::*;
+use std::io::BufReader;
use std::net::TcpStream;
-use space::modules::types::ModuleType;
-use space::client::mining::client_mining;
-use space::client::engines::client_engines;
-use space::client::refinery::client_refinery;
+use space::client::construction::client_construction;
use space::client::dashboard::client_dashboard;
+use space::client::engines::client_engines;
+use space::client::mining::client_mining;
use space::client::navigation::client_navigation;
-use space::client::construction::client_construction;
+use space::client::refinery::client_refinery;
+use space::modules::types::ModuleType;
#[derive(Debug, Deserialize)]
struct Config {
- username : Option<String>,
- password : Option<String>,
- server : Option<String>,
+ username: Option<String>,
+ password: Option<String>,
+ server: Option<String>,
}
fn main() {
@@ -35,12 +35,12 @@ fn main() {
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 config: Config = toml::from_str(&config_string).unwrap();
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");
@@ -52,17 +52,17 @@ fn main() {
server = "localhost:6000".to_string();
send = name.clone() + ":" + &password;
- },
+ }
}
let mut stream = TcpStream::connect(&server).unwrap();
let mut buff_r = BufReader::new(stream.try_clone().unwrap());
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
let mut recv = String::new();
buff_r.read_line(&mut recv).unwrap();
- let modules : Vec<ModuleType> = serde_json::from_str(&recv.replace("\n","")).unwrap();
+ let modules: Vec<ModuleType> = serde_json::from_str(&recv.replace("\n", "")).unwrap();
println!("Choose your module:");
for (i, module) in modules.iter().enumerate() {
@@ -71,10 +71,13 @@ fn main() {
let mut choice = String::new();
io::stdin().read_line(&mut choice).expect("Failed");
- let module_type = modules.into_iter().nth(choice.replace("\n", "").parse::<usize>().unwrap()).unwrap();
+ let module_type = modules
+ .into_iter()
+ .nth(choice.replace("\n", "").parse::<usize>().unwrap())
+ .unwrap();
let send = serde_json::to_string(&module_type).unwrap() + "\n";
- stream.write(send.as_bytes()).unwrap();
+ stream.write_all(send.as_bytes()).unwrap();
match module_type {
ModuleType::Dashboard => client_dashboard(buff_r),