diff --git a/src/blackcore/context/contextnetworkimpl.cpp b/src/blackcore/context/contextnetworkimpl.cpp index 1a62905b3..19236417e 100644 --- a/src/blackcore/context/contextnetworkimpl.cpp +++ b/src/blackcore/context/contextnetworkimpl.cpp @@ -280,7 +280,7 @@ namespace BlackCore { Q_UNUSED(originator;) 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); parser.parse(commandLine); if (!parser.isKnownCommand()) { return false; } @@ -401,6 +401,15 @@ namespace BlackCore 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; } diff --git a/src/blackcore/context/contextnetworkimpl.h b/src/blackcore/context/contextnetworkimpl.h index 1bbdb1d5f..31e245302 100644 --- a/src/blackcore/context/contextnetworkimpl.h +++ b/src/blackcore/context/contextnetworkimpl.h @@ -209,6 +209,7 @@ namespace BlackCore //! .altos .altoffset altitude offset for testing //! .reinit .reinitialize re-initialize all aircraft //! .watchdog on|off watchdog on/off + //! .wallop message send wallop message //! //! @} //! \copydoc IContextNetwork::parseCommandLine @@ -223,6 +224,7 @@ namespace BlackCore BlackMisc::CSimpleCommandParser::registerCommand({".m callsign message text", "send text message"}); 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({".wallop message", "send a wallop message"}); BlackMisc::CSimpleCommandParser::registerCommand({".reinit", "re-initialize all aircraft"}); } diff --git a/src/blackcore/network.h b/src/blackcore/network.h index b90b28eb6..77444f0e9 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -245,6 +245,12 @@ namespace BlackCore */ 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 diff --git a/src/blackcore/vatsim/networkvatlib.cpp b/src/blackcore/vatsim/networkvatlib.cpp index 1ffa39177..90be34d95 100644 --- a/src/blackcore/vatsim/networkvatlib.cpp +++ b/src/blackcore/vatsim/networkvatlib.cpp @@ -482,9 +482,9 @@ namespace BlackCore if (!m_net) { initializeSession(); } this->clearState(); m_filterPasswordFromLogin = true; - QByteArray callsign = toFSD(m_loginMode == LoginAsObserver ? - m_ownCallsign.getAsObserverCallsignString() : - m_ownCallsign.asString()); + QByteArray callsign = toFSDnoColon(m_loginMode == LoginAsObserver ? + m_ownCallsign.getAsObserverCallsignString() : + m_ownCallsign.asString()); QByteArray name; if (m_loginMode == LoginAsObserver) { @@ -532,8 +532,8 @@ namespace BlackCore 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; } CTextMessageList privateMessages = messages.getPrivateMessages(); 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) { Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected"); diff --git a/src/blackcore/vatsim/networkvatlib.h b/src/blackcore/vatsim/networkvatlib.h index 42a1f047c..ecbd76482 100644 --- a/src/blackcore/vatsim/networkvatlib.h +++ b/src/blackcore/vatsim/networkvatlib.h @@ -101,6 +101,7 @@ namespace BlackCore //! \name Text message functions //! @{ virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override; + virtual void sendWallopMessage(const QString &message) override; //! @} //! \name ATC functions