summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-03-21 09:48:59 -0500
committertom barrett <spalf0@gmail.com>2019-03-21 09:48:59 -0500
commit6fb0b0d918963a22aeb4050139e8d0000c74a9ff (patch)
tree72c9ff1d51fbf8d599ad27730b5feab4d921c0a2 /src
parent69aa9f090d551c1ebb211f3a01273b28421fc9c0 (diff)
simplified client sending and added more tractorbeam options
Diffstat (limited to 'src')
-rw-r--r--src/client/construction.rs17
-rw-r--r--src/client/dashboard.rs12
-rw-r--r--src/client/engines.rs17
-rw-r--r--src/client/mining.rs17
-rw-r--r--src/client/navigation.rs25
-rw-r--r--src/client/refinery.rs17
-rw-r--r--src/client/tractorbeam.rs48
7 files changed, 79 insertions, 74 deletions
diff --git a/src/client/construction.rs b/src/client/construction.rs
index 28a91be..b555601 100644
--- a/src/client/construction.rs
+++ b/src/client/construction.rs
@@ -13,7 +13,7 @@ use crate::modules::construction;
pub fn client_construction(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut stdin = async_stdin();
loop {
let mut recv = String::new();
@@ -41,16 +41,13 @@ pub fn client_construction(mut stream: TcpStream, mut buff_r: BufReader<TcpStrea
.unwrap();
}
- if let Some(c) = stdin.next() {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write_all(send.as_bytes()).unwrap();
+ let mut key = String::new();
+ stdin.read_to_string(&mut key).unwrap();
+ if key.as_str() == "q" {
+ break;
}
+ key.push_str("\n");
+ stream.write_all(key.as_bytes()).unwrap();
stdout.flush().unwrap();
}
diff --git a/src/client/dashboard.rs b/src/client/dashboard.rs
index ec1fd4b..c6e7718 100644
--- a/src/client/dashboard.rs
+++ b/src/client/dashboard.rs
@@ -11,7 +11,7 @@ use crate::mass::Mass;
pub fn client_dashboard(mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut stdin = async_stdin();
loop {
let mut recv = String::new();
@@ -27,12 +27,12 @@ pub fn client_dashboard(mut buff_r: BufReader<TcpStream>) {
)
.unwrap();
- if let Some(c) = stdin.next() {
- let c = c.unwrap() as char;
- if c == 'q' {
- break;
- }
+ let mut key = String::new();
+ stdin.read_to_string(&mut key).unwrap();
+ if key.as_str() == "q" {
+ break;
}
+
stdout.flush().unwrap();
}
}
diff --git a/src/client/engines.rs b/src/client/engines.rs
index 52af206..8cb709e 100644
--- a/src/client/engines.rs
+++ b/src/client/engines.rs
@@ -14,7 +14,7 @@ use crate::modules::engines;
pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut stdin = async_stdin();
loop {
let mut recv = String::new();
@@ -50,16 +50,13 @@ pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
.unwrap();
}
- if let Some(c) = stdin.next() {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write_all(send.as_bytes()).unwrap();
+ let mut key = String::new();
+ stdin.read_to_string(&mut key).unwrap();
+ if key.as_str() == "q" {
+ break;
}
+ key.push_str("\n");
+ stream.write_all(key.as_bytes()).unwrap();
stdout.flush().unwrap();
sleep(Duration::from_millis(100));
diff --git a/src/client/mining.rs b/src/client/mining.rs
index c9ad3dc..5c69ef8 100644
--- a/src/client/mining.rs
+++ b/src/client/mining.rs
@@ -12,7 +12,7 @@ use crate::modules::mining;
pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut stdin = async_stdin();
loop {
let mut recv = String::new();
@@ -47,16 +47,13 @@ pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
write!(stdout, "{}Ship has no astroid targeted.", clear).unwrap();
}
- if let Some(c) = stdin.next() {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write_all(send.as_bytes()).unwrap();
+ let mut key = String::new();
+ stdin.read_to_string(&mut key).unwrap();
+ if key.as_str() == "q" {
+ break;
}
+ key.push_str("\n");
+ stream.write_all(key.as_bytes()).unwrap();
stdout.flush().unwrap();
}
diff --git a/src/client/navigation.rs b/src/client/navigation.rs
index 7e6959b..ba6d912 100644
--- a/src/client/navigation.rs
+++ b/src/client/navigation.rs
@@ -12,7 +12,7 @@ use crate::modules::navigation;
pub fn client_navigation(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut stdin = async_stdin();
loop {
let mut recv = String::new();
@@ -51,20 +51,19 @@ pub fn client_navigation(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>
.unwrap();
}
- if let Some(c) = stdin.next() {
- let c = c.unwrap() as char;
- if c == 'q' {
- break;
- } else {
- let i = c.to_digit(10).unwrap() as usize;
- if i < navigation_data.available_targets.len() {
- let mut send = String::new();
- send.push_str(&navigation_data.available_targets[i].0);
- send.push_str("\n");
- stream.write_all(send.as_bytes()).unwrap();
- }
+ let mut key = String::new();
+ stdin.read_to_string(&mut key).unwrap();
+ if key.as_str() == "q" {
+ break;
+ } else {
+ let mut send = String::new();
+ if let Ok(i) = key.parse::<usize>() {
+ send.push_str(&navigation_data.available_targets[i].0);
+ send.push_str("\n");
+ stream.write_all(send.as_bytes()).unwrap();
}
}
+
stdout.flush().unwrap();
}
}
diff --git a/src/client/refinery.rs b/src/client/refinery.rs
index 99d4be7..9b16c94 100644
--- a/src/client/refinery.rs
+++ b/src/client/refinery.rs
@@ -12,7 +12,7 @@ use crate::modules::refinery;
pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut stdin = async_stdin();
loop {
let mut recv = String::new();
@@ -34,16 +34,13 @@ pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>)
write!(stdout, "{}You have no crude minerals.", clear).unwrap();
}
- if let Some(c) = stdin.next() {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write_all(send.as_bytes()).unwrap();
+ let mut key = String::new();
+ stdin.read_to_string(&mut key).unwrap();
+ if key.as_str() == "q" {
+ break;
}
+ key.push_str("\n");
+ stream.write_all(key.as_bytes()).unwrap();
stdout.flush().unwrap();
}
diff --git a/src/client/tractorbeam.rs b/src/client/tractorbeam.rs
index c8a6d92..0274886 100644
--- a/src/client/tractorbeam.rs
+++ b/src/client/tractorbeam.rs
@@ -6,13 +6,19 @@ use self::termion::raw::IntoRawMode;
use std::io::{stdout, Read, Write};
use std::io::{BufRead, BufReader};
use std::net::TcpStream;
+use std::str::FromStr;
use crate::modules::tractorbeam;
pub fn client_tractorbeam(mut stream: TcpStream, mut buff_r: BufReader<TcpStream>) {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
- let mut stdin = async_stdin().bytes();
+ let mut async_in = async_stdin();
+
+ let mut server_recv_data = tractorbeam::ServerRecvData {
+ key: String::from_str("").unwrap(),
+ desired_distance: None,
+ };
loop {
let mut recv = String::new();
@@ -22,30 +28,36 @@ pub fn client_tractorbeam(mut stream: TcpStream, mut buff_r: BufReader<TcpStream
write!(stdout, "{}", termion::clear::All).unwrap();
let clear = termion::cursor::Goto(1, 1);
-
if data.has_target {
match data.status {
tractorbeam::Status::None => write!(
stdout,
- "{}Press o to pull, p to push, b to bring to 5m.",
+ "{}Press o to pull, p to push, b to bring to a specific distance, a to acquire item.",
clear
)
.unwrap(),
tractorbeam::Status::Push => write!(
stdout,
- "{}Press o to pull, p to stop pushing, b to bring to 5m.",
+ "{}Press o to pull, p to stop pushing, b to bring to a specific distance, a to acquire item.",
clear
)
.unwrap(),
tractorbeam::Status::Pull => write!(
stdout,
- "{}Press o to stop pulling, p to push, b to bring to 5m.",
+ "{}Press o to stop pulling, p to push, b to bring to a specific distance, a to acquire item.",
clear
)
.unwrap(),
tractorbeam::Status::Bring => write!(
stdout,
- "{}Press o to pulling, p to push, b to stop bringing to 5m.",
+ "{}Press o to pull, p to push, b to stop bringing to {} m, a to acquire item.",
+ clear,
+ data.desired_distance.unwrap(),
+ )
+ .unwrap(),
+ tractorbeam::Status::Acquire => write!(
+ stdout,
+ "{}Press o to pull, p to push, b to bring to a specific distance, a to stop acquiring the item.",
clear
)
.unwrap(),
@@ -54,16 +66,22 @@ pub fn client_tractorbeam(mut stream: TcpStream, mut buff_r: BufReader<TcpStream
write!(stdout, "{}You have no target.", clear).unwrap();
}
- if let Some(c) = stdin.next() {
- let c = c.unwrap();
- let mut send = String::new();
- send.push(c as char);
- if send.as_bytes() == b"q" {
- break;
- }
- send.push_str("\n");
- stream.write_all(send.as_bytes()).unwrap();
+ server_recv_data.desired_distance = None;
+
+ let mut key = String::new();
+ async_in.read_to_string(&mut key).unwrap();
+
+ if key.as_str() == "q" {
+ break;
+ } else if key.as_str() == "b" && data.has_target {
+ server_recv_data.desired_distance = Some(5.0);
}
+
+ server_recv_data.key = key.to_string();
+
+ let send = serde_json::to_string(&server_recv_data).unwrap() + "\n";
+ stream.write_all(send.as_bytes()).unwrap();
+
stdout.flush().unwrap();
}
}