summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-06-08 02:29:35 -0500
committertom barrett <spalf0@gmail.com>2018-06-08 02:29:35 -0500
commit01fee8c1a2449a0d086a8bde42de1d61dbdc9231 (patch)
treeb19311f55a2ca8222e4533efe72dc4b158f53193
parent11b51897dda7609b5a22a490bfb8cd2c269b5969 (diff)
-ability to have login data / server info come in from config file
-rw-r--r--.space3
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--README.md2
-rw-r--r--src/bin/client.rs45
5 files changed, 51 insertions, 10 deletions
diff --git a/.space b/.space
new file mode 100644
index 0000000..4a9c315
--- /dev/null
+++ b/.space
@@ -0,0 +1,3 @@
+username = "tom"
+password = "pass"
+server = "localhost:6000"
diff --git a/Cargo.lock b/Cargo.lock
index b40bfd8..6160261 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -117,6 +117,7 @@ dependencies = [
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -148,6 +149,14 @@ dependencies = [
]
[[package]]
+name = "toml"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -191,6 +200,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
+"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
diff --git a/Cargo.toml b/Cargo.toml
index b0b82c1..cbb856f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,3 +9,4 @@ serde_derive = "1.0"
serde_json = "1.0"
termion = "1.5.1"
rand = "0.4"
+toml = "0.4"
diff --git a/README.md b/README.md
index 797766f..05ec88c 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,12 @@
space
ideas
-- refinery module (processes minerals)
- construction module (upgrade ship, create stations which perform module functions better and cheaper)
- weapons modules
- communication module (various ranges of tx/rx, encryption of messages)
- tiers of minerals, modules
- pretty dashboard
- better client cli parsing (e.g. ability to do ./client navigation)
-- ability to have login data come from config file (among other useful settings)
- some sort of energy / fuel mechanic
- server ability to quit and import/export all data
- collisions
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();