Changed println to log

master
noah metz 2024-01-21 00:35:00 -07:00
parent cb8c57e1b9
commit cd36ee4957
1 changed files with 33 additions and 33 deletions

@ -142,12 +142,16 @@ struct Event {
} }
impl Event { impl Event {
fn from_match_list_response(response: BackendMessage) -> Event { fn new(name: String) -> Event {
Event{ Event{
name: String::from(""), name,
divisions: Vec::new(), divisions: Vec::new(),
} }
} }
fn parse_match_list(self: &Event, match_list: BackendMessage) {
let divisions: Vec<Division> = Vec::new();
}
} }
struct Division { struct Division {
@ -190,10 +194,7 @@ impl BackendMessage {
request_id: u32::from_le_bytes(bytes[0..4].try_into().unwrap()), request_id: u32::from_le_bytes(bytes[0..4].try_into().unwrap()),
data, data,
}), }),
Err(error) => { Err(_) => None,
println!("Protobuf parse error: {:?}", error);
return None;
},
} }
} }
@ -442,7 +443,7 @@ impl TMClient {
log::debug!("Sent: {:?}", packet); log::debug!("Sent: {:?}", packet);
self.last_seq_num += 1; self.last_seq_num += 1;
}, },
Err(error) => println!("Request send error: {:?}", error), Err(error) => log::error!("Request send error: {:?}", error),
} }
} }
} }
@ -464,32 +465,27 @@ impl TMClient {
let ack = BackendPacket::new(packet.header, packet.timestamp, 5, self.last_seq_num+1, notice.notice_id.to_le_bytes().to_vec()); let ack = BackendPacket::new(packet.header, packet.timestamp, 5, self.last_seq_num+1, notice.notice_id.to_le_bytes().to_vec());
self.last_seq_num += 1; self.last_seq_num += 1;
match self.stream.write(&ack.as_bytes()) { match self.stream.write(&ack.as_bytes()) {
Ok(_) => println!("Sent ACK for notice {}", notice.notice_id), Ok(_) => log::debug!("Sent ACK for notice {}", notice.notice_id),
Err(error) => println!("ACK error: {:?}", error), Err(error) => log::error!("ACK error: {:?}", error),
} }
match self.notices.send(Box::new(notice.notice)) { match self.notices.send(Box::new(notice.notice)) {
Ok(_) => println!("Forwarded notice to callback engine"), Ok(_) => log::debug!("Forwarded notice to callback engine"),
Err(error) => println!("Notice forward error {:?}", error), Err(error) => log::error!("Notice forward error {:?}", error),
} }
}, },
None => println!("Notice parse error: {:?}", packet), None => log::error!("Notice parse error: {:?}", packet),
} }
}, },
// Response message // Response message
3 => { 3 => {
match BackendMessage::from_bytes(packet.data.clone()) { match BackendMessage::from_bytes(packet.data.clone()) {
Some(message) => { Some(message) => {
println!("About to send");
match self.responses.send(Box::new(message)) { match self.responses.send(Box::new(message)) {
Ok(_) => { Ok(_) => log::debug!("Forwarded response to callback engine"),
println!("Forwarded response to callback engine"); Err(error) => log::error!("Response forward error {:?}", error),
}
Err(error) => {
println!("Response forward error {:?}", error)
}
} }
}, },
None => println!("BackendMessage parse error: {:?}", packet), None => log::error!("BackendMessage parse error: {:?}", packet),
} }
}, },
// Server Message // Server Message
@ -500,30 +496,30 @@ impl TMClient {
let connect_response = ConnectMsg::from_welcome(welcome_msg, &self.password, self.uuid, self.client_name, self.username); let connect_response = ConnectMsg::from_welcome(welcome_msg, &self.password, self.uuid, self.client_name, self.username);
let response = BackendPacket::new(packet.header, packet.timestamp, packet.msg_type, self.last_seq_num+1, 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 self.stream.write(&response.as_bytes()) { match self.stream.write(&response.as_bytes()) {
Err(error) => println!("Send error: {:?}", error), Err(error) => log::error!("Send error: {:?}", error),
Ok(_) => self.last_seq_num += 1, Ok(_) => self.last_seq_num += 1,
} }
} else if welcome_msg.state_valid == 0 { } else if welcome_msg.state_valid == 0 {
println!("pw_valid but not state_valid"); log::error!("pw_valid but not state_valid");
} else { } else {
self.connected = true; self.connected = true;
println!("Connected to TM backend!"); log::info!("Connected to TM backend!");
} }
}, },
None => println!("Failed to parse welcome msg"), None => log::error!("Failed to parse welcome msg"),
} }
}, },
_ => println!("Unhandled message type: {}", packet.msg_type), _ => log::warn!("Unhandled message type: {}", packet.msg_type),
} }
}, },
None => { None => {
println!("Failed to parse BackendPacket({}): {}", read, String::from_utf8_lossy(&incoming)); log::error!("Failed to parse BackendPacket({}): {}", read, String::from_utf8_lossy(&incoming));
// Sleep to prevent busy loop when TM is spamming 0 length packets // Sleep to prevent busy loop when TM is spamming 0 length packets
thread::sleep(Duration::from_millis(100)); thread::sleep(Duration::from_millis(100));
} }
} }
}, },
Err(error) => {}, Err(_) => {},
} }
} }
@ -674,6 +670,11 @@ fn main() {
} }
); );
let get_event_name_req = BackendMessage::new(101, tm::BackendMessageData::default());
tm_connection.requests.send(Box::new(get_event_name_req)).unwrap();
let get_event_name_resp = tm_connection.responses.recv().unwrap();
let mut event = Event::new(String::from(get_event_name_resp.data.event_config.unwrap().event_name.unwrap()));
let mut get_match_list_tuple = tm::MatchTuple::default(); let mut get_match_list_tuple = tm::MatchTuple::default();
get_match_list_tuple.division = Some(0); get_match_list_tuple.division = Some(0);
get_match_list_tuple.round = None; get_match_list_tuple.round = None;
@ -688,9 +689,8 @@ fn main() {
tm_connection.requests.send(Box::new(get_match_list_req)).unwrap(); tm_connection.requests.send(Box::new(get_match_list_req)).unwrap();
let get_match_list_resp = tm_connection.responses.recv().unwrap(); let get_match_list_resp = tm_connection.responses.recv().unwrap();
println!("Get Match List Response: {:?}", get_match_list_resp);
let mut event = Event::from_match_list_response(*get_match_list_resp); event.parse_match_list(*get_match_list_resp);
while running { while running {
thread::sleep(Duration::from_millis(1000)); thread::sleep(Duration::from_millis(1000));
@ -700,8 +700,8 @@ fn main() {
match callback { match callback {
None => { None => {
match notice.id { match notice.id {
None => println!("Notice without NoticeId received"), None => log::error!("Notice without NoticeId received"),
Some(notice_id) => println!("Unhandled NoticeId: {}", notice_id), Some(notice_id) => log::warn!("Unhandled NoticeId: {}", notice_id),
} }
}, },
Some(callback) => { Some(callback) => {
@ -711,13 +711,13 @@ fn main() {
let result = client.publish(message.topic, QoS::AtMostOnce, true, message.payload); let result = client.publish(message.topic, QoS::AtMostOnce, true, message.payload);
match result { match result {
Ok(_) => {}, Ok(_) => {},
Err(error) => println!("Publish error: {}", error), Err(error) => log::error!("Publish error: {}", error),
} }
} }
}, },
} }
}, },
Err(error) => println!("Notice recv error: {}", error), Err(error) => log::error!("Notice recv error: {}", error),
} }
} }