Skip to content

Commit 6889171

Browse files
committed
Initial commit
0 parents  commit 6889171

38 files changed

Lines changed: 2314 additions & 0 deletions

Readme-CN.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# AdvancedFlightServer-Go
3+
4+
[English Version](Readme.md)
5+
6+
## 简介
7+
8+
AdvancedFlightServer-Go 是一个用 Go 语言编写的模拟飞行联机服务器,支持 Swift、Echo、Euroscope 或其他自定义的客户端。
9+
10+
## 特点
11+
12+
- 更快的速度
13+
- 使用 FSD Version 3.000 Draft 9 协议
14+
- 使用 JSON 进行数据输出
15+
- 使用 PostgreSQL 数据库进行账户存储
16+
- 支持高并发
17+
- 跨平台支持(开发测试环境为 Windows 11 和 CentOS 8,理论上支持所有 Golang 支持的平台)
18+
- 解决了 FSD V3.000 Draft 9 在 Linux 系统运行时随机崩溃的问题
19+
- 自带的METAR数据源
20+
21+
## 使用指南
22+
23+
1. 使用 `go build AdvancedFlightServer/main` 进行编译。
24+
2. 运行编译后的可执行文件。
25+
3. 第一次运行程序会生成一个 `config.ini` 文件,请先关闭程序。
26+
4. 填写 `config.ini` 文件中的相关条目。
27+
5. 重新打开程序即可。
28+
29+
## 开源许可
30+
31+
本软件使用 AGPL v3.0 开源许可。
32+
33+
## 贡献
34+
35+
欢迎通过提交 PR 的方式为本代码库做出贡献。
36+
37+
## 商业版本
38+
39+
除了开源版本外,我们还提供商业版本,该版本具有以下特性:
40+
41+
- 使用 Vatsim v3.4 协议
42+
- 支持管制员修改飞行计划
43+
- 支持 Euroscope 内置 ATIS
44+
- 支持管制员 INFO line 和 Logoff time
45+
- 支持 VisualPosition 刷新(飞机在地面上时,每 0.2 秒钟刷新一次位置信息)
46+
- 支持锁定飞行计划(管制员修改过的飞行计划自动锁定,直到下线)
47+
- 支持标牌操作记录等
48+
49+
请注意,商业版本的详细信息和许可要求可能会有所不同。如有兴趣了解商业版本,请联系我们获取更多信息。

Readme.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# AdvancedFlightServer-Go
2+
3+
[中文版](Readme-CN.md)
4+
5+
## Introduction
6+
7+
AdvancedFlightServer-Go is a flight simulation multiplayer server written in Go. It supports Swift, Echo, Euroscope or other custom clients.
8+
9+
## Features
10+
11+
- Faster speed
12+
- Uses FSD Version 3.000 Draft 9 protocol
13+
- Outputs data in JSON format
14+
- Stores accounts in PostgreSQL database
15+
- Supports high concurrency
16+
- Cross-platform support (developed and tested on Windows 11 and CentOS 8, theoretically supports all platforms supported by Golang)
17+
- Resolves the issue of random crashes when running FSD V3.000 Draft 9 on Linux systems
18+
- Built-in METAR data.
19+
20+
## Usage Guide
21+
22+
1. Compile the code using `go build AdvancedFlightServer/main`.
23+
2. Run the compiled executable.
24+
3. The program will generate a `config.ini` file on the first run. Close the program.
25+
4. Fill in the entries in the `config.ini` file.
26+
5. Reopen the program.
27+
28+
## Open Source License
29+
30+
This software is licensed under the AGPL v3.0.
31+
32+
## Contribution
33+
34+
Contributions to this codebase are welcome via pull requests.
35+
36+
## Commercial Version
37+
38+
In addition to the open-source version, we also offer a commercial version with the following features:
39+
40+
- Uses Vatsim v3.4 protocol
41+
- Supports modification of flight plans by controllers
42+
- Supports Euroscope built-in ATIS
43+
- Supports INFO line and Logoff time for controllers
44+
- Supports VisualPosition refresh (refreshes position information every 0.2 seconds when the aircraft is on the ground)
45+
- Supports locking of flight plans (automatically locks modified flight plans until the controller goes offline)
46+
- Supports operation record of labels, and more
47+
48+
Please note that the commercial version may have different details and licensing requirements. If you are interested in the commercial version, please contact us for more information.

config/Config.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package config
2+
3+
import (
4+
"AdvancedFlightServer/util"
5+
"fmt"
6+
"github.com/spf13/viper"
7+
"log"
8+
)
9+
10+
func defaultConfig() {
11+
viper.SetDefault("server.port", 6809)
12+
viper.SetDefault("db.addr", "127.0.0.1")
13+
viper.SetDefault("db.port", 3306)
14+
viper.SetDefault("db.username", "root")
15+
viper.SetDefault("db.password", "123456")
16+
viper.SetDefault("db.dbname", "flightserver")
17+
viper.SetDefault("server.motd", fmt.Sprintf("Advanced Flight Server v%s. Open source by AFcPPe under CC-BY-NC-SA 4.0", util.Version))
18+
viper.SetDefault("server.weather_url", "http://metar.flightsim.top/getall")
19+
viper.SetDefault("server.output_dir", "./whazzup.json")
20+
err := viper.SafeWriteConfigAs("config.ini")
21+
if err != nil {
22+
return
23+
}
24+
}
25+
26+
func ReadConfig() {
27+
log.Println("Reading config file from config.ini...")
28+
viper.SetConfigName("config")
29+
viper.AddConfigPath(".")
30+
defaultConfig()
31+
err := viper.ReadInConfig()
32+
if err != nil {
33+
log.Println("Error while reading config file. Using default config.")
34+
log.Fatal(err)
35+
return
36+
}
37+
38+
}

main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"AdvancedFlightServer/config"
5+
"AdvancedFlightServer/service"
6+
"AdvancedFlightServer/tasks"
7+
"AdvancedFlightServer/util"
8+
)
9+
10+
func main() {
11+
config.ReadConfig()
12+
util.ConnectToDatabase()
13+
util.SetupCron()
14+
tasks.SetupCron()
15+
service.StartServer()
16+
}

model/orm/User.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package orm
2+
3+
type User struct {
4+
Uid int
5+
Username string
6+
Password string
7+
Salt string
8+
Rating int
9+
}

model/pdu/ATCPosition.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package pdu
2+
3+
import (
4+
"AdvancedFlightServer/model/server"
5+
"fmt"
6+
"strconv"
7+
"strings"
8+
)
9+
10+
type ATCPosition struct {
11+
Base
12+
Frequencies []string
13+
Facility server.NetworkFacility
14+
VisibilityRange int
15+
Rating server.NetworkRating
16+
Lat float64
17+
Lon float64
18+
}
19+
20+
func NewPDUATCPosition(from string, freq []string, facility, visRange, rating int, lat, lon float64) *ATCPosition {
21+
return &ATCPosition{
22+
Base: Base{
23+
From: from,
24+
To: "",
25+
},
26+
Frequencies: freq,
27+
Facility: server.NetworkFacility(facility),
28+
VisibilityRange: visRange,
29+
Rating: server.NetworkRating(rating),
30+
Lat: lat,
31+
Lon: lon,
32+
}
33+
}
34+
35+
func ATCPositionFromTokens(tokens []string) (*ATCPosition, error) {
36+
if len(tokens) < 7 {
37+
return nil, fmt.Errorf("PDUError tokens length < 7")
38+
}
39+
freq := strings.Split(tokens[1], "&")
40+
facility, err := strconv.Atoi(tokens[2])
41+
if err != nil {
42+
return nil, err
43+
}
44+
visRange, err := strconv.Atoi(tokens[3])
45+
if err != nil {
46+
return nil, err
47+
}
48+
rating, err := strconv.Atoi(tokens[4])
49+
if err != nil {
50+
return nil, err
51+
}
52+
lat, err := strconv.ParseFloat(tokens[5], 64)
53+
if err != nil {
54+
return nil, err
55+
}
56+
lon, err := strconv.ParseFloat(tokens[6], 64)
57+
if err != nil {
58+
return nil, err
59+
}
60+
return NewPDUATCPosition(tokens[0], freq, facility, visRange, rating, lat, lon), nil
61+
}
62+
63+
func (pdu *ATCPosition) ToTokens() []string {
64+
freq := strings.Join(pdu.Frequencies, "&")
65+
return []string{
66+
pdu.From,
67+
freq,
68+
strconv.Itoa(int(pdu.Facility)),
69+
strconv.Itoa(pdu.VisibilityRange),
70+
strconv.Itoa(int(pdu.Rating)),
71+
strconv.FormatFloat(pdu.Lat, 'f', -1, 64),
72+
strconv.FormatFloat(pdu.Lon, 'f', -1, 64),
73+
"0",
74+
}
75+
}
76+
77+
func (pdu *ATCPosition) GetHeader() string {
78+
return "%"
79+
}

model/pdu/AddATC.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package pdu
2+
3+
import (
4+
"AdvancedFlightServer/model/server"
5+
"fmt"
6+
"strconv"
7+
)
8+
9+
type AddATC struct {
10+
Base
11+
Callsign string
12+
Name string
13+
Cid string
14+
Password string
15+
Rating server.NetworkRating
16+
ProtocolRevision int
17+
}
18+
19+
func NewPDUAddATC(from, to, name, cid, password string, rating int, protocolRevision int) *AddATC {
20+
return &AddATC{
21+
Base: Base{
22+
From: from,
23+
To: to,
24+
},
25+
Callsign: from,
26+
Name: name,
27+
Cid: cid,
28+
Password: password,
29+
Rating: server.NetworkRating(rating),
30+
ProtocolRevision: protocolRevision,
31+
}
32+
}
33+
34+
func AddATCFromTokens(tokens []string) (*AddATC, error) {
35+
if len(tokens) < 7 {
36+
return nil, fmt.Errorf("invalid number of tokens")
37+
}
38+
39+
rating, err := strconv.Atoi(tokens[5])
40+
if err != nil {
41+
return nil, fmt.Errorf("invalid rating value")
42+
}
43+
44+
protocolRevision, err := strconv.Atoi(tokens[6])
45+
if err != nil {
46+
return nil, fmt.Errorf("invalid protocol revision value")
47+
}
48+
49+
return NewPDUAddATC(tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], rating, protocolRevision), nil
50+
}
51+
52+
func (p *AddATC) ToTokens() []string {
53+
return []string{p.Callsign, p.To, p.Name, p.Cid, p.Password, strconv.Itoa(int(p.Rating)), strconv.Itoa(p.ProtocolRevision)}
54+
}
55+
56+
func (p *AddATC) GetHeader() string {
57+
return "#AA"
58+
}

model/pdu/AddPilot.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package pdu
2+
3+
import (
4+
"AdvancedFlightServer/model/server"
5+
"fmt"
6+
"strconv"
7+
)
8+
9+
type AddPilot struct {
10+
Base
11+
Callsign string
12+
Cid string
13+
Password string
14+
Rating server.NetworkRating
15+
ProtocolVersion int
16+
RealName string
17+
SimType string
18+
}
19+
20+
func NewPDUAddPilot(from, to, cid, password string, networkRating, protocolVersion int, simType int, realName string) *AddPilot {
21+
return &AddPilot{
22+
Base: Base{
23+
From: from,
24+
To: to,
25+
},
26+
Callsign: from,
27+
Cid: cid,
28+
Password: password,
29+
Rating: server.NetworkRating(networkRating),
30+
ProtocolVersion: protocolVersion,
31+
RealName: realName,
32+
SimType: strconv.Itoa(simType),
33+
}
34+
}
35+
36+
func AddPilotFromTokens(tokens []string) (*AddPilot, error) {
37+
if len(tokens) < 8 {
38+
return nil, fmt.Errorf("PDUError tokens length < 8")
39+
}
40+
networkRating, err := strconv.Atoi(tokens[4])
41+
if err != nil {
42+
return nil, err
43+
}
44+
protocolVersion, err := strconv.Atoi(tokens[5])
45+
if err != nil {
46+
return nil, err
47+
}
48+
simType, err := strconv.Atoi(tokens[6])
49+
if err != nil {
50+
return nil, err
51+
}
52+
return NewPDUAddPilot(tokens[0], tokens[1], tokens[2], tokens[3], networkRating, protocolVersion, simType, tokens[7]), nil
53+
}
54+
55+
func (pdu *AddPilot) ToTokens() []string {
56+
return []string{
57+
pdu.From,
58+
pdu.To,
59+
pdu.Cid,
60+
pdu.Password,
61+
strconv.Itoa(int(pdu.Rating)),
62+
strconv.Itoa(pdu.ProtocolVersion),
63+
pdu.SimType,
64+
pdu.RealName,
65+
}
66+
}
67+
68+
func (pdu *AddPilot) GetHeader() string {
69+
return "#AP"
70+
}

0 commit comments

Comments
 (0)