Make sure there are no "illegal" characters in text messages

This commit is contained in:
Klaus Basan
2018-09-27 03:58:47 +02:00
parent 09f6738363
commit 85f7a37c8b
4 changed files with 23 additions and 22 deletions

View File

@@ -322,7 +322,7 @@ namespace BlackCore
}
else
{
CFrequency radioFrequency = CComSystem::parseComFrequency(receiver, CPqString::SeparatorsBestGuess);
const CFrequency radioFrequency = CComSystem::parseComFrequency(receiver, CPqString::SeparatorsBestGuess);
if (!radioFrequency.isNull())
{
if (CComSystem::isValidCivilAviationFrequency(radioFrequency))

View File

@@ -460,7 +460,7 @@ namespace BlackCore
updateOwnCallsign(callsign);
}
void CNetworkVatlib::presetIcaoCodes(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft)
void CNetworkVatlib::presetIcaoCodes(const CSimulatedAircraft &ownAircraft)
{
Q_ASSERT_X(isDisconnected(), Q_FUNC_INFO, "Can't change ICAO codes while still connected");
m_ownAircraftIcaoCode = ownAircraft.getAircraftIcaoCode();
@@ -530,7 +530,7 @@ namespace BlackCore
this->clearState();
}
void CNetworkVatlib::sendTextMessages(const BlackMisc::Network::CTextMessageList &messages)
void CNetworkVatlib::sendTextMessages(const CTextMessageList &messages)
{
Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected");
@@ -554,7 +554,7 @@ namespace BlackCore
// currently I send individual messages
freqsVec.clear();
freqsVec.push_back(message.getFrequency().valueInteger(CFrequencyUnit::kHz()));
Vat_SendRadioMessage(m_net.data(), freqsVec.data(), static_cast<unsigned int>(freqsVec.size()), toFSD(message.getMessage()));
Vat_SendRadioMessage(m_net.data(), freqsVec.data(), static_cast<unsigned int>(freqsVec.size()), toFSDnoColon(message.getMessage()));
emit this->textMessageSent(message);
}
}

View File

@@ -87,7 +87,7 @@ namespace BlackMisc
{
if (textMessage.isEmpty()) { return false; }
if (!this->canBeAppended(textMessage)) { return false; }
m_message += " " + textMessage.getMessage();
m_message += QStringLiteral(" ") % textMessage.getMessage();
return true;
}
@@ -98,7 +98,7 @@ namespace BlackMisc
return m_frequency.valueRoundedWithUnit(CFrequencyUnit::MHz(), 3);
}
bool CTextMessage::isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const
bool CTextMessage::isSendToFrequency(const CFrequency &frequency) const
{
if (!this->isRadioMessage()) { return false; }
return m_frequency == frequency;
@@ -106,15 +106,20 @@ namespace BlackMisc
bool CTextMessage::isSendToUnicom() const
{
return this->isSendToFrequency(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyUnicom());
return this->isSendToFrequency(CPhysicalQuantitiesConstants::FrequencyUnicom());
}
bool CTextMessage::hasValidRecipient() const
{
if (!m_recipientCallsign.isEmpty()) return true;
if (!m_recipientCallsign.isEmpty()) { return true; }
return CComSystem::isValidCivilAviationFrequency(m_frequency);
}
void CTextMessage::setMessage(const QString &message)
{
m_message = asciiOnlyString(simplifyAccents(message.simplified().trimmed()));
}
bool CTextMessage::isRadioMessage() const
{
return (CComSystem::isValidCivilAviationFrequency(m_frequency));
@@ -122,7 +127,7 @@ namespace BlackMisc
bool CTextMessage::isServerMessage() const
{
if (!this->isPrivateMessage()) return false;
if (!this->isPrivateMessage()) { return false; }
const CCallsign cs = this->getSenderCallsign();
return (cs.asString().startsWith("SERVER", Qt::CaseInsensitive));
}
@@ -134,8 +139,7 @@ namespace BlackMisc
{
if (!m_senderCallsign.isEmpty())
{
if (!s.isEmpty()) s.append(separator);
s.append(m_senderCallsign.getStringAsSet());
if (!s.isEmpty()) { s += separator % m_senderCallsign.getStringAsSet(); }
}
}
@@ -143,22 +147,19 @@ namespace BlackMisc
{
if (!m_recipientCallsign.isEmpty())
{
if (!s.isEmpty()) s.append(separator);
s.append(m_recipientCallsign.getStringAsSet());
if (!s.isEmpty()) { s += separator % m_recipientCallsign.getStringAsSet(); }
}
else
{
if (CComSystem::isValidCivilAviationFrequency(m_frequency))
{
if (!s.isEmpty()) s.append(separator);
s.append(m_frequency.valueRoundedWithUnit(3, true));
if (!s.isEmpty()) { s += separator % m_frequency.valueRoundedWithUnit(3, true); }
}
}
} // to
if (m_message.isEmpty()) return s;
if (!s.isEmpty()) s.append(separator);
s.append(m_message);
if (m_message.isEmpty()) { return s; }
if (!s.isEmpty()) { s += separator % m_message; }
return s;
}
@@ -181,9 +182,9 @@ namespace BlackMisc
bool CTextMessage::isSelcalMessage() const
{
// some first level checks, before really parsing the message
if (this->isEmpty()) return false;
if (this->isPrivateMessage()) return false;
if (m_message.length() > 15 || m_message.length() < 10) return false; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
if (this->isEmpty()) { return false; }
if (this->isPrivateMessage()) { return false; }
if (m_message.length() > 15 || m_message.length() < 10) { return false; } // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
return this->getSelcalCode().length() == 4;
}

View File

@@ -89,7 +89,7 @@ namespace BlackMisc
bool isEmpty() const { return m_message.isEmpty(); }
//! Set message
void setMessage(const QString &message) { m_message = message.trimmed().simplified(); }
void setMessage(const QString &message);
//! Get frequency
const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }