|
|
|
@ -322,6 +322,7 @@ struct TMClient {
|
|
|
|
|
uuid: [u8; 16],
|
|
|
|
|
client_name: [u8; 32],
|
|
|
|
|
password: String,
|
|
|
|
|
last_seq_num: u64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TMConnection {
|
|
|
|
@ -359,6 +360,7 @@ impl TMClient {
|
|
|
|
|
uuid,
|
|
|
|
|
client_name,
|
|
|
|
|
password,
|
|
|
|
|
last_seq_num: 0xFFFFFFFFFFFFFFFF,
|
|
|
|
|
},
|
|
|
|
|
TMConnection{
|
|
|
|
|
stream: stream_arc,
|
|
|
|
@ -367,7 +369,7 @@ impl TMClient {
|
|
|
|
|
},);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn process(self: &TMClient) {
|
|
|
|
|
fn process(self: &mut TMClient) {
|
|
|
|
|
|
|
|
|
|
let mut incoming = [0; 2048];
|
|
|
|
|
let mut stream = self.stream.lock().unwrap();
|
|
|
|
@ -376,6 +378,7 @@ impl TMClient {
|
|
|
|
|
let data = incoming[0..read].to_vec();
|
|
|
|
|
match BackendPacket::from_bytes(data) {
|
|
|
|
|
Some(packet) => {
|
|
|
|
|
self.last_seq_num = packet.seq_num;
|
|
|
|
|
match packet.msg_type {
|
|
|
|
|
2 => {
|
|
|
|
|
match ConnectMsg::from_bytes(packet.data) {
|
|
|
|
@ -383,10 +386,13 @@ impl TMClient {
|
|
|
|
|
println!("Welcome msg: {:?}", welcome_msg);
|
|
|
|
|
if welcome_msg.pw_valid == 0 {
|
|
|
|
|
let connect_response = ConnectMsg::from_welcome(welcome_msg, &self.password, self.uuid, self.client_name);
|
|
|
|
|
let response = BackendPacket::new(packet.header, packet.timestamp, packet.msg_type, packet.seq_num, connect_response.as_bytes());
|
|
|
|
|
let response = BackendPacket::new(packet.header, packet.timestamp, packet.msg_type, self.last_seq_num+1, connect_response.as_bytes());
|
|
|
|
|
match stream.write(&response.as_bytes()) {
|
|
|
|
|
Err(error) => println!("Send error: {:?}", error),
|
|
|
|
|
Ok(sent) => println!("Sent {} bytes", sent),
|
|
|
|
|
Ok(sent) => {
|
|
|
|
|
println!("Sent {} bytes", sent);
|
|
|
|
|
self.last_seq_num += 1;
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
println!("Connected to TM backend!");
|
|
|
|
@ -563,7 +569,7 @@ fn main() {
|
|
|
|
|
let running = true;
|
|
|
|
|
let uuid = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
|
|
|
|
let client_name: [u8;32] = [b'r', b'u', b's', b't', b'-', b'b', b'r', b'i', b'd', b'g', b'e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
|
|
|
let (tm_client, tm_connection) = TMClient::new(uuid, client_name, String::from(""));
|
|
|
|
|
let (mut tm_client, tm_connection) = TMClient::new(uuid, client_name, String::from(""));
|
|
|
|
|
let tm_thread = thread::spawn(move ||
|
|
|
|
|
while running {
|
|
|
|
|
tm_client.process();
|
|
|
|
|