From 002a4d3ee181ffa1013991df84c4ab7c1784c206 Mon Sep 17 00:00:00 2001 From: Sequal32 Date: Sun, 20 Sep 2020 12:17:01 -0400 Subject: [PATCH] assigned beacon code & validate atc cases --- src/main.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index d7b21f8..dadd75c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,17 +46,21 @@ fn build_flightplan_string(callsign: &str, fp: &FlightPlan) -> String { } fn build_beacon_code_string(my_callsign: &str, callsign: &str, beacon_code: &str) -> String { - format!("#PCSERVER:{}:CCP:BC:{}:{}", my_callsign, callsign, beacon_code) + format!("#PCSERVER:{}:CCP:BC:{}:{}\r\n", my_callsign, callsign, beacon_code) } fn build_metar_string(callsign: &str, metar: &String) -> String { format!("$ARSERVER:{}:METAR:{}\r\n", callsign, metar) } -fn build_validate_atc_string(callsign: &str) -> String { +fn build_validate_atc_string_with_callsign(callsign: &str) -> String { format!("$CRSERVER:{0:}:ATC:Y:{0:}\r\n", callsign) } +fn build_validate_atc_string_without_callsign(callsign: &str) -> String { + format!("$CRSERVER:{0:}:ATC:Y\r\n", callsign) +} + #[derive(Default)] struct TrackedData { did_set_fp: bool @@ -183,14 +187,6 @@ fn main() { weather.request_weather(&metar.payload) } }, - PacketTypes::ATCPosition(position) => { - // Update callsign - if current_callsign != position.callsign { - // Recognize callsign as a valid controller - current_callsign = position.callsign.to_string(); - stream.write(build_validate_atc_string(¤t_callsign).as_bytes()).ok(); - } - }, PacketTypes::ClientQuery(cq) => match cq.payload { ClientQueryPayload::FlightPlan(callsign) => { if let Some(data) = tracker.get_data_for_callsign(&callsign) { @@ -199,6 +195,16 @@ fn main() { } } } + ClientQueryPayload::IsValidATCQuery(callsign) => { + // Recognize callsign as a valid controller + current_callsign = cq.from.to_string(); + + if callsign.is_some() { + stream.write(build_validate_atc_string_with_callsign(¤t_callsign).as_bytes()).ok(); + } else { + stream.write(build_validate_atc_string_without_callsign(¤t_callsign).as_bytes()).ok(); + } + } _ => () } _ => ()