Skip to content

Commit d408a38

Browse files
authored
Merge pull request #282 from TwinFan/Next
v4.2.1 OpenSky API Credentials
2 parents 6014c2f + 563a21c commit d408a38

36 files changed

+2678
-259
lines changed

.github/actions/build-mac/action.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@ outputs:
2222
runs:
2323
using: "composite"
2424
steps:
25-
- name: Install required libs
26-
shell: bash
27-
run: |
28-
brew install ninja
29-
- name: Prepare
30-
shell: bash
31-
run: |
32-
mkdir build-mac
3325
- name: CMake
3426
shell: bash
3527
run: |
28+
mkdir build-mac
3629
cd build-mac
3730
pwd
3831
cmake -G Ninja ..

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif()
2323
set(CMAKE_BUILD_TYPE RelWithDebInfo)
2424

2525
project(LiveTraffic
26-
VERSION 4.2.0
26+
VERSION 4.2.1
2727
DESCRIPTION "LiveTraffic X-Plane plugin")
2828
set(VERSION_BETA 0)
2929

@@ -148,6 +148,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/SDK/CHeaders/XPLM")
148148
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/ImGui")
149149
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/ImGui/misc/cpp")
150150
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/ImgWindow")
151+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/portable-file-dialogs")
151152
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/Font")
152153
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/metaf/include")
153154

Include/Constants.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ extern time_t LT_BETA_VER_LIMIT; // BETA versions are limited
145145
extern char LT_BETA_VER_LIMIT_TXT[];
146146
#define BETA_LIMITED_VERSION "BETA limited to %s"
147147
#define BETA_LIMITED_EXPIRED "BETA-Version limited to %s has EXPIRED -> SHUTTING DOWN! Get an up-to-date version from X-Plane.org."
148-
constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
148+
constexpr int LT_NEW_VER_CHECK_TIME = 24; ///< [h] between two checks for a new LT version
149149

150150
//MARK: Text Constants
151151
#define LIVE_TRAFFIC "LiveTraffic"
@@ -154,10 +154,9 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
154154
#define PLUGIN_SIGNATURE "TwinFan.plugin.LiveTraffic"
155155
#define PLUGIN_DESCRIPTION "Create Multiplayer Aircraft based on live traffic."
156156
constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
157-
#define LT_DOWNLOAD_URL "https://forums.x-plane.org/index.php?/files/file/49749-livetraffic/"
158-
#define LT_DOWNLOAD_CH "X-Plane.org"
159-
#define OPSKY_EDIT_AC "https://opensky-network.org/aircraft-profile?icao24="
160-
#define OPSKY_EDIT_ROUTE "https://opensky-network.org/add-route?callsign="
157+
#define LT_DOWNLOAD_URL "https://forums.x-plane.org/files/file/49749-livetraffic/"
158+
#define OPSKY_EDIT_AC "https://opensky-network.org/data/aircraft?icao24="
159+
// Disabled until OpenSky offers the service again to maintain routes - #define OPSKY_EDIT_ROUTE "https://opensky-network.org/add-route?callsign="
161160
#define MSG_DISABLED "Disabled"
162161
#define MSG_STARTUP "LiveTraffic %s starting up..."
163162
#define MSG_WELCOME "LiveTraffic %s successfully loaded!"
@@ -211,8 +210,8 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
211210
#define CFG_DEFAULT_CAR_TYPE "DEFAULT_CAR_TYPE"
212211
#define CFG_DEFAULT_AC_TYP_INFO "Default a/c type is '%s'"
213212
#define CFG_DEFAULT_CAR_TYP_INFO "Default car type is '%s'"
214-
#define CFG_OPENSKY_USER "OpenSky_User"
215-
#define CFG_OPENSKY_PWD "OpenSky_Pwd"
213+
#define CFG_OPENSKY_CLIENT "OpenSky_Client"
214+
#define CFG_OPENSKY_SECRET "OpenSky_Secret"
216215
#define CFG_ADSBEX_API_KEY "ADSBEX_API_KEY"
217216
#define CFG_RT_LICENSE "RealTraffic_License"
218217
#define CFG_FSC_USER "FSC_User"
@@ -242,6 +241,7 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
242241
#define MENU_HELP_INSTALL_CSL "Installaton of CSL Models"
243242
#define MENU_HELP_SUPPORT_FORUM "Support Forum"
244243
#define MENU_HELP_SUPPORT_HOWTO "Support HowTo"
244+
#define MENU_HELP_DOWNLOAD "Download LiveTraffic"
245245
#define MENU_NEWVER "New Version %s available!"
246246
#ifdef DEBUG
247247
#define MENU_RELOAD_PLUGINS "Reload all Plugins (Caution!)"
@@ -278,8 +278,8 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
278278
#define HELP_SET_CSL "setup/configuration/settings-csl"
279279
#define HELP_SET_DEBUG "setup/configuration/settings-debug"
280280

281-
#define URL_SUPPORT_FORUM "https://forums.x-plane.org/index.php?/forums/forum/457-livetraffic-support/"
282-
#define URL_SUPPORT_HOWTO "https://forums.x-plane.org/index.php?/forums/topic/174691-support"
281+
#define URL_SUPPORT_FORUM "https://forums.x-plane.org/forums/forum/457-livetraffic-support/"
282+
#define URL_SUPPORT_HOWTO "https://forums.x-plane.org/forums/topic/174691-support-attach-a-logtxt-file-and-provide-the-following-details/"
283283

284284
//MARK: File Paths
285285
// these are under the plugins directory
@@ -304,6 +304,7 @@ constexpr const char* PATH_DELIMS = "/\\"; ///< potential path delimiters i
304304

305305
//MARK: Error Texsts
306306
constexpr long HTTP_OK = 200;
307+
constexpr long HTTP_MOVED = 302; ///< redirect
307308
constexpr long HTTP_BAD_REQUEST = 400;
308309
constexpr long HTTP_UNAUTHORIZED = 401;
309310
constexpr long HTTP_PAYMENT_REQU = 402;

Include/DataRefs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Doc8643 {
118118
/// non-standardized human-readable `model` entries in
119119
/// tracking data (especially in OpenSky's data) to an ICAO a/c type code.
120120
/// The file has been created by forum user crbascott.
121-
/// @see https://forums.x-plane.org/index.php?/forums/topic/188206-matching-lacks-icao-ac-type-code/
121+
/// @see https://forums.x-plane.org/forums/topic/188206-matching-lacks-icao-ac-type-code/
122122
namespace ModelIcaoType
123123
{
124124
/// Read the `model_typecode.txt` file
@@ -753,8 +753,8 @@ class DataRefs
753753

754754
std::string sDefaultAcIcaoType = CSL_DEFAULT_ICAO_TYPE;
755755
std::string sDefaultCarIcaoType = CSL_CAR_ICAO_TYPE;
756-
std::string sOpenSkyUser; ///< OpenSky Network user
757-
std::string sOpenSkyPwd; ///< OpenSky Network password
756+
std::string sOpenSkyClient; ///< OpenSky Network Client ID
757+
std::string sOpenSkySecret; ///< OpenSky Network Client Secret
758758
std::string sADSBExAPIKey; ///< ADS-B Exchange API key
759759
std::string sRTLicense; ///< RealTraffic License
760760
std::string sFSCUser; ///< FSCharter login user
@@ -1009,10 +1009,10 @@ class DataRefs
10091009
inline bool IsChannelEnabled (dataRefsLT ch) const { return bChannel[ch - DR_CHANNEL_FIRST]; }
10101010
int CntChannelEnabled () const;
10111011

1012-
void GetOpenSkyCredentials (std::string& user, std::string& pwd)
1013-
{ user = sOpenSkyUser; pwd = sOpenSkyPwd; }
1014-
void SetOpenSkyUser (const std::string& user) { sOpenSkyUser = user; OpenSkyRRemain = LONG_MAX; OpenSkyRetryAt.clear(); }
1015-
void SetOpenSkyPwd (const std::string& pwd) { sOpenSkyPwd = pwd; OpenSkyRRemain = LONG_MAX; OpenSkyRetryAt.clear(); }
1012+
void GetOpenSkyCredentials (std::string& clientId, std::string& clientSecret)
1013+
{ clientId = sOpenSkyClient; clientSecret = sOpenSkySecret; }
1014+
void SetOpenSkyClient (const std::string& clientId) { sOpenSkyClient = clientId; OpenSkyRRemain = LONG_MAX; OpenSkyRetryAt.clear(); }
1015+
void SetOpenSkySecret (const std::string& clientSecret) { sOpenSkySecret = clientSecret; OpenSkyRRemain = LONG_MAX; OpenSkyRetryAt.clear(); }
10161016

10171017
const std::string& GetADSBExAPIKey () const { return sADSBExAPIKey; }
10181018
void SetADSBExAPIKey (const std::string& apiKey) { sADSBExAPIKey = apiKey; }

Include/LTChannel.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ LTChannel* LTFlightDataGetCh (dataRefsLT ch);
364364
//
365365
void LTFlightDataAcMaintenance();
366366

367+
//
368+
// MARK: Network helper functions
369+
//
370+
371+
// cleanup the slist, returns if something was actually deleted
372+
bool CurlCleanupSlist (curl_slist* &pList);
373+
367374
//
368375
//MARK: Parson Helper Functions
369376
//

Include/LTOpenSky.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,23 @@
2929

3030
//MARK: OpenSky Constants
3131
#define OPSKY_CHECK_NAME "OpenSky Explorer"
32-
#define OPSKY_CHECK_URL "https://opensky-network.org/network/explorer"
32+
#define OPSKY_CHECK_URL "https://map.opensky-network.org/?lat=%.3f&lon=%.3f"
3333
#define OPSKY_CHECK_POPUP "Check OpenSky's coverage"
3434

35+
#define OPSKY_URL_GETTOKEN "https://auth.opensky-network.org/auth/realms/opensky-network/protocol/openid-connect/token"
36+
#define OPSKY_BODY_GETTOKEN "grant_type=client_credentials&client_id=%s&client_secret=%s"
37+
#define OPSKY_ACCESS_TOKEN "access_token"
38+
#define OPSKY_AUTH_BEARER "Authorization: Bearer "
39+
#define OPSKY_AUTH_EXPIRES "expires_in"
40+
constexpr long OPSKY_AUTH_EXP_DEFAULT = 1800; ///< default expiration in case we don't find expiration field
41+
3542
#define OPSKY_NAME "OpenSky Network"
3643
#define OPSKY_URL_ALL "https://opensky-network.org/api/states/all?lamin=%.3f&lomin=%.3f&lamax=%.3f&lomax=%.3f"
37-
#define OPSKY_SLUG_FMT "https://opensky-network.org/network/explorer?icao24=%06lx"
44+
#define OPSKY_SLUG_FMT "https://map.opensky-network.org/?icao=%06lx"
3845
#define OPSKY_TIME "time"
3946
#define OPSKY_AIRCRAFT_ARR "states"
40-
#define OPSKY_RREMAIN "X-Rate-Limit-Remaining:"
41-
#define OPSKY_RETRY "X-Rate-Limit-Retry-After-Seconds:"
47+
#define OPSKY_RREMAIN "x-rate-limit-remaining:"
48+
#define OPSKY_RETRY "x-rate-limit-retry-after-seconds:"
4249
constexpr int OPSKY_TRANSP_ICAO = 0; // icao24
4350
constexpr int OPSKY_CALL = 1; // callsign
4451
constexpr int OPSKY_COUNTRY = 2; // origin_county
@@ -60,14 +67,31 @@ constexpr double OPSKY_SMOOTH_GROUND = 35.0; // smooth 35s of ground data
6067
//
6168
class OpenSkyConnection : public LTFlightDataChannel
6269
{
70+
protected:
71+
enum State {
72+
OPSKY_STATE_NONE = 0, ///< no/initial/unknown status
73+
OPSKY_STATE_GETTING_TOKEN, ///< have credentials, but no access token yet
74+
OPSKY_STATE_GET_PLANES, ///< normal operations: fetch planes
75+
} eState = OPSKY_STATE_NONE;
76+
struct curl_slist* pHdrForm = nullptr; ///< HTTP Header (needed during fetching a token)
77+
struct curl_slist* pHdrToken = nullptr; ///< HTTP Header containing the bearer token
78+
float tTokenExpiration = NAN; ///< when will the token expire?
6379
public:
6480
OpenSkyConnection ();
81+
void ResetStatus (); ///< used to force fetching a new token, e.g. after change of credentials
6582
std::string GetURL (const positionTy& pos) override;
83+
void ComputeBody (const positionTy& pos) override; ///< only needed for token request, will then form token request body
6684
bool ProcessFetchedData () override;
6785
std::string GetStatusText () const override; ///< return a human-readable staus
6886
// // shall data of this channel be subject to LTFlightData::DataSmoothing?
6987
// bool DoDataSmoothing (double& gndRange, double& airbRange) const override
7088
// { gndRange = OPSKY_SMOOTH_GROUND; airbRange = OPSKY_SMOOTH_AIRBORNE; return true; }
89+
90+
/// @brief Process OpenSKy's 'crendetials.json' file to fetch User ID/Secret from it
91+
static bool ProcessCredentialsJson (const std::string& sFileName,
92+
std::string& sClientId,
93+
std::string& sSecret);
94+
7195
protected:
7296
void Main () override; ///< virtual thread main function
7397

@@ -155,6 +179,7 @@ constexpr unsigned long OPSKY_NUM_LN_PER_POS = 250;
155179
class OpenSkyAcMasterFile : public LTACMasterdataChannel
156180
{
157181
protected:
182+
char sAcDbfileName[50] = {0}; ///< Aircraft Database file name
158183
std::ifstream fAcDb; ///< Aircraft Database file
159184
std::string ln; ///< a line in the database file
160185

@@ -167,7 +192,8 @@ class OpenSkyAcMasterFile : public LTACMasterdataChannel
167192
public:
168193
std::string GetURL (const positionTy&) override { return ""; } ///< No URL for the standard request processing
169194
bool ProcessFetchedData () override; ///< Process looked up master data
170-
protected:
195+
std::string GetStatusText () const override; ///< adds the database date to the status text
196+
protected:
171197
bool AcceptRequest (const acStatUpdateTy& requ) override; ///< accept only master data requests
172198
void Main () override; ///< virtual thread main function
173199
bool LookupData (); ///< perform the file lookup

Include/LTSayIntentions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
#define SI_DISPLAYNAME "displayname"
4545
#define SI_ORIGIN "origin"
4646
#define SI_DEST "final_destination"
47-
#define SI_CALL "callsign"
47+
#define SI_CALL "flight_icao" ///< callsign machine-readable, e.g. "AAL2502"
48+
#define SI_CALL_SPOKEN "callsign" ///< callsign as spoken, e.g. "American-two-five-zero-two"
4849
#define SI_REG "tail_number"
4950
#define SI_HEADING "heading"
5051
#define SI_AC_TYPE "aircraft_icao"

Include/LiveTraffic.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ void LTMainStop ();
162162

163163
void LTRegularUpdates(); ///< collects all updates that need to be done up to every flight loop cycle
164164
void MenuUpdateAllItemStatus();
165+
bool IsNewVersionAvail (); ///< Is there a new version of LiveTraffic available for download?
166+
std::string GetNewVersionNr (); ///< Return the new version's number
165167
void HandleNewVersionAvail ();
166168

167169
#ifdef DEBUG
@@ -189,6 +191,9 @@ bool IsDir (const std::string& path);
189191
/// List of files in a directory (wrapper around XPLMGetDirectoryContents)
190192
std::vector<std::string> GetDirContents (const std::string& path, bool bDirOnly = false);
191193

194+
/// Return a (platform-specific) path to the user's Download folder
195+
std::string GetDefaultDownloadDir();
196+
192197
/// @brief Read a text line from file, no matter if ended by CRLF or LF
193198
std::istream& safeGetline(std::istream& is, std::string& t);
194199

@@ -430,8 +435,8 @@ float interpolate (const std::vector<float>& scale,
430435
inline long randoml (long min, long max)
431436
{ return long(((double) rand() / (RAND_MAX+1.0)) * (max-min+1)) + min; }
432437

433-
// gets latest version info from X-Plane.org
434-
bool FetchXPlaneOrgVersion ();
438+
/// Fetches the latest available LiveTraffic version number
439+
bool FetchLatestLTVersion ();
435440

436441
/// LiveTraffic's version number as pure integer for returning in a dataRef, like 201 for v2.01
437442
int GetLTVerNum(void* = NULL);

Include/SettingsUI.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
// Settings UI Main window
2626
//
2727

28+
// Forward declarations for portable-file-dialog stuff, which we don't want to include in pre-compiled header
29+
namespace pfd { class open_file; }
30+
void pfd_open_file_deleter (pfd::open_file* p);
31+
2832
/// Settings dialog
2933
class LTSettingsUI : public LTImgWindow
3034
{
@@ -33,9 +37,11 @@ class LTSettingsUI : public LTImgWindow
3337
char sFilter[50] = {0};
3438

3539
// Channel: OpenSky
36-
std::string sOpenSkyUser; ///< OpenSky Network user
37-
std::string sOpenSkyPwd; ///< OpenSky Network password
38-
bool bOpenSkyPwdClearText = false; ///< Is OpenSky pwd displayed clear text?
40+
/// smart pointer to the at most one System File Open Dialog
41+
std::unique_ptr<pfd::open_file, decltype(&pfd_open_file_deleter)> pfdOpenFile;
42+
std::string sOpenSkyClientId; ///< OpenSky Network Client ID
43+
std::string sOpenSkySecret; ///< OpenSky Network Secret
44+
bool bOpenSkySecretClearText = false; ///< Is OpenSky pwd displayed clear text?
3945

4046
// Channel: ADS-B Exchange
4147
enum {

Lib/ImgWindow/ImgWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ ImgWindow::HandleKeyFuncCB(
562562
// Apparently, the virtual VR keyboard sends both the Up and the Down
563563
// event within the same drawing cycle, which would overwrite
564564
// io.KeyDown[XPLM_VK_BACK] with false again before we could pass on true.
565-
// Also see https://forums.x-plane.org/index.php?/forums/topic/147139-dear-imgui-x-plane/&do=findComment&comment=2032062
565+
// Also see https://forums.x-plane.org/forums/topic/147139-dear-imgui-x-plane/&do=findComment&comment=2032062
566566
// though I am following a different solution:
567567
// So we ignore the "up" event (release key) here, and do the actual
568568
// release only after the next drawing cycle (flag bResetBackspace).

0 commit comments

Comments
 (0)