Sending wallop message

This commit is contained in:
Klaus Basan
2018-10-04 16:54:31 +02:00
parent 7e47349b30
commit df4ef3f52d
5 changed files with 32 additions and 6 deletions

View File

@@ -280,7 +280,7 @@ namespace BlackCore
{ {
Q_UNUSED(originator;) Q_UNUSED(originator;)
if (commandLine.isEmpty()) { return false; } if (commandLine.isEmpty()) { return false; }
static const QStringList cmds({ ".msg", ".m", ".altos", ".altoffset", ".watchdog", ".reinit", ".reinitialize" }); static const QStringList cmds({ ".msg", ".m", ".altos", ".altoffset", ".wallop", ".watchdog", ".reinit", ".reinitialize" });
CSimpleCommandParser parser(cmds); CSimpleCommandParser parser(cmds);
parser.parse(commandLine); parser.parse(commandLine);
if (!parser.isKnownCommand()) { return false; } if (!parser.isKnownCommand()) { return false; }
@@ -401,6 +401,15 @@ namespace BlackCore
CLogMessage(this).info("Re-init %1 aircraft") << count; CLogMessage(this).info("Re-init %1 aircraft") << count;
} }
} }
else if (parser.matchesCommand(".wallop"))
{
if (parser.countParts() < 2) { return false; }
if (!m_network) { return false; }
if (!this->isConnected()) { return false; }
const QString wallopMsg = simplifyAccents(parser.part(1).simplified().trimmed());
m_network->sendWallopMessage(wallopMsg);
return true;
}
return false; return false;
} }

View File

@@ -209,6 +209,7 @@ namespace BlackCore
//! .altos .altoffset altitude offset for testing //! .altos .altoffset altitude offset for testing
//! .reinit .reinitialize re-initialize all aircraft //! .reinit .reinitialize re-initialize all aircraft
//! .watchdog on|off watchdog on/off //! .watchdog on|off watchdog on/off
//! .wallop message send wallop message
//! </pre> //! </pre>
//! @} //! @}
//! \copydoc IContextNetwork::parseCommandLine //! \copydoc IContextNetwork::parseCommandLine
@@ -223,6 +224,7 @@ namespace BlackCore
BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message text", "send text message"}); BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message text", "send text message"});
BlackMisc::CSimpleCommandParser::registerCommand({".altos callsign offsetvalue", "set altitude offset value (testing)"}); BlackMisc::CSimpleCommandParser::registerCommand({".altos callsign offsetvalue", "set altitude offset value (testing)"});
BlackMisc::CSimpleCommandParser::registerCommand({".watchdog on|off", "enable/disable network watchdog (testing)"}); BlackMisc::CSimpleCommandParser::registerCommand({".watchdog on|off", "enable/disable network watchdog (testing)"});
BlackMisc::CSimpleCommandParser::registerCommand({".wallop message", "send a wallop message"});
BlackMisc::CSimpleCommandParser::registerCommand({".reinit", "re-initialize all aircraft"}); BlackMisc::CSimpleCommandParser::registerCommand({".reinit", "re-initialize all aircraft"});
} }

View File

@@ -245,6 +245,12 @@ namespace BlackCore
*/ */
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) = 0; virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) = 0;
/*!
* Send a wallop message.
* \pre Network must be connected when calling this function.
*/
virtual void sendWallopMessage(const QString &message) = 0;
//! @} //! @}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
//! \name Custom packets //! \name Custom packets

View File

@@ -482,7 +482,7 @@ namespace BlackCore
if (!m_net) { initializeSession(); } if (!m_net) { initializeSession(); }
this->clearState(); this->clearState();
m_filterPasswordFromLogin = true; m_filterPasswordFromLogin = true;
QByteArray callsign = toFSD(m_loginMode == LoginAsObserver ? QByteArray callsign = toFSDnoColon(m_loginMode == LoginAsObserver ?
m_ownCallsign.getAsObserverCallsignString() : m_ownCallsign.getAsObserverCallsignString() :
m_ownCallsign.asString()); m_ownCallsign.asString());
QByteArray name; QByteArray name;
@@ -532,8 +532,8 @@ namespace BlackCore
void CNetworkVatlib::sendTextMessages(const CTextMessageList &messages) void CNetworkVatlib::sendTextMessages(const CTextMessageList &messages)
{ {
Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected"); BLACK_VERIFY_X(this->isConnected(), Q_FUNC_INFO, "Sending text message, but not connected");
if (!this->isConnected()) { return; }
if (messages.isEmpty()) { return; } if (messages.isEmpty()) { return; }
CTextMessageList privateMessages = messages.getPrivateMessages(); CTextMessageList privateMessages = messages.getPrivateMessages();
privateMessages.markAsSent(); privateMessages.markAsSent();
@@ -559,6 +559,14 @@ namespace BlackCore
} }
} }
void CNetworkVatlib::sendWallopMessage(const QString &message)
{
if (message.isEmpty()) {return; }
BLACK_VERIFY_X(this->isConnected(), Q_FUNC_INFO, "Sending wallop, but not connected");
if (!this->isConnected()) { return; }
Vat_SendWallop(m_net.data(), toFSDnoColon(simplifyAccents(message)));
}
void CNetworkVatlib::sendCustomPacket(const CCallsign &callsign, const QString &packetId, const QStringList &data) void CNetworkVatlib::sendCustomPacket(const CCallsign &callsign, const QString &packetId, const QStringList &data)
{ {
Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected"); Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected");

View File

@@ -101,6 +101,7 @@ namespace BlackCore
//! \name Text message functions //! \name Text message functions
//! @{ //! @{
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override; virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override;
virtual void sendWallopMessage(const QString &message) override;
//! @} //! @}
//! \name ATC functions //! \name ATC functions