Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
39 changes: 27 additions & 12 deletions .do/deploy.template.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
spec:
name: cpdlc-server
# App Platform has no persistent disk, so the server keeps its data in a PostgreSQL database
databases:
- name: db
engine: PG
production: false
services:
- name: cpdlc-server
instance_count: 1
Expand All @@ -13,16 +18,26 @@ spec:
envs:
- key: Logging__Level
value: Information
- key: Acars__0__Type
value: Hoppie
- key: Acars__0__FlightSimulationNetwork
value: VATSIM
- key: Acars__0__StationIdentifier
value: CHANGE_ME
- key: Acars__0__Url
value: http://www.hoppie.nl/acars/system/connect.html
- key: Acars__0__AuthenticationCode
value: CHANGE_ME
- key: DatabaseProvider
value: PostgreSql
- key: DatabaseConnectionString
scope: RUN_TIME
value: ${db.DATABASE_URL}

# You must set the master key before you deploy. Without it, the server does not start.
# Make a key with: openssl rand -base64 32
# Keep a copy of the key in a safe place. If the key changes, you must enter the ACARS authentication codes again.
- key: MasterKey
scope: RUN_TIME
type: SECRET
- key: Handoff__NotificationLeadTime
value: "10"
value: ""

# You must set the VATSIM Connect client before you deploy. Without it, the server does not start.
# Set the redirect URL of the client to https://<app URL>/signin-vatsim
- key: VatsimConnect__ClientId
scope: RUN_TIME
value: ""
- key: VatsimConnect__ClientSecret
scope: RUN_TIME
type: SECRET
value: ""
19 changes: 19 additions & 0 deletions .fallout/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"ExecutableTarget": {
"type": "string",
"enum": [
"AddMigration",
"AddNuGetSource",
"CheckVersion",
"CompilePlugin",
"CompileServer",
Expand Down Expand Up @@ -126,11 +128,28 @@
],
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)"
},
"ForceVersion": {
"type": "string",
"description": "Version to use instead of the GitVersion version, for example 1.0.0-rc1"
},
"GitHubToken": {
"type": "string",
"description": "GitHub token for creating releases",
"default": "Secrets must be entered via 'fallout :secrets [profile]'"
},
"MigrationName": {
"type": "string",
"description": "Name of the migration to add"
},
"NuGetToken": {
"type": "string",
"description": "GitHub personal access token (classic) with the read:packages scope, for the NuGet feed",
"default": "Secrets must be entered via 'fallout :secrets [profile]'"
},
"NuGetUsername": {
"type": "string",
"description": "GitHub username for the NuGet feed"
},
"ProfileName": {
"type": "string"
},
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ jobs:
.fallout/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: CompilePlugin, Test'
run: ./build.cmd CompilePlugin Test
- name: 'Run: AddNuGetSource, CompilePlugin, Test'
run: ./build.cmd AddNuGetSource CompilePlugin Test
env:
NuGetUsername: ${{ secrets.NUGET_USERNAME }}
NuGetToken: ${{ secrets.NUGET_TOKEN }}
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ jobs:
.fallout/temp
~/.nuget/packages
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
- name: 'Run: Release'
run: ./build.cmd Release
- name: 'Run: AddNuGetSource, Release'
run: ./build.cmd AddNuGetSource Release
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
NuGetUsername: ${{ secrets.NUGET_USERNAME }}
NuGetToken: ${{ secrets.NUGET_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@ npm-debug.log
# Database
*.db*

/logs
/logs

# Local SQLite database of the CPDLC server
.data/
1 change: 1 addition & 0 deletions CPDLC.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ServerEndpoint": "https://vatpac-cpdlc.eoinmotherway.dev/hubs/controller",
"AutoConnect": false,
"Stations": ["YBBB", "YMMM", "NFFF", "AYPM"],
"LogLevel": "Verbose",
"MaxCurrentMessages": 50,
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<img src="./README.png" />
</h3>

> [!NOTE]
> Even though the development of this plugin was inspired by real ATM systems such as those from Thales Group, the plugin is absolutely NOT affiliated with or endorsed by said company. The plugin and all associated files shall be used solely for the purpose of simulation on the VATSIM network.
>
> The plugin and the CPDLC server are third-party software. They are not provided, operated or endorsed by VATSIM.

## Overview

This plugin enables CPDLC (Controller-Pilot Data Link Communications) functionality in vatSys, allowing controllers to send and receive datalink messages with aircraft on the VATSIM network.
Expand All @@ -26,9 +31,7 @@ Deploy your own CPDLC Server instance:

[![Deploy to DigitalOcean](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/YuKitsune/CPDLCPlugin/tree/main)

After deployment, configure the following environment variables:
- `Acars__0__StationIdentifier`: Your station identifier (e.g., YZZZ)
- `Acars__0__AuthenticationCode`: Your Hoppie ACARS authentication code
Before you deploy, set the `MasterKey` environment variable to a key from `openssl rand -base64 32`, and keep a copy of the key in a safe place. After deployment, open the setup URL from the server log to create the administrator. Then add your ACARS connection (station identifier and Hoppie authentication code) in Settings → ACARS on the server dashboard (`/settings/acars`).

## Installation

Expand Down
96 changes: 89 additions & 7 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ namespace _build;
GitHubActionsImage.WindowsLatest,
OnPushBranches = ["main"],
OnPullRequestBranches = ["main"],
InvokedTargets = [nameof(CompilePlugin), nameof(Test)],
InvokedTargets = [nameof(AddNuGetSource), nameof(CompilePlugin), nameof(Test)],
ImportSecrets = [nameof(NuGetUsername), nameof(NuGetToken)],
FetchDepth = 0)]
[GitHubActions(
"release",
GitHubActionsImage.WindowsLatest,
OnPushTags = ["v*"],
InvokedTargets = [nameof(Release)],
ImportSecrets = [nameof(GitHubToken)],
InvokedTargets = [nameof(AddNuGetSource), nameof(Release)],
ImportSecrets = [nameof(GitHubToken), nameof(NuGetUsername), nameof(NuGetToken)],
EnableGitHubToken = true,
FetchDepth = 0,
WritePermissions = [GitHubActionsPermissions.Contents])]
Expand All @@ -54,15 +55,32 @@ class Build : FalloutBuild
[Secret]
readonly string GitHubToken;

[Parameter("GitHub username for the NuGet feed")]
readonly string NuGetUsername;

[Parameter("GitHub personal access token (classic) with the read:packages scope, for the NuGet feed")]
[Secret]
readonly string NuGetToken;

[Parameter("Output directory for server build")]
readonly string ServerOutputDirectory;

[Parameter("Name of the migration to add")]
readonly string MigrationName;

[Parameter("Version to use instead of the GitVersion version, for example 1.0.0-rc1")]
readonly string ForceVersion;

[GitRepository]
readonly GitRepository GitRepository;

[GitVersion]
readonly GitVersion GitVersion;

// The NuGet feed that contains the vatSysToolbox package
const string NuGetSourceName = "YuKitsune";
const string NuGetSourceUrl = "https://nuget.pkg.github.com/YuKitsune/index.json";

const string ReleasePluginName = "CPDLCPlugin";
const string DebugPluginName = "CPDLCPlugin - Debug";
const string PluginAssemblyFileName = "CPDLCPlugin.dll";
Expand Down Expand Up @@ -147,9 +165,44 @@ class Build : FalloutBuild
Log.Information("vatSys.exe extracted to {Path}", VatSysExePath);
});

Target AddNuGetSource => _ => _
.Description("Adds the GitHub Packages NuGet feed with the GitHub credentials, or updates the credentials.")
.Requires(() => NuGetUsername)
.Requires(() => NuGetToken)
.Executes(() =>
{
// The .NET CLI can encrypt the password only on Windows
var storePasswordInClearText = !OperatingSystem.IsWindows();

var sourceExists = DotNetTasks.DotNet("nuget list source", logOutput: false)
.Any(o => o.Text.Contains(NuGetSourceUrl));

if (sourceExists)
{
Log.Information("Updating the credentials of the NuGet source {Name}", NuGetSourceName);
DotNetTasks.DotNetNuGetUpdateSource(s => s
.SetName(NuGetSourceName)
.SetSource(NuGetSourceUrl)
.SetUsername(NuGetUsername)
.SetPassword(NuGetToken)
.SetStorePasswordInClearText(storePasswordInClearText));
}
else
{
Log.Information("Adding the NuGet source {Name}", NuGetSourceName);
DotNetTasks.DotNetNuGetAddSource(s => s
.SetName(NuGetSourceName)
.SetSource(NuGetSourceUrl)
.SetUsername(NuGetUsername)
.SetPassword(NuGetToken)
.SetStorePasswordInClearText(storePasswordInClearText));
}
});

Target CompilePlugin => _ => _
.Description("Compiles the plugin")
.DependsOn(DownloadVatSys)
.After(AddNuGetSource)
.Executes(() =>
{
var version = GetSemanticVersion();
Expand All @@ -164,8 +217,8 @@ class Build : FalloutBuild
.SetConfiguration(Configuration)
.SetOutputDirectory(PluginBuildOutputDirectory)
.SetVersion(version)
.SetAssemblyVersion(GitVersion.MajorMinorPatch)
.SetFileVersion(GitVersion.MajorMinorPatch)
.SetAssemblyVersion(GetMajorMinorPatch())
.SetFileVersion(GetMajorMinorPatch())
.SetInformationalVersion(version)
.SetProperty("VatSysPath", VatSysExePath.Parent.Parent));
});
Expand Down Expand Up @@ -234,6 +287,7 @@ class Build : FalloutBuild

Target TestPlugin => _ => _
.DependsOn(DownloadVatSys)
.After(AddNuGetSource)
.Executes(() =>
{
Log.Information("Running plugin tests");
Expand Down Expand Up @@ -365,13 +419,29 @@ class Build : FalloutBuild
.SetConfiguration(Configuration)
.SetOutput(ServerBuildOutputDirectory)
.SetVersion(version)
.SetAssemblyVersion(GitVersion.MajorMinorPatch)
.SetFileVersion(GitVersion.MajorMinorPatch)
.SetAssemblyVersion(GetMajorMinorPatch())
.SetFileVersion(GetMajorMinorPatch())
.SetInformationalVersion(version));

Log.Information("Server published to {OutputDirectory}", ServerBuildOutputDirectory);
});

Target AddMigration => _ => _
.Description("Adds an EF Core migration for each database provider of the server (SQLite and PostgreSQL).")
.Requires(() => MigrationName)
.Executes(() =>
{
AddServerMigration("SqliteCpdlcDbContext", "Persistence/Migrations/Sqlite");
AddServerMigration("PostgreSqlCpdlcDbContext", "Persistence/Migrations/PostgreSql");

void AddServerMigration(string context, string outputDirectory)
{
Log.Information("Adding migration {MigrationName} for {Context}", MigrationName, context);
DotNetTasks.DotNet(
$"ef migrations add {MigrationName} --project {ServerProjectPath} --context {context} --output-dir {outputDirectory}");
}
});

Target PackageServer => _ => _
.Description("Bundles the server into a zip archive.")
.DependsOn(CompileServer)
Expand Down Expand Up @@ -477,8 +547,20 @@ static AbsolutePath GetVatSysProfilePath(string profileName)
return Path.Combine(documentsPath, "vatSys Files", "Profiles", profileName);
}

// The assembly and file versions cannot have a pre-release label or build metadata
string GetMajorMinorPatch()
{
if (!string.IsNullOrEmpty(ForceVersion))
return ForceVersion.Split('-', '+')[0];

return GitVersion?.MajorMinorPatch ?? "0.0.0";
}

string GetSemanticVersion()
{
if (!string.IsNullOrEmpty(ForceVersion))
return ForceVersion;

// For main/master branch, or if we're on a detached head (building from a tag)
// use major.minor.patch (e.g., "1.2.3")
if (string.IsNullOrEmpty(GitVersion.BranchName) || GitVersion.BranchName is "main" or "master")
Expand Down
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,36 @@ services:
dockerfile: source/CPDLCServer/Dockerfile
env_file:
- .env
environment:
DataPath: /data
# Used only when DatabaseProvider=PostgreSql. In the container, the database is at the postgres service.
DatabaseConnectionString: Host=postgres;Port=5432;Database=cpdlc;Username=cpdlc;Password=cpdlc
depends_on:
postgres:
condition: service_healthy
required: false
ports:
- "8080:8080"
volumes:
- server-data:/data

# A PostgreSQL server for local development. Start it with: docker compose --profile postgres up
postgres:
profiles: [postgres]
image: postgres:17-alpine
environment:
POSTGRES_DB: cpdlc
POSTGRES_USER: cpdlc
POSTGRES_PASSWORD: cpdlc
ports:
- "127.0.0.1:5432:5432"
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U cpdlc -d cpdlc"]
interval: 5s
timeout: 5s
retries: 10

ngrok:
profiles: [ngrok]
Expand All @@ -25,3 +53,7 @@ services:
- .env
ports:
- 4040:4040

volumes:
server-data:
postgres-data:
1 change: 0 additions & 1 deletion docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Stage 1: Build the static site with Node.
FROM node:lts-alpine AS build
ENV FORCE_COLOR=0
RUN corepack enable
WORKDIR /opt/docusaurus
COPY . /opt/docusaurus/
RUN npm ci
Expand Down
Loading