From 452dd2986dc712acb77cd6cee5f93d2451b35bb5 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sat, 20 Jan 2024 18:02:13 -0700 Subject: [PATCH] Fixed connect packet typo --- src/main.rs | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8a479c9..6dda60f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,18 +164,6 @@ struct Match { name: String, } -struct TMClient { - stream: Arc>>, - notices: mpsc::Sender, - responses: mpsc::Sender, -} - -struct TMConnection { - stream: Arc>>, - notices: mpsc::Receiver, - responses: mpsc::Receiver, -} - struct BackendMessage { status: u8, request_id: u32, @@ -303,8 +291,8 @@ impl ConnectMsg { last_notice_id: u64::from_le_bytes(bytes[20..28].try_into().unwrap()), username: bytes[28..44].to_owned().try_into().unwrap(), pass_hash: bytes[44..76].to_owned().try_into().unwrap(), - pw_valid: bytes[77].to_owned(), - state_valid: bytes[78].to_owned(), + pw_valid: bytes[76].to_owned(), + state_valid: bytes[77].to_owned(), client_name: bytes[78..110].to_owned().try_into().unwrap(), server_time_zone: i32::from_le_bytes(bytes[110..114].try_into().unwrap()), }); @@ -327,8 +315,23 @@ impl ConnectMsg { } } +struct TMClient { + stream: Arc>>, + notices: mpsc::Sender, + responses: mpsc::Sender, + uuid: [u8; 16], + client_name: [u8; 32], + password: String, +} + +struct TMConnection { + stream: Arc>>, + notices: mpsc::Receiver, + responses: mpsc::Receiver, +} + impl TMClient { - fn new() -> (TMClient, TMConnection) { + fn new(uuid: [u8; 16], client_name: [u8; 32], password: String) -> (TMClient, TMConnection) { let (notice_tx, notice_rx) = mpsc::channel(); let (response_tx, response_rx) = mpsc::channel(); @@ -352,12 +355,15 @@ impl TMClient { return (TMClient{ stream: stream_arc.clone(), notices: notice_tx, - responses: response_tx + responses: response_tx, + uuid, + client_name, + password, }, TMConnection{ stream: stream_arc, notices: notice_rx, - responses: response_rx + responses: response_rx, },); } @@ -376,9 +382,7 @@ impl TMClient { Some(welcome_msg) => { println!("Welcome msg: {:?}", welcome_msg); if welcome_msg.pw_valid == 0 { - let uuid = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let client_name = [116, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - let connect_response = ConnectMsg::from_welcome(welcome_msg, "", uuid, client_name); + 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()); match stream.write(&response.as_bytes()) { Err(error) => println!("Send error: {:?}", error), @@ -557,7 +561,9 @@ fn main() { ); let running = true; - let (tm_client, tm_connection) = TMClient::new(); + 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 tm_thread = thread::spawn(move || while running { tm_client.process();