This repository was archived by the owner on Apr 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCoFrancePlugIn.cpp
More file actions
616 lines (487 loc) · 24.6 KB
/
Copy pathCoFrancePlugIn.cpp
File metadata and controls
616 lines (487 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
#include "pch.h"
#include "CoFrancePlugIn.h"
#include "RadarScreen.h"
CoFrancePlugIn::CoFrancePlugIn(void):CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE, MY_PLUGIN_NAME, MY_PLUGIN_VERSION, MY_PLUGIN_DEVELOPER, MY_PLUGIN_COPYRIGHT)
{
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
char DllPathFile[_MAX_PATH];
GetModuleFileNameA(HINSTANCE(&__ImageBase), DllPathFile, sizeof(DllPathFile));
DllPath = DllPathFile;
DllPath.resize(DllPath.size() - strlen("CoFrance.dll"));
LoadConfigFile();
Stca = new CSTCA(CoFranceConfig);
// Register tag items
RegisterTagItemType("Two number ground speed", CoFranceTags::GS);
RegisterTagItemType("Vertical Indicator", CoFranceTags::VZ_INDICATOR);
RegisterTagItemType("Dynamic Coordinated Point (reduced)", CoFranceTags::COPXN_POINT_REDUCED);
RegisterTagItemType("Dynamic Coordinated Level (reduced)", CoFranceTags::COPXN_ALT_REDUCED);
RegisterTagItemType("Dynamic Coordinated Level (full)", CoFranceTags::COPXN_ALT_FULL);
RegisterTagItemType("Dummy item", CoFranceTags::DUMMY);
RegisterTagItemType("Dummy item (tagged)", CoFranceTags::DUMMY_TAGGED);
RegisterTagItemType("Scratchpad Indicator (Detail)", CoFranceTags::SCRATCHPAD_INDIC);
RegisterTagItemType("Conflict group (Detail)", CoFranceTags::CONFLICT_GROUP_DETAIL);
RegisterTagItemType("Conflict group (Tagged)", CoFranceTags::CONFLICT_GROUP_TAGGED);
RegisterTagItemType("RFL", CoFranceTags::RFL);
RegisterTagItemType("CFL", CoFranceTags::CFL);
RegisterTagItemType("CFL (Detail)", CoFranceTags::CFL_DETAILED);
RegisterTagItemType("Approach Intention Code", CoFranceTags::APP_INTENTION);
RegisterTagItemType("Vertical Speed", CoFranceTags::VZ);
RegisterTagItemType("STCA Indicator", CoFranceTags::STCA);
RegisterTagItemType("OCL Flag", CoFranceTags::OCL_FLAG);
RegisterTagItemType("Assigned Speed", CoFranceTags::ASSIGNED_SPEED);
RegisterTagItemFunction("Assign Conflict Group", CoFranceTags::FUNCTION_CONFLICT_POPUP);
//RegisterTagItemFunction("Show OCL", CoFranceTags::FUNCTION_OCL_TP);
RegisterTagItemFunction("Open ASP Popup", CoFranceTags::FUNCTION_OPEN_ASP);
RegisterTagItemType("Stand", CoFranceTags::STAND);
DisplayUserMessage("Message", "CoFrance PlugIn", string("Version " + string(MY_PLUGIN_VERSION) + " loaded.").c_str(), false, false, false, false, false);
}
CoFrancePlugIn::~CoFrancePlugIn()
{
GdiplusShutdown(gdiplusToken);
}
CRadarScreen* CoFrancePlugIn::OnRadarScreenCreated(const char* sDisplayName, bool NeedRadarContent, bool GeoReferenced, bool CanBeSaved, bool CanBeCreated)
{
if (CanLoadRadarScreen)
return new RadarScreen(this);
else
return NULL;
}
bool CoFrancePlugIn::OnCompileCommand(const char* sCommandLine)
{
if (strcmp(sCommandLine, ".cofrance reload") == 0) {
LoadConfigFile();
return true;
}
if (strcmp(sCommandLine, ".cofrance reload-local") == 0 || strcmp(sCommandLine, ".cofrl") == 0) {
LoadConfigFile(false);
return true;
}
if (strcmp(sCommandLine, ".cofrance perf") == 0) {
performanceMode = true;
return true;
}
if (strcmp(sCommandLine, ".cofrance debug") == 0) {
Debug = !Debug;
if (Debug) {
DisplayUserMessage("CoFrance", "Debug", "Debug enabled", true, true, false, true, false);
}
else {
DisplayUserMessage("CoFrance", "Debug", "Debug disabled", true, true, false, true, false);
}
return true;
}
return false;
}
void CoFrancePlugIn::OnGetTagItem(CFlightPlan FlightPlan, CRadarTarget RadarTarget, int ItemCode, int TagData, char sItemString[16], int* pColorCode, COLORREF* pRGB, double* pFontSize)
{
if (ItemCode == CoFranceTags::GS) {
if (!RadarTarget.IsValid())
return;
int gs = roundUp(RadarTarget.GetPosition().GetReportedGS(), 10);
string gs_s = padWithZeros(3, gs);
strcpy_s(sItemString, 16, gs_s.substr(0, 2).c_str());
}
if (ItemCode == CoFranceTags::SCRATCHPAD_INDIC) {
string txt = CoFranceCharacters::Pen;
if (strlen(FlightPlan.GetControllerAssignedData().GetScratchPadString()) > 0)
txt = FlightPlan.GetControllerAssignedData().GetScratchPadString();
strcpy_s(sItemString, 16, txt.substr(0, 15).c_str());
}
if (ItemCode == CoFranceTags::CONFLICT_GROUP_DETAIL) {
if (ConflictGroups.find(FlightPlan.GetCallsign()) != ConflictGroups.end()) {
strcpy_s(sItemString, 16, ConflictGroups[FlightPlan.GetCallsign()].c_str());
*pColorCode = TAG_COLOR_RGB_DEFINED;
*pRGB = GetConflictGroupColor(this->CoFranceConfig, ConflictGroups[FlightPlan.GetCallsign()].c_str());
}
else {
strcpy_s(sItemString, 16, CoFranceCharacters::Moon.c_str());
}
}
if (ItemCode == CoFranceTags::CONFLICT_GROUP_TAGGED) {
if (ConflictGroups.find(FlightPlan.GetCallsign()) != ConflictGroups.end()) {
strcpy_s(sItemString, 16, ConflictGroups[FlightPlan.GetCallsign()].c_str());
*pColorCode = TAG_COLOR_RGB_DEFINED;
*pRGB = GetConflictGroupColor(this->CoFranceConfig, ConflictGroups[FlightPlan.GetCallsign()].c_str());
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::DUMMY) {
DetailedAircraft = RadarTarget.GetCallsign();
strcpy_s(sItemString, 16, "");
}
if (ItemCode == CoFranceTags::ASSIGNED_SPEED) {
string aspeed = "";
if (FlightPlan.GetControllerAssignedData().GetAssignedMach() != 0) {
aspeed = "m";
aspeed += "." + to_string(FlightPlan.GetControllerAssignedData().GetAssignedMach());
if (string(FlightPlan.GetControllerAssignedData().GetFlightStripAnnotation(CoFranceTags::ANNOTATION_SPEED_SIGN)) == string("+"))
aspeed += "+";
if (string(FlightPlan.GetControllerAssignedData().GetFlightStripAnnotation(CoFranceTags::ANNOTATION_SPEED_SIGN)) == string("-"))
aspeed += "-";
} else if (FlightPlan.GetControllerAssignedData().GetAssignedSpeed() != 0) {
aspeed = "k";
if (FlightPlan.GetControllerAssignedData().GetAssignedSpeed() % 10 == 1)
aspeed += to_string((FlightPlan.GetControllerAssignedData().GetAssignedSpeed() - 1)/10) + "+";
else if (FlightPlan.GetControllerAssignedData().GetAssignedSpeed() % 10 == 9)
aspeed += to_string((FlightPlan.GetControllerAssignedData().GetAssignedSpeed() + 1)/10) + "-";
else
aspeed += to_string(FlightPlan.GetControllerAssignedData().GetAssignedSpeed()/10);
}
strcpy_s(sItemString, 16, aspeed.c_str());
}
if (ItemCode == CoFranceTags::DUMMY_TAGGED) {
if (DetailedAircraft == RadarTarget.GetCallsign())
DetailedAircraft = "";
strcpy_s(sItemString, 16, "");
}
if (ItemCode == CoFranceTags::RFL) {
string rfl = "RFL";
if (FlightPlan.IsValid()) {
if (FlightPlan.GetFinalAltitude() > 0) {
rfl = padWithZeros(2, FlightPlan.GetFinalAltitude() / 1000);
// VFRs can be cleared up to 500 feet interval so we have to display more
if (FlightPlan.GetFlightPlanData().GetPlanType() == "V")
rfl = padWithZeros(3, FlightPlan.GetFinalAltitude() / 100);
if (FlightPlan.GetFinalAltitude() <= GetTransitionAltitude())
rfl = "A" + rfl;
}
}
strcpy_s(sItemString, 16, rfl.c_str());
}
if (ItemCode == CoFranceTags::CFL || ItemCode == CoFranceTags::CFL_DETAILED) {
string cfl = "";
if (ItemCode == CoFranceTags::CFL_DETAILED)
cfl = "CFL";
if (FlightPlan.IsValid()) {
if (FlightPlan.GetClearedAltitude() > 0) {
cfl = padWithZeros(2, FlightPlan.GetClearedAltitude() / 1000);
// VFRs can be cleared up to 500 feet interval so we have to display more
if (FlightPlan.GetFlightPlanData().GetPlanType() == "V")
cfl = padWithZeros(3, FlightPlan.GetClearedAltitude() / 100);
if (FlightPlan.GetClearedAltitude() <= GetTransitionAltitude())
cfl = "A" + cfl;
}
if (FlightPlan.GetControllerAssignedData().GetClearedAltitude() == 1)
cfl = CoFranceCharacters::ClearedAPPIndicator.c_str();;
if (FlightPlan.GetControllerAssignedData().GetClearedAltitude() == 2)
cfl = CoFranceCharacters::ClearedVisualIndicator.c_str();
// If not detailed and reached alt, then nothing to show
if (ItemCode == CoFranceTags::CFL && abs(RadarTarget.GetPosition().GetFlightLevel() - FlightPlan.GetClearedAltitude()) < 100)
cfl = "";
}
strcpy_s(sItemString, 16, cfl.c_str());
}
if (ItemCode == CoFranceTags::VZ_INDICATOR) {
if (!RadarTarget.IsValid())
return;
string tendency = "-";
int delta_fl = RadarTarget.GetPosition().GetFlightLevel() -
RadarTarget.GetPreviousPosition(RadarTarget.GetPosition()).GetFlightLevel();
if (abs(delta_fl) >= 10)
tendency = delta_fl < 0 ? "|" : "^";
strcpy_s(sItemString, 16, tendency.c_str());
}
if (ItemCode == CoFranceTags::APP_INTENTION) {
// Three types of codes:
// 1. VFR
// 2. Arrival (Assigned Runway with different colours)
// 3. Departure (Abbreviated SID)
if (FlightPlan.IsValid()) {
if (FlightPlan.GetFlightPlanData().GetPlanType()[0] == 'V') {
// We have a VFR flight
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_vfr");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, "VFR");
}
else {
// We have a departure
if (FlightPlan.GetDistanceFromOrigin() <= 50) {
string abbr_sid = "";
if (strlen(FlightPlan.GetFlightPlanData().GetSidName()) > 0) {
abbr_sid = FlightPlan.GetFlightPlanData().GetSidName();
abbr_sid = abbr_sid.substr(0, 3);
}
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, abbr_sid.c_str());
}
else {
// We have an arrival
string arr_rwy = "";
if (strlen(FlightPlan.GetFlightPlanData().GetArrivalRwy()) > 0) {
arr_rwy = FlightPlan.GetFlightPlanData().GetArrivalRwy();
arr_rwy = arr_rwy.substr(0, 3);
}
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_arrival");
if (startsWith("LFPG", FlightPlan.GetFlightPlanData().GetDestination()) &&
(startsWith("26", FlightPlan.GetFlightPlanData().GetArrivalRwy()) || startsWith("08", FlightPlan.GetFlightPlanData().GetArrivalRwy()))) {
// South arrival at LFPG, different colour
element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_lfpg_arr_south");
}
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, arr_rwy.c_str());
}
}
}
}
if (ItemCode == CoFranceTags::VZ) {
if (!RadarTarget.IsValid())
return;
string VerticalRate = "00";
CRadarTargetPositionData pos = RadarTarget.GetPosition();
CRadarTargetPositionData oldpos = RadarTarget.GetPreviousPosition(pos);
int mathVerticalRate = 0;
if (pos.IsValid() && oldpos.IsValid()) {
int deltaalt = pos.GetFlightLevel() - oldpos.GetFlightLevel();
int deltaT = oldpos.GetReceivedTime() - pos.GetReceivedTime();
if (deltaT > 0) {
float vz = abs(deltaalt) * (60.0f / deltaT);
mathVerticalRate = (int)vz;
// If the rate is too much
if ((int)abs(vz) >= 9999) {
VerticalRate = "++";
if (deltaalt < 0)
VerticalRate = "--";
}
else if (abs(vz) >= 100 && abs(deltaalt) >= 20) {
string rate = padWithZeros(2, (int)abs(vz / 100));
VerticalRate = "+" + rate;
if (deltaalt < 0)
VerticalRate = "-" + rate;
}
}
}
strcpy_s(sItemString, 16, VerticalRate.c_str());
}
if (ItemCode == CoFranceTags::COPXN_POINT_REDUCED) {
if (!FlightPlan.IsValid())
return;
string copx = "";
if (FlightPlan.GetTrackingControllerIsMe()) {
if (strlen(FlightPlan.GetExitCoordinationPointName()) > 0) {
copx = FlightPlan.GetExitCoordinationPointName();
*pColorCode = GetCoordinationTagColour(FlightPlan.GetExitCoordinationNameState());
}
}
else {
if (strlen(FlightPlan.GetEntryCoordinationPointName()) > 0) {
copx = FlightPlan.GetEntryCoordinationPointName();
*pColorCode = GetCoordinationTagColour(FlightPlan.GetEntryCoordinationPointState());
}
}
if (string(FlightPlan.GetControllerAssignedData().GetDirectToPointName()) == copx) {\
// If direct to COPX has been given, no need to display it
copx = "";
}
strcpy_s(sItemString, 16, copx.substr(0, 15).c_str());
}
if (ItemCode == CoFranceTags::COPXN_ALT_REDUCED || ItemCode == CoFranceTags::COPXN_ALT_FULL) {
if (!FlightPlan.IsValid())
return;
string copx_alt = "";
if (FlightPlan.GetTrackingControllerIsMe()) {
if (FlightPlan.GetExitCoordinationAltitude() > 0) {
copx_alt = string("x") + padWithZeros(2, FlightPlan.GetExitCoordinationAltitude() / 1000);
*pColorCode = GetCoordinationTagColour(FlightPlan.GetExitCoordinationAltitudeState());
}
}
else if (FlightPlan.GetEntryCoordinationAltitude() > 0) {
copx_alt = string("e") + padWithZeros(2, FlightPlan.GetEntryCoordinationAltitude() / 1000);
*pColorCode = GetCoordinationTagColour(FlightPlan.GetEntryCoordinationAltitudeState());
}
if (ItemCode == CoFranceTags::COPXN_ALT_FULL && copx_alt.size() == 0) {
if (FlightPlan.GetTrackingControllerIsMe())
copx_alt = "x...";
else
copx_alt = "e...";
}
strcpy_s(sItemString, 16, copx_alt.substr(0, 15).c_str());
}
if (ItemCode == CoFranceTags::STCA) {
if (Stca->IsSTCA(RadarTarget.GetCallsign())) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "sep_warning");
if (Blink)
element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "stca_warning");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, "STCA");
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::OCL_FLAG) {
if (!FlightPlan.IsValid())
return;
string test = FlightPlan.GetFlightPlanData().GetRoute();
const char* destination = FlightPlan.GetFlightPlanData().GetDestination();
// if is OCL revelant
if (StringContainsArray(test, Brest_Oceanic_Points)) {
// Display OCL flag
if (HasOCL(FlightPlan.GetCallsign())) {
// Check if level change required
int ocl_level = GetOCLLevel(FlightPlan.GetCallsign());
int cfl = FlightPlan.GetControllerAssignedData().GetClearedAltitude();
if (cfl == 0)
cfl = FlightPlan.GetControllerAssignedData().GetFinalAltitude();
if (cfl != ocl_level && ocl_level != 0) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
string item = "LCHG";
item += std::to_string(ocl_level / 1000);
strcpy_s(sItemString, 16, item.c_str());
}
}
// If there is no OCL and exit of sector is within 45mins and the flight is headed to the Americas (ICAOs starting with KCPSTMN, and SPEM) we display an alert
else if (startsWith("K", destination) || startsWith("C", destination) ||
startsWith("P", destination) || startsWith("T", destination) ||
startsWith("S", destination) || startsWith("M", destination) ||
startsWith("N", destination) || startsWith("LFVP", destination) || startsWith("LFVM", destination)) {
int minutes = 99;
for (int i = FlightPlan.GetExtractedRoute().GetPointsCalculatedIndex(); i < FlightPlan.GetExtractedRoute().GetPointsNumber(); i++) {
if (StringContainsArray(FlightPlan.GetExtractedRoute().GetPointName(i), Brest_Oceanic_Points)) {
minutes = FlightPlan.GetExtractedRoute().GetPointDistanceInMinutes(i);
break;
}
}
if (minutes <= 30) {
*pColorCode = EuroScopePlugIn::TAG_COLOR_RGB_DEFINED;
auto element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "intention_code_departure");
if (minutes < 15)
element_colour = toml::find<std::vector<int>>(CoFranceConfig, "colours", "sep_warning");
*pRGB = RGB(element_colour[0], element_colour[1], element_colour[2]);
strcpy_s(sItemString, 16, "OCL");
}
}
}
else {
strcpy_s(sItemString, 16, "");
}
}
if (ItemCode == CoFranceTags::STAND) {
if (!FlightPlan.IsValid())
return;
strcpy_s(sItemString, 16, "INOP");
}
}
void CoFrancePlugIn::OnTimer(int Counter)
{
if (RawOCLData.valid() && RawOCLData.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
string d = RawOCLData.get();
try {
SharedData::OCLData = nlohmann::json::parse(d);
}
catch (std::exception &exc) {
}
}
Blink = !Blink;
// STCA gets refreshed every 3 seconds
if (Counter % 3 == 0 && !performanceMode)
Stca->OnRefresh(this);
// Every 30 seconds poll OCL data
if (Counter % 30 == 0) {
if (ControllerMyself().IsValid() && ControllerMyself().IsController()) {
if (SharedData::OCLEnabled) {
// Don't start a new OCL fetch if the previous one is still in-flight.
if (RawOCLData.valid() &&
RawOCLData.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
DisplayUserMessage("Message", "CoFrance PlugIn", string("Skipping OCL data refresh, previous query still pending ").c_str(), false, false, false, false, false);
return;
}
RawOCLData = async(launch::async, &CoFrancePlugIn::LoadOCLData, this);
}
}
}
}
void CoFrancePlugIn::OnFunctionCall(int FunctionId, const char* sItemString, POINT Pt, RECT Area)
{
if (FunctionId == CoFranceTags::FUNCTION_CONFLICT_POPUP) {
SetASELAircraft(FlightPlanSelect(sItemString));
OpenPopupList(Area, "Conflict Group", 1);
AddPopupListElement(CoFranceCharacters::Moon.c_str(), "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP);
AddPopupListElement(CoFranceCharacters::Star.c_str(), "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP);
AddPopupListElement(CoFranceCharacters::Losange.c_str(), "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP);
AddPopupListElement("Remove", "", CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP, false, 2, false, true);
}
if (FunctionId == CoFranceTags::FUNCTION_HANDLE_CONFLICT_GROUP) {
if (ConflictGroups.find(FlightPlanSelectASEL().GetCallsign()) != ConflictGroups.end() && strcmp(sItemString, "Remove") == 0)
ConflictGroups.erase(FlightPlanSelectASEL().GetCallsign());
else if (strcmp(sItemString, "Remove") != 0)
ConflictGroups[FlightPlanSelectASEL().GetCallsign()] = sItemString;
}
if (FunctionId == CoFranceTags::FUNCTION_OCL_TP) {
CFlightPlan fp = FlightPlanSelectASEL();
auto t = fp.GetCallsign();
if (!fp.IsValid())
return;
SharedData::OCL_Tooltip_timer = std::chrono::system_clock::now();
if (HasOCL(fp.GetCallsign())) {
SharedData::OCL_Tooltip_string = GetFullOCL(fp.GetCallsign());
SharedData::OCL_Tooltip_pt = Pt;
}
}
}
void CoFrancePlugIn::LoadConfigFile(bool fromWeb)
{
DisplayUserMessage("Message", "CoFrance PlugIn", "Reading config file...", false, false, false, false, false);
try {
if (fromWeb) {
httplib::Client cli(CONFIG_ONLINE_URL_BASE);
if (auto res = cli.Get(CONFIG_ONLINE_URL_PATH)) {
if (res->status == 200) {
std::istringstream is(res->body, std::ios_base::binary | std::ios_base::in);
CoFranceConfig = toml::parse(is, "std::string");
}
else
fromWeb = false;
}
else
fromWeb = false;
cli.stop();
if (!fromWeb)
DisplayUserMessage("Message", "CoFrance PlugIn", "Error loading web config, reverting to local file!", false, false, false, false, false);
}
if (!fromWeb) {
CoFranceConfig = toml::parse(DllPath + "\\CoFrance.toml");
}
CanLoadRadarScreen = true;
DisplayUserMessage("Message", "CoFrance PlugIn", "Config file loaded!", false, false, false, false, false);
}
catch (const std::exception& exc) {
CanLoadRadarScreen = false;
DisplayUserMessage("Message", "CoFrance PlugIn", string("Error reading config file " + string(exc.what())).c_str(), false, false, false, false, false);
}
}
string CoFrancePlugIn::LoadOCLData()
{
try {
httplib::Client cli("https://nattrak.vatsim.net");
cli.set_connection_timeout(0, 500000);
cli.set_read_timeout(0, 500000);
cli.set_write_timeout(0, 500000);
if (auto res = cli.Get("/api/plugins")) {
if (res->status == 200) {
cli.stop();
return res->body;
}
else {
cli.stop();
DisplayUserMessage("Message", "CoFrance PlugIn", string("Error fetching OCL data, server returned HTTP code: " + to_string(res->status) + " body: " + res->body).c_str(), false, false, false, false, false);
return "[]";
}
}
cli.stop();
}
catch (const std::exception& exc) {
DisplayUserMessage("Message", "CoFrance PlugIn", string("Error fetching OCL data: " + string(exc.what())).c_str(), false, false, false, false, false);
return "[]";
}
return "[]";
//return "[ { \"callsign\": \"BER1PE\", \"status\": \"CLEARED\", \"nat\": \"A\", \"fix\": \"MALOT\", \"level\": \"320\", \"mach\": \"0.89\", \"estimating_time\": \"1921\", \"clearance_issued\": \"2021-03-26 00:21:19\", \"extra_info\": \"CROSS MALOT NOT BEFORE 1925\" }, { \"callsign\":\"ADB3908\", \"status\":\"PENDING\", \"nat\":\"RR\", \"fix\":\"PORTI\", \"level\": \"350\", \"mach\": \"0.82\", \"estimating_time\":\"18:41\", \"clearance_issued\":null, \"extra_info\":null } ]";
}