|
|
@ -164,18 +164,6 @@ struct Match {
|
|
|
|
name: String,
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct TMClient {
|
|
|
|
|
|
|
|
stream: Arc<Mutex<openssl::ssl::SslStream<TcpStream>>>,
|
|
|
|
|
|
|
|
notices: mpsc::Sender<tm::Notice>,
|
|
|
|
|
|
|
|
responses: mpsc::Sender<BackendMessage>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct TMConnection {
|
|
|
|
|
|
|
|
stream: Arc<Mutex<openssl::ssl::SslStream<TcpStream>>>,
|
|
|
|
|
|
|
|
notices: mpsc::Receiver<tm::Notice>,
|
|
|
|
|
|
|
|
responses: mpsc::Receiver<BackendMessage>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct BackendMessage {
|
|
|
|
struct BackendMessage {
|
|
|
|
status: u8,
|
|
|
|
status: u8,
|
|
|
|
request_id: u32,
|
|
|
|
request_id: u32,
|
|
|
@ -303,8 +291,8 @@ impl ConnectMsg {
|
|
|
|
last_notice_id: u64::from_le_bytes(bytes[20..28].try_into().unwrap()),
|
|
|
|
last_notice_id: u64::from_le_bytes(bytes[20..28].try_into().unwrap()),
|
|
|
|
username: bytes[28..44].to_owned().try_into().unwrap(),
|
|
|
|
username: bytes[28..44].to_owned().try_into().unwrap(),
|
|
|
|
pass_hash: bytes[44..76].to_owned().try_into().unwrap(),
|
|
|
|
pass_hash: bytes[44..76].to_owned().try_into().unwrap(),
|
|
|
|
pw_valid: bytes[77].to_owned(),
|
|
|
|
pw_valid: bytes[76].to_owned(),
|
|
|
|
state_valid: bytes[78].to_owned(),
|
|
|
|
state_valid: bytes[77].to_owned(),
|
|
|
|
client_name: bytes[78..110].to_owned().try_into().unwrap(),
|
|
|
|
client_name: bytes[78..110].to_owned().try_into().unwrap(),
|
|
|
|
server_time_zone: i32::from_le_bytes(bytes[110..114].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<Mutex<openssl::ssl::SslStream<TcpStream>>>,
|
|
|
|
|
|
|
|
notices: mpsc::Sender<tm::Notice>,
|
|
|
|
|
|
|
|
responses: mpsc::Sender<BackendMessage>,
|
|
|
|
|
|
|
|
uuid: [u8; 16],
|
|
|
|
|
|
|
|
client_name: [u8; 32],
|
|
|
|
|
|
|
|
password: String,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct TMConnection {
|
|
|
|
|
|
|
|
stream: Arc<Mutex<openssl::ssl::SslStream<TcpStream>>>,
|
|
|
|
|
|
|
|
notices: mpsc::Receiver<tm::Notice>,
|
|
|
|
|
|
|
|
responses: mpsc::Receiver<BackendMessage>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TMClient {
|
|
|
|
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 (notice_tx, notice_rx) = mpsc::channel();
|
|
|
|
let (response_tx, response_rx) = mpsc::channel();
|
|
|
|
let (response_tx, response_rx) = mpsc::channel();
|
|
|
|
|
|
|
|
|
|
|
@ -352,12 +355,15 @@ impl TMClient {
|
|
|
|
return (TMClient{
|
|
|
|
return (TMClient{
|
|
|
|
stream: stream_arc.clone(),
|
|
|
|
stream: stream_arc.clone(),
|
|
|
|
notices: notice_tx,
|
|
|
|
notices: notice_tx,
|
|
|
|
responses: response_tx
|
|
|
|
responses: response_tx,
|
|
|
|
|
|
|
|
uuid,
|
|
|
|
|
|
|
|
client_name,
|
|
|
|
|
|
|
|
password,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
TMConnection{
|
|
|
|
TMConnection{
|
|
|
|
stream: stream_arc,
|
|
|
|
stream: stream_arc,
|
|
|
|
notices: notice_rx,
|
|
|
|
notices: notice_rx,
|
|
|
|
responses: response_rx
|
|
|
|
responses: response_rx,
|
|
|
|
},);
|
|
|
|
},);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -376,9 +382,7 @@ impl TMClient {
|
|
|
|
Some(welcome_msg) => {
|
|
|
|
Some(welcome_msg) => {
|
|
|
|
println!("Welcome msg: {:?}", welcome_msg);
|
|
|
|
println!("Welcome msg: {:?}", welcome_msg);
|
|
|
|
if welcome_msg.pw_valid == 0 {
|
|
|
|
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 connect_response = ConnectMsg::from_welcome(welcome_msg, &self.password, self.uuid, self.client_name);
|
|
|
|
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 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, packet.seq_num, connect_response.as_bytes());
|
|
|
|
match stream.write(&response.as_bytes()) {
|
|
|
|
match stream.write(&response.as_bytes()) {
|
|
|
|
Err(error) => println!("Send error: {:?}", error),
|
|
|
|
Err(error) => println!("Send error: {:?}", error),
|
|
|
@ -557,7 +561,9 @@ fn main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let running = true;
|
|
|
|
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 ||
|
|
|
|
let tm_thread = thread::spawn(move ||
|
|
|
|
while running {
|
|
|
|
while running {
|
|
|
|
tm_client.process();
|
|
|
|
tm_client.process();
|
|
|
|