Ref T761, partner callsign message relay (swift with co-pilot)

* handle server error messages correctly as "error"
* (relayed) sender can be ATC or aircraft
* relay private messages correctly
This commit is contained in:
Klaus Basan
2019-11-20 23:28:07 +01:00
committed by Mat Sutcliffe
parent 22d8b52fe8
commit f07ca09424
7 changed files with 45 additions and 29 deletions

View File

@@ -76,10 +76,10 @@ namespace BlackCore
this); // thread owner
m_fsdClient->start(); // FSD thread
connect(m_fsdClient, &CFSDClient::connectionStatusChanged, this, &CContextNetwork::onFsdConnectionStatusChanged, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::killRequestReceived, this, &CContextNetwork::kicked, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::textMessagesReceived, this, &CContextNetwork::textMessagesReceived, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::textMessageSent, this, &CContextNetwork::textMessageSent, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::severeNetworkError, this, &CContextNetwork::severeNetworkError, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::killRequestReceived, this, &CContextNetwork::kicked, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::textMessagesReceived, this, &CContextNetwork::onTextMessagesReceived, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::textMessageSent, this, &CContextNetwork::onTextMessageSent, Qt::QueuedConnection);
connect(m_fsdClient, &CFSDClient::severeNetworkError, this, &CContextNetwork::severeNetworkError, Qt::QueuedConnection);
// 2. Update timer for data (network data such as frequency)
// we use 2 timers so we can query at different times (not too many queirs at once)
@@ -703,7 +703,7 @@ namespace BlackCore
void CContextNetwork::onTextMessagesReceived(const CTextMessageList &messages)
{
const CTextMessageList textMessages = messages.withRelayedToPrivateMessages();
emit this->textMessagesReceived(textMessages);
emit this->textMessagesReceived(textMessages); // relayed messaged "now look like PMs"
if (textMessages.containsPrivateMessages())
{
@@ -714,10 +714,9 @@ namespace BlackCore
}
// part to send to partner "forward"
if (m_fsdClient && !m_fsdClient->getPresetPartnerCallsign().isEmpty())
const CCallsign partnerCallsign = m_fsdClient ? m_fsdClient->getPresetPartnerCallsign() : CCallsign();
if (!partnerCallsign.isEmpty())
{
const CCallsign partnerCallsign = m_fsdClient->getPresetPartnerCallsign();
// IMPORTANT: use messages AND NOT textMessages here, exclude messages from partner to avoid infinite roundtrips
CTextMessageList relayedMessages;
const CTextMessageList privateMessages = messages.getPrivateMessages().withRemovedPrivateMessagesFromCallsign(partnerCallsign);
@@ -738,6 +737,14 @@ namespace BlackCore
}
}
void CContextNetwork::onTextMessageSent(const CTextMessage &message)
{
if (message.isEmpty()) { return; }
if (message.isRelayedMessage()) { return; }
emit this->textMessageSent(message);
}
const CSimulatedAircraft CContextNetwork::ownAircraft() const
{
Q_ASSERT(this->getRuntime());

View File

@@ -316,9 +316,12 @@ namespace BlackCore
//! Update METAR collection
void updateMetars(const BlackMisc::Weather::CMetarList &metars);
//! Check if a supervisor message was received, message has to be relayed ...
//! Check when a message was received, if the message has to be relayed, is a supervisor message ...
void onTextMessagesReceived(const BlackMisc::Network::CTextMessageList &messages);
//! Text message has been sent
void onTextMessageSent(const BlackMisc::Network::CTextMessage &message);
//! An ATIS has been received
void onChangedAtisReceived(const BlackMisc::Aviation::CCallsign &callsign);

View File

@@ -1285,28 +1285,28 @@ namespace BlackCore
const ServerError serverError = ServerError::fromTokens(tokens);
switch (serverError.m_errorNumber)
{
case ServerErrorCode::CallsignInUse: CLogMessage(this).error(u"The requested callsign is already taken"); break;
case ServerErrorCode::InvalidCallsign: CLogMessage(this).error(u"The requested callsign is not valid"); break;
case ServerErrorCode::InvalidCidPassword: CLogMessage(this).error(u"Wrong user ID or password, inactive account"); break;
case ServerErrorCode::InvalidRevision: CLogMessage(this).error(u"This server does not support our protocol version"); break;
case ServerErrorCode::ServerFull: CLogMessage(this).error(u"The server is full"); break;
case ServerErrorCode::CidSuspended: CLogMessage(this).error(u"Your user account is suspended"); break;
case ServerErrorCode::RatingTooLow: CLogMessage(this).error(u"You are not authorized to use the requested rating"); break;
case ServerErrorCode::InvalidClient: CLogMessage(this).error(u"This software is not authorized for use on this network"); break;
case ServerErrorCode::CallsignInUse: CLogMessage(this).error(u"The requested callsign is already taken"); break;
case ServerErrorCode::InvalidCallsign: CLogMessage(this).error(u"The requested callsign is not valid"); break;
case ServerErrorCode::InvalidCidPassword: CLogMessage(this).error(u"Wrong user ID or password, inactive account"); break;
case ServerErrorCode::InvalidRevision: CLogMessage(this).error(u"This server does not support our protocol version"); break;
case ServerErrorCode::ServerFull: CLogMessage(this).error(u"The server is full"); break;
case ServerErrorCode::CidSuspended: CLogMessage(this).error(u"Your user account is suspended"); break;
case ServerErrorCode::RatingTooLow: CLogMessage(this).error(u"You are not authorized to use the requested rating"); break;
case ServerErrorCode::InvalidClient: CLogMessage(this).error(u"This software is not authorized for use on this network"); break;
case ServerErrorCode::RequestedLevelTooHigh: CLogMessage(this).error(u"You are not authorized to use the requested pilot rating"); break;
case ServerErrorCode::NoError: CLogMessage(this).info(u"OK"); break;
case ServerErrorCode::SyntaxError: CLogMessage(this).info(u"Malformed packet: Syntax error: %1") << serverError.m_causingParameter; break;
case ServerErrorCode::InvalidSrcCallsign: CLogMessage(this).info(u"FSD message was using an invalid callsign: %1 (%2)") << serverError.m_causingParameter << serverError.m_description; break;
case ServerErrorCode::NoSuchCallsign: CLogMessage(this).info(u"FSD Server: no such callsign: %1 %2") << serverError.m_causingParameter << serverError.m_description; break;
case ServerErrorCode::NoFlightPlan: CLogMessage(this).info(u"FSD Server: no flight plan"); break;
case ServerErrorCode::NoWeatherProfile: CLogMessage(this).info(u"FSD Server: requested weather profile does not exist"); break;
case ServerErrorCode::NoError: CLogMessage(this).info(u"OK"); break;
case ServerErrorCode::SyntaxError: CLogMessage(this).error(u"Malformed packet: Syntax error: %1") << serverError.getCausingParameter(); break;
case ServerErrorCode::InvalidSrcCallsign: CLogMessage(this).info(u"FSD message was using an invalid callsign: %1 (%2)") << serverError.getCausingParameter() << serverError.getDescription(); break;
case ServerErrorCode::NoSuchCallsign: CLogMessage(this).info(u"FSD Server: no such callsign: %1 %2") << serverError.getCausingParameter() << serverError.getDescription(); break;
case ServerErrorCode::NoFlightPlan: CLogMessage(this).info(u"FSD Server: no flight plan"); break;
case ServerErrorCode::NoWeatherProfile: CLogMessage(this).info(u"FSD Server: requested weather profile does not exist"); break;
// we have no idea what these mean
case ServerErrorCode::AlreadyRegistered: CLogMessage(this).info(u"Server says already registered: %1") << serverError.m_description; break;
case ServerErrorCode::InvalidCtrl: CLogMessage(this).info(u"Server invalid control: %1") << serverError.m_description; break;
case ServerErrorCode::Unknown: CLogMessage(this).info(u"Server sent unknown error code: %1 (%2)") << serverError.m_causingParameter << serverError.m_description; break;
case ServerErrorCode::AuthTimeout: CLogMessage(this).error(u"Client did not authenticate in time"); break;
case ServerErrorCode::AlreadyRegistered: CLogMessage(this).warning(u"Server says already registered: %1") << serverError.getDescription(); break;
case ServerErrorCode::InvalidCtrl: CLogMessage(this).warning(u"Server invalid control: %1") << serverError.getDescription(); break;
case ServerErrorCode::Unknown: CLogMessage(this).warning(u"Server sent unknown error code: %1 (%2)") << serverError.getCausingParameter() << serverError.getDescription(); break;
case ServerErrorCode::AuthTimeout: CLogMessage(this).warning(u"Client did not authenticate in time"); break;
}
if (serverError.isFatalError()) { disconnectFromServer(); }
}

View File

@@ -63,7 +63,7 @@ namespace BlackCore
{
BlackMisc::CLogMessage(static_cast<ServerError *>(nullptr)).debug(u"Wrong number of arguments.");
return {};
};
}
return ServerError(tokens[0], tokens[1], static_cast<ServerErrorCode>(tokens[2].toInt()), tokens[3], tokens[4]);
}
}

View File

@@ -37,6 +37,11 @@ namespace BlackCore
//! PDU identifier
static QString pdu() { return "$ER"; }
//! Getter @{
const QString &getCausingParameter() const { static const QString n("no details"); return m_causingParameter.isEmpty() ? n : m_causingParameter; }
const QString &getDescription() const { static const QString n("no description"); return m_description.isEmpty() ? n : m_description; }
//! @}
//! Properties @{
ServerErrorCode m_errorNumber;
QString m_causingParameter;

View File

@@ -97,7 +97,7 @@ namespace BlackMisc
if (index < CTextMessage::swiftRelayMessage().length()) { return false; }
if (m_message.length() <= index + 1) { return false; } // no next line
const QString originalSender = m_message.left(index).remove(CTextMessage::swiftRelayMessage()).trimmed();
this->setSenderCallsign(CCallsign(originalSender, CCallsign::Aircraft));
this->setSenderCallsign(CCallsign(originalSender)); // sender can be aircraft or ATC
m_message = m_message.mid(index + 1);
return true;
}

View File

@@ -109,6 +109,7 @@ namespace BlackMisc
int c = 0;
for (CTextMessage &m : *this)
{
// Turn "relay" message into private message
if (m.relayedMessageToPrivateMessage()) { c++; }
}
return c;