generalize Client Query packet forwarding logic

This commit is contained in:
Reese Norris
2025-05-23 11:50:48 -07:00
parent e6e45b0e72
commit 97a6292974
2 changed files with 67 additions and 63 deletions

View File

@@ -207,6 +207,29 @@ func parseVisRange(packet []byte, index int) (visRange float64, ok bool) {
return
}
// forwardClientQuery freely routes a client query packet depending on the recipient.
func forwardClientQuery(po *postOffice, client *Client, packet []byte) {
recipient := getField(packet, 1)
if len(recipient) < 2 {
client.sendError(NoSuchCallsignError, "Invalid recipient")
return
}
switch string(recipient) {
case "@94835":
// Broadcast to in-range ATC
broadcastRangedAtcOnly(po, client, packet)
return
case "@94836":
// Broadcast to all in-range clients
broadcastRanged(po, client, packet)
return
}
sendDirectOrErr(po, client, recipient, packet)
}
// broadcastRanged broadcasts a packet to all clients in range
func broadcastRanged(po *postOffice, client *Client, packet []byte) {
packetStr := string(packet)