mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 14:35:36 +08:00
Changes:
- Implement bootstrapping library for managing several concurrent internal services
- Refactor concurrency model for connections/logical clients and their associated I/O
- Refactor server context singleton
- Refactor error handling
- Most errors are now gracefully sent to the FSD client directly encoded as an $ER packet,
enhancing visibility and debugging
- Most errors are now rightfully treated as non-fatal
- Refactor package/dependency graph
- Refactor calling conventions/interfaces for many packages
- Refactor database package
- Refactor post office
Features:
- Add VATSIM-esque HTTP/JSON "data feed"
- Add ephemeral in-memory database option
- Add user management REST API
- Add improved web interface
- Add MySQL support (drop SQLite support)
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/renorris/openfsd/postoffice"
|
|
"github.com/renorris/openfsd/protocol"
|
|
"github.com/renorris/openfsd/servercontext"
|
|
"time"
|
|
)
|
|
|
|
func pilotPositionHandler(invoker Invoker, packet string) (result Result, err error) {
|
|
// Parse packet
|
|
pdu := protocol.PilotPositionPDU{}
|
|
if err = pdu.Parse(packet); err != nil {
|
|
return
|
|
}
|
|
|
|
// Verify source callsign
|
|
if pdu.From != invoker.Callsign() {
|
|
return pduSourceInvalidResult()
|
|
}
|
|
|
|
// Write location to post office
|
|
invoker.SetGeohash(servercontext.PostOffice().SetLocation(invoker.Address(), pdu.Lat, pdu.Lng))
|
|
|
|
// Update SendFastEnabled state if required
|
|
if invoker.SendFastEnabled() && pdu.GroundSpeed == 0 {
|
|
invoker.SetSendFastEnabled(false)
|
|
disableSendFastPDU := protocol.SendFastPDU{
|
|
From: protocol.ServerCallsign,
|
|
To: invoker.Callsign(),
|
|
DoSendFast: false,
|
|
}
|
|
result.addReply(disableSendFastPDU.Serialize())
|
|
} else if !invoker.SendFastEnabled() && pdu.GroundSpeed > 0 {
|
|
invoker.SetSendFastEnabled(true)
|
|
enableSendFastPDU := protocol.SendFastPDU{
|
|
From: protocol.ServerCallsign,
|
|
To: invoker.Callsign(),
|
|
DoSendFast: true,
|
|
}
|
|
result.addReply(enableSendFastPDU.Serialize())
|
|
}
|
|
|
|
// Update invoker address state
|
|
state := invoker.Address().State()
|
|
|
|
state.Latitude = pdu.Lat
|
|
state.Longitude = pdu.Lng
|
|
state.Heading = int(pdu.Heading)
|
|
state.Groundspeed = pdu.GroundSpeed
|
|
state.Altitude = pdu.TrueAltitude
|
|
state.Transponder = pdu.SquawkCode
|
|
state.LastUpdated = time.Now()
|
|
|
|
invoker.SetAddressState(&state)
|
|
|
|
// Proximity broadcast position update
|
|
mail := postoffice.NewMail(invoker.Address(), postoffice.MailTypeGeneralProximityBroadcast, "", packet)
|
|
result.addMail(mail)
|
|
|
|
return
|
|
}
|