Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,19 @@ CONFIGURE_FILE(
${CMAKE_BINARY_DIR}/Version.h
)

# No warnings for external libraries (EuroScopePlugIn.h)
INCLUDE_DIRECTORIES(
SYSTEM ${CMAKE_SOURCE_DIR}/external/include
)

INCLUDE_DIRECTORIES(
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src/
${CMAKE_SOURCE_DIR}/external/include
${CMAKE_SOURCE_DIR}
)

ADD_DEFINITIONS(
-D_CRT_SECURE_NO_WARNINGS
-DSQLITE_THREADSAFE=0
-DSQLITE_DEFAULT_FILE_FORMAT=4
-DSQLITE_DEFAULT_SYNCHRONOUS=0
-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=0
-DSQLITE_WIN32_MALLOC
-DSQLITE_THREADSAFE=0
-DWIN32_LEAN_AND_MEAN
)

Expand All @@ -74,11 +72,8 @@ SET(SOURCE_FILES
src/core/DataManager.h
src/core/Server.cpp
src/core/Server.h
src/log/Logger.cpp
src/log/Logger.h
src/log/sqlite3.c
src/log/sqlite3.h
src/log/sqlite3ext.h
src/log/SpdLogger.cpp
src/log/SpdLogger.h
src/vACDM.cpp
src/vACDM.h
src/main.cpp
Expand All @@ -88,14 +83,16 @@ SET(SOURCE_FILES
FIND_PACKAGE(OpenSSL CONFIG REQUIRED)
FIND_PACKAGE(httplib CONFIG REQUIRED)
FIND_PACKAGE(nlohmann_json CONFIG REQUIRED)
FIND_PACKAGE(spdlog CONFIG REQUIRED)

ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCE_FILES})

TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/external/lib/EuroScopePlugInDLL.lib
${CMAKE_SOURCE_DIR}/external/lib/EuroScopePlugInDLL.lib
OpenSSL::SSL OpenSSL::Crypto
httplib::httplib
nlohmann_json::nlohmann_json
spdlog::spdlog_header_only
crypt32.lib ws2_32.lib Shlwapi.lib
)

Expand Down
2 changes: 1 addition & 1 deletion src/config/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool ConfigParser::parse(const std::string &filename, PluginConfig &config) {
parsed = this->parseColor(values[1], config.debug, lineOffset);
} else {
this->m_errorLine = lineOffset;
this->m_errorMessage = "Unknown file entry: " + value[0];
this->m_errorMessage = "Unknown file entry: " + values[0];
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/core/CompileCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "core/DataManager.h"
#include "core/Server.h"
#include "log/Logger.h"
#include "log/SpdLogger.h"
#include "utils/Number.h"
#include "utils/String.h"
#include "vACDM.h"
Expand Down Expand Up @@ -53,7 +53,7 @@ bool vACDM::OnCompileCommand(const char *sCommandLine) {
DisplayMessage("All pilot data cleared");

DisplayMessage("Executing vACDM as the MASTER");
Logger::instance().log(Logger::LogSender::vACDM, "Switched to MASTER", Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::vACDM, "Switched to MASTER", SpdLogger::LogLevel::Info);
com::Server::instance().setMaster(true);

return true;
Expand All @@ -64,7 +64,7 @@ bool vACDM::OnCompileCommand(const char *sCommandLine) {
return true;
} else if (std::string::npos != command.find("SLAVE")) {
DisplayMessage("Executing vACDM as the SLAVE");
Logger::instance().log(Logger::LogSender::vACDM, "Switched to SLAVE", Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::vACDM, "Switched to SLAVE", SpdLogger::LogLevel::Info);
com::Server::instance().setMaster(false);

// Clear all pilot data when switching to slave mode
Expand All @@ -77,9 +77,9 @@ bool vACDM::OnCompileCommand(const char *sCommandLine) {
return true;
} else if (std::string::npos != command.find("LOG")) {
if (std::string::npos != command.find("LOGLEVEL")) {
DisplayMessage(Logger::instance().handleLogLevelCommand(command));
DisplayMessage(SpdLogger::handleLogLevelCommand(command));
} else {
DisplayMessage(Logger::instance().handleLogCommand(command));
DisplayMessage(SpdLogger::handleLogCommand(command));
}
return true;
} else if (std::string::npos != command.find("UPDATERATE")) {
Expand All @@ -88,8 +88,8 @@ bool vACDM::OnCompileCommand(const char *sCommandLine) {
DisplayMessage("Usage: .vacdm UPDATERATE value");
return true;
}
if (false == isNumber(elements[2]) ||
std::stoi(elements[2]) < minUpdateCycleSeconds && std::stoi(elements[2]) > maxUpdateCycleSeconds) {
if ((false == isNumber(elements[2])) ||
(std::stoi(elements[2]) < minUpdateCycleSeconds || std::stoi(elements[2]) > maxUpdateCycleSeconds)) {
DisplayMessage("Usage: .vacdm UPDATERATE value");
DisplayMessage("Value must be number between " + std::to_string(minUpdateCycleSeconds) + " and " +
std::to_string(maxUpdateCycleSeconds));
Expand Down
57 changes: 26 additions & 31 deletions src/core/DataManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "DataManager.h"

#include "core/Server.h"
#include "log/Logger.h"
#include "log/SpdLogger.h"
#include "utils/Date.h"

using namespace vacdm::com;
Expand Down Expand Up @@ -47,13 +47,11 @@ void DataManager::clearAllPilotData() {

// Also clear any pending updates
std::lock_guard guardUpdates(this->m_euroscopeUpdatesLock);
this->m_euroscopeFlightplanUpdates.clear();

// Clear any pending messages
this->m_euroscopeFlightplanUpdates.clear(); // Clear any pending messages
std::lock_guard guardMessages(this->m_asyncMessagesLock);
this->m_asynchronousMessages.clear();

Logger::instance().log(Logger::LogSender::DataManager, "All pilot data cleared", Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager, "All pilot data cleared", SpdLogger::LogLevel::Info);
}

std::string DataManager::setUpdateCycleSeconds(const int newUpdateCycleSeconds) {
Expand Down Expand Up @@ -186,11 +184,10 @@ void DataManager::processAsynchronousMessages(std::map<std::string, std::array<t
default:
break;
}

Logger::instance().log(Logger::LogSender::DataManager,
"Sending " + messageType + " update: " + callsign + " - " +
utils::Date::timestampToIsoString(message.value),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager,
"Sending " + messageType + " update: " + callsign + " - " +
utils::Date::timestampToIsoString(message.value),
SpdLogger::LogLevel::Info);

break;
}
Expand Down Expand Up @@ -387,10 +384,9 @@ void DataManager::consolidateWithBackend(std::map<std::string, std::array<types:
bool removeFlight = pilot->second[ServerData].inactive == true;
for (auto updateIt = backendPilots.begin(); updateIt != backendPilots.end(); ++updateIt) {
if (updateIt->callsign == pilot->second[EuroscopeData].callsign) {
Logger::instance().log(
Logger::LogSender::DataManager,
"Updating " + pilot->second[EuroscopeData].callsign + " with" + updateIt->callsign,
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager,
"Updating " + pilot->second[EuroscopeData].callsign + " with " + updateIt->callsign,
SpdLogger::LogLevel::Info);
pilot->second[ServerData] = *updateIt;
DataManager::consolidateData(pilot->second);
removeFlight = false;
Expand Down Expand Up @@ -439,14 +435,13 @@ void DataManager::consolidateData(std::array<types::Pilot, 3>& pilot) {
pilot[ConsolidatedData].destination = pilot[EuroscopeData].destination;
pilot[ConsolidatedData].runway = pilot[EuroscopeData].runway;
pilot[ConsolidatedData].sid = pilot[EuroscopeData].sid;

logging::Logger::instance().log(Logger::LogSender::DataManager, "Consolidated " + pilot[ServerData].callsign,
logging::Logger::LogLevel::Info);
logging::SpdLogger::log(SpdLogger::LogSender::DataManager, "Consolidated " + pilot[ServerData].callsign,
SpdLogger::LogLevel::Info);
} else {
logging::Logger::instance().log(Logger::LogSender::DataManager,
"Callsign mismatch during consolidation: " + pilot[EuroscopeData].callsign +
", " + pilot[ServerData].callsign,
logging::Logger::LogLevel::Critical);
logging::SpdLogger::log(SpdLogger::LogSender::DataManager,
"Callsign mismatch during consolidation: " + pilot[EuroscopeData].callsign + ", " +
pilot[ServerData].callsign,
SpdLogger::LogLevel::Critical);
}
}

Expand All @@ -467,8 +462,8 @@ void DataManager::processEuroScopeUpdates(std::map<std::string, std::array<types
// find pilot in list
for (auto& pair : pilots) {
if (pilot.callsign == pair.first) {
Logger::instance().log(Logger::LogSender::DataManager, "Updated data of " + pilot.callsign,
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager, "Updated data of " + pilot.callsign,
SpdLogger::LogLevel::Info);

pair.second[EuroscopeData] = pilot;
found = true;
Expand All @@ -477,7 +472,7 @@ void DataManager::processEuroScopeUpdates(std::map<std::string, std::array<types
}

if (false == found) {
Logger::instance().log(Logger::LogSender::DataManager, "Added " + pilot.callsign, Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager, "Added " + pilot.callsign, SpdLogger::LogLevel::Info);
pilots.insert({pilot.callsign, {pilot, pilot, types::Pilot()}});
}
}
Expand Down Expand Up @@ -509,19 +504,19 @@ void DataManager::consolidateFlightplanUpdates(std::list<EuroscopeFlightplanUpda
if (currentUpdate.timeIssued > it->timeIssued) {
// Update with the newer data
*it = currentUpdate;
Logger::instance().log(Logger::LogSender::DataManager,
"Updated: " + std::string(currentUpdate.data.callsign), Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager,
"Updated: " + std::string(currentUpdate.data.callsign), SpdLogger::LogLevel::Info);
} else {
// Existing data is already newer, no update needed
Logger::instance().log(Logger::LogSender::DataManager,
"Skipped old update for: " + std::string(currentUpdate.data.callsign),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager,
"Skipped old update for: " + std::string(currentUpdate.data.callsign),
SpdLogger::LogLevel::Info);
}
} else {
// Flight plan with the callsign doesn't exist, add it to the result list
resultList.push_back(currentUpdate);
Logger::instance().log(Logger::LogSender::DataManager,
"Update added: " + std::string(currentUpdate.data.callsign), Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::DataManager,
"Update added: " + std::string(currentUpdate.data.callsign), SpdLogger::LogLevel::Info);
}
}

Expand Down
66 changes: 29 additions & 37 deletions src/core/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <numeric>

#include "Version.h"
#include "log/Logger.h"
#include "log/SpdLogger.h"
#include "utils/Date.h"

using namespace vacdm;
Expand Down Expand Up @@ -73,17 +73,16 @@ bool Server::checkWebApi() {
// Send GET request
auto result = m_client->Get(url);
if (!result || result->status != 200) {
Logger::instance().log(
Logger::LogSender::Server,
"Failed to connect to API: " + (result ? std::to_string(result->status) : "connection error"),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server,
"Failed to connect to API: " + (result ? std::to_string(result->status) : "connection error"),
SpdLogger::LogLevel::Info);
this->m_apiIsValid = false;
return m_apiIsValid;
}

std::string response = result->body;
Logger::instance().log(Logger::LogSender::Server, "Received API-version-message: " + response,
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, "Received API-version-message: " + response,
SpdLogger::LogLevel::Info);
try {
auto root = nlohmann::json::parse(response);
if (PLUGIN_VERSION_MAJOR != root["major"].get<int>()) {
Expand All @@ -93,8 +92,8 @@ bool Server::checkWebApi() {
this->m_apiIsValid = true;
}
} catch (const std::exception& e) {
Logger::instance().log(Logger::LogSender::Server, "Failed to parse response JSON: " + std::string(e.what()),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, "Failed to parse response JSON: " + std::string(e.what()),
SpdLogger::LogLevel::Info);
this->m_errorCode = "Invalid backend-version response: " + response;
this->m_apiIsValid = false;
}
Expand All @@ -113,9 +112,8 @@ Server::ServerConfiguration Server::getServerConfig() {

if (result && result->status == 200) {
nlohmann::json root;

Logger::instance().log(Logger::LogSender::Server, "Received configuration: " + result->body,
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, "Received configuration: " + result->body,
SpdLogger::LogLevel::Info);

try {
root = nlohmann::json::parse(result->body);
Expand All @@ -125,9 +123,8 @@ Server::ServerConfiguration Server::getServerConfig() {
config.allowMasterAsObserver = root["allowObsMaster"].get<bool>();
return config;
} catch (const std::exception& e) {
Logger::instance().log(Logger::LogSender::Server,
"Failed to parse response JSON: " + std::string(e.what()),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, "Failed to parse response JSON: " + std::string(e.what()),
SpdLogger::LogLevel::Info);
}
}
}
Expand All @@ -150,7 +147,7 @@ std::list<types::Pilot> Server::getPilots(const std::list<std::string> airports)
[](const std::string& a, const std::string& b) { return a + "," + b; });
}

Logger::instance().log(Logger::LogSender::Server, url, Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, url, SpdLogger::LogLevel::Info);

auto result = m_client->Get(url);
if (result && result->status == 200) {
Expand Down Expand Up @@ -209,13 +206,12 @@ std::list<types::Pilot> Server::getPilots(const std::list<std::string> airports)
// event booking data
pilots.back().hasBooking = pilot["hasBooking"].get<bool>();
}
Logger::instance().log(Logger::LogSender::Server, "Pilots size: " + std::to_string(pilots.size()),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, "Pilots size: " + std::to_string(pilots.size()),
SpdLogger::LogLevel::Info);
return pilots;

} catch (const std::exception& e) {
Logger::instance().log(Logger::LogSender::Server, "Failed to parse response JSON: " + std::string(e.what()),
Logger::LogLevel::Info);
SpdLogger::log(SpdLogger::LogSender::Server, "Failed to parse response JSON: " + std::string(e.what()),
SpdLogger::LogLevel::Info);
}
}
return {};
Expand All @@ -225,21 +221,19 @@ void Server::sendPostMessage(const std::string& endpointUrl, const nlohmann::jso
if (this->m_apiIsChecked == false || this->m_apiIsValid == false || this->m_clientIsMaster == false) return;

const auto message = root.dump();

if (root.contains("callsign")) {
Logger::instance().log(Logger::LogSender::Server,
"Posting " + root["callsign"].get<std::string>() + " with message: " + message,
Logger::LogLevel::Debug);
SpdLogger::log(SpdLogger::LogSender::Server,
"Posting " + root["callsign"].get<std::string>() + " with message: " + message,
SpdLogger::LogLevel::Debug);
}

std::lock_guard guard(m_clientMutex);
if (m_client) {
auto result = m_client->Post(endpointUrl, message, "application/json");

if (result && root.contains("callsign")) {
Logger::instance().log(Logger::LogSender::Server,
"Posted " + root["callsign"].get<std::string>() + " response: " + result->body,
Logger::LogLevel::Debug);
SpdLogger::log(SpdLogger::LogSender::Server,
"Posted " + root["callsign"].get<std::string>() + " response: " + result->body,
SpdLogger::LogLevel::Debug);
}
}
}
Expand All @@ -248,21 +242,19 @@ void Server::sendPatchMessage(const std::string& endpointUrl, const nlohmann::js
if (this->m_apiIsChecked == false || this->m_apiIsValid == false || this->m_clientIsMaster == false) return;

const auto message = root.dump();

if (root.contains("callsign")) {
Logger::instance().log(Logger::LogSender::Server,
"Patching " + root["callsign"].get<std::string>() + " with message: " + message,
Logger::LogLevel::Debug);
SpdLogger::log(SpdLogger::LogSender::Server,
"Patching " + root["callsign"].get<std::string>() + " with message: " + message,
SpdLogger::LogLevel::Debug);
}

std::lock_guard guard(m_clientMutex);
if (m_client) {
auto result = m_client->Patch(endpointUrl, message, "application/json");

if (result && root.contains("callsign")) {
Logger::instance().log(Logger::LogSender::Server,
"Patched " + root["callsign"].get<std::string>() + " response: " + result->body,
Logger::LogLevel::Debug);
SpdLogger::log(SpdLogger::LogSender::Server,
"Patched " + root["callsign"].get<std::string>() + " response: " + result->body,
SpdLogger::LogLevel::Debug);
}
}
}
Expand Down
Loading