blob: 2dd4d7d304377d00b963a75834b3dcc4c29ac811 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
use std::io;
use std::thread;
use std::io::BufReader;
use std::io::prelude::*;
use std::net::{TcpStream, Shutdown};
extern crate space;
use space::ship::Ship;
extern crate serde_json;
fn get_login_info() -> String {
let mut name = String::new();
println!("Ship Name:");
io::stdin().read_line(&mut name).expect("Failed");
let mut password = String::new();
println!("Password:");
io::stdin().read_line(&mut password).expect("Failed");
name.replace("\n", "") + ":" + &password
}
fn main() {
let mut stream = TcpStream::connect("localhost:6000").unwrap();
let mut buff_r = BufReader::new(stream.try_clone().unwrap());
let send = get_login_info();
stream.write(send.as_bytes());
let mut data = String::new();
buff_r.read_line(&mut data);
let modules : Vec<&str> = data.split(",").collect();
println!("Choose your module:");
for (i, module) in modules.iter().enumerate() {
println!("{}) {}", i, module);
}
let mut choice = String::new();
io::stdin().read_line(&mut choice).expect("Failed");
stream.write(choice.as_bytes());
let mut data = String::new();
buff_r.read_line(&mut data);
let ship : Ship = serde_json::from_str(&data).unwrap();
println!("{:?}", ship.location.0);
stream.shutdown(Shutdown::Both);
}
|