mirror of
https://github.com/renorris/openfsd
synced 2026-03-22 23:05:36 +08:00
Compare commits
5 Commits
v1.0-beta.
...
v1.0-beta.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
456503ef84 | ||
|
|
fa51997b33 | ||
|
|
cfab03a90f | ||
|
|
a4210f836a | ||
|
|
7adfae6a23 |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Reese Norris
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,5 +1,7 @@
|
||||
# openfsd
|
||||
|
||||
[](https://github.com/renorris/openfsd/blob/main/LICENSE)
|
||||
|
||||
**openfsd** is an open-source multiplayer flight simulation server implementing the modern VATSIM FSD protocol. It connects pilots and air traffic controllers in a shared virtual environment.
|
||||
|
||||
## About
|
||||
|
||||
@@ -16,7 +16,8 @@ type Client struct {
|
||||
cancelCtx func()
|
||||
sendChan chan string
|
||||
|
||||
lat, lon, visRange atomic.Float64
|
||||
lat, lon, visRange atomic.Float64
|
||||
closestVelocityClientDistance float64 // The closest Velocity-compatible client in meters
|
||||
|
||||
flightPlan atomic.String
|
||||
assignedBeaconCode atomic.String
|
||||
@@ -31,7 +32,11 @@ type Client struct {
|
||||
facilityType int // ATC facility type. This value is only relevant for ATC
|
||||
loginData
|
||||
|
||||
authState vatsimAuthState
|
||||
authState vatsimAuthState
|
||||
sendFastEnabled bool
|
||||
}
|
||||
|
||||
type LatLon struct {
|
||||
}
|
||||
|
||||
func newClient(ctx context.Context, conn net.Conn, scanner *bufio.Scanner, loginData loginData) (client *Client) {
|
||||
|
||||
@@ -163,6 +163,17 @@ func (s *Server) handlePilotPosition(client *Client, packet []byte) {
|
||||
client.heading.Store(int32(heading))
|
||||
|
||||
client.lastUpdated.Store(time.Now())
|
||||
|
||||
// Check if we need to update the sendfast state
|
||||
if client.sendFastEnabled {
|
||||
if (client.closestVelocityClientDistance / 1852.0) > 5.0 { // 5.0 nautical miles
|
||||
sendDisableSendFastPacket(client)
|
||||
}
|
||||
} else {
|
||||
if (client.closestVelocityClientDistance / 1852.0) < 5.0 { // 5.0 nautical miles
|
||||
sendEnableSendFastPacket(client)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handleFastPilotPosition handles logic for fast `^`, stopped `#ST`, and slow `#SL` pilot position updates
|
||||
|
||||
@@ -85,15 +85,27 @@ func (p *postOffice) updatePosition(client *Client, newCenter [2]float64, newVis
|
||||
return
|
||||
}
|
||||
|
||||
// search calls `callback` for every other Client within geographical range of the provided Client
|
||||
// search calls `callback` for every other Client within geographical range of the provided Client.
|
||||
//
|
||||
// It automatically resets and populates the Client.nearbyClients and Client.closestVelocityClientDistance values
|
||||
func (p *postOffice) search(client *Client, callback func(recipient *Client) bool) {
|
||||
clientMin, clientMax := calculateBoundingBox(client.latLon(), client.visRange.Load())
|
||||
|
||||
client.closestVelocityClientDistance = math.MaxFloat64
|
||||
|
||||
p.treeLock.RLock()
|
||||
p.tree.Search(clientMin, clientMax, func(foundMin [2]float64, foundMax [2]float64, foundClient *Client) bool {
|
||||
if foundClient == client {
|
||||
return true // Ignore self
|
||||
}
|
||||
|
||||
if foundClient.protoRevision == 101 {
|
||||
dist := distance(client.lat.Load(), client.lon.Load(), foundClient.lat.Load(), foundClient.lon.Load())
|
||||
if dist < client.closestVelocityClientDistance {
|
||||
client.closestVelocityClientDistance = dist
|
||||
}
|
||||
}
|
||||
|
||||
return callback(foundClient)
|
||||
})
|
||||
p.treeLock.RUnlock()
|
||||
|
||||
27
fsd/util.go
27
fsd/util.go
@@ -391,3 +391,30 @@ func pitchBankHeading(packed uint32) (pitch float64, bank float64, heading float
|
||||
func strPtr(str string) *string {
|
||||
return &str
|
||||
}
|
||||
|
||||
// sendEnableSendFastPacket sends an 'enable' $SF Send Fast packet to the client
|
||||
func sendEnableSendFastPacket(client *Client) {
|
||||
sendSendFastPacket(client, true)
|
||||
}
|
||||
|
||||
// sendDisableSendFastPacket sends a 'disable' $SF Send Fast packet to the client
|
||||
func sendDisableSendFastPacket(client *Client) {
|
||||
sendSendFastPacket(client, false)
|
||||
}
|
||||
|
||||
// sendSendFastPacket sends a $SF Send Fast packet to the client
|
||||
func sendSendFastPacket(client *Client, enabled bool) {
|
||||
builder := strings.Builder{}
|
||||
builder.Grow(32)
|
||||
builder.WriteString("$SFSERVER:")
|
||||
builder.WriteString(client.callsign)
|
||||
builder.WriteByte(':')
|
||||
if enabled {
|
||||
builder.WriteByte('1')
|
||||
} else {
|
||||
builder.WriteByte('0')
|
||||
}
|
||||
builder.WriteString("\r\n")
|
||||
|
||||
client.send(builder.String())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,6 @@ title openfsd
|
||||
|
||||
start /b cmd /c "set DATABASE_AUTO_MIGRATE=true&& set DATABASE_SOURCE_NAME=openfsd.db?_pragma=busy_timeout(5000)^&_pragma=journal_mode(WAL)&& go run ."
|
||||
|
||||
powershell -Command "while (-not (Test-NetConnection -ComputerName localhost -Port 13618 -InformationLevel Quiet)) { Start-Sleep -Seconds 1 }"
|
||||
powershell -Command "$ProgressPreference = 'SilentlyContinue'; while (-not (Test-NetConnection -ComputerName localhost -Port 13618 -InformationLevel Quiet)) { Start-Sleep -Seconds 1 }" >nul 2>&1
|
||||
|
||||
cmd /c "cd web&& set FSD_HTTP_SERVICE_ADDRESS=http://localhost:13618&& set DATABASE_SOURCE_NAME=../openfsd.db?_pragma=busy_timeout(5000)^&_pragma=journal_mode(WAL)&& go run ."
|
||||
|
||||
Reference in New Issue
Block a user