diff --git a/Configuration.cpp b/Configuration.cpp index a5980fd..da54a20 100644 --- a/Configuration.cpp +++ b/Configuration.cpp @@ -685,6 +685,8 @@ private: QString udp_server_name_; port_type udp_server_port_; + QString tcp_server_name_; + port_type tcp_server_port_; QString n3fjp_server_name_; port_type n3fjp_server_port_; bool broadcast_to_n3fjp_; @@ -692,9 +694,10 @@ private: port_type n1mm_server_port_; bool broadcast_to_n1mm_; bool accept_udp_requests_; - bool udpWindowToFront_; - bool udpWindowRestore_; + bool accept_tcp_requests_; bool udpEnabled_; + bool tcpEnabled_; + int tcpMaxConnections_; DataMode data_mode_; bool pwrBandTxMemory_; bool pwrBandTuneMemory_; @@ -868,16 +871,19 @@ QString Configuration::aprs_server_name () const {return m_->aprs_server_name_;} auto Configuration::aprs_server_port () const -> port_type {return m_->aprs_server_port_;} QString Configuration::udp_server_name () const {return m_->udp_server_name_;} auto Configuration::udp_server_port () const -> port_type {return m_->udp_server_port_;} +QString Configuration::tcp_server_name () const {return m_->tcp_server_name_;} +auto Configuration::tcp_server_port () const -> port_type {return m_->tcp_server_port_;} bool Configuration::accept_udp_requests () const {return m_->accept_udp_requests_;} +bool Configuration::accept_tcp_requests () const {return m_->accept_tcp_requests_;} QString Configuration::n3fjp_server_name () const {return m_->n3fjp_server_name_;} auto Configuration::n3fjp_server_port () const -> port_type {return m_->n3fjp_server_port_;} bool Configuration::broadcast_to_n3fjp () const {return m_->broadcast_to_n3fjp_;} QString Configuration::n1mm_server_name () const {return m_->n1mm_server_name_;} auto Configuration::n1mm_server_port () const -> port_type {return m_->n1mm_server_port_;} bool Configuration::broadcast_to_n1mm () const {return m_->broadcast_to_n1mm_;} -bool Configuration::udpWindowToFront () const {return m_->udpWindowToFront_;} -bool Configuration::udpWindowRestore () const {return m_->udpWindowRestore_;} bool Configuration::udpEnabled () const {return m_->udpEnabled_;} +bool Configuration::tcpEnabled () const {return m_->tcpEnabled_;} +int Configuration::tcp_max_connections() const { return m_->tcpMaxConnections_; } Bands * Configuration::bands () {return &m_->bands_;} Bands const * Configuration::bands () const {return &m_->bands_;} StationList * Configuration::stations () {return &m_->stations_;} @@ -1618,16 +1624,19 @@ void Configuration::impl::initialize_models () ui_->aprs_server_port_spin_box->setValue (aprs_server_port_); ui_->udp_server_line_edit->setText (udp_server_name_); ui_->udp_server_port_spin_box->setValue (udp_server_port_); + ui_->tcp_server_line_edit->setText (tcp_server_name_); + ui_->tcp_server_port_spin_box->setValue (tcp_server_port_); ui_->accept_udp_requests_check_box->setChecked (accept_udp_requests_); + ui_->accept_tcp_requests_check_box->setChecked (accept_tcp_requests_); ui_->n3fjp_server_name_line_edit->setText (n3fjp_server_name_); ui_->n3fjp_server_port_spin_box->setValue (n3fjp_server_port_); ui_->enable_n3fjp_broadcast_check_box->setChecked (broadcast_to_n3fjp_); ui_->n1mm_server_name_line_edit->setText (n1mm_server_name_); ui_->n1mm_server_port_spin_box->setValue (n1mm_server_port_); ui_->enable_n1mm_broadcast_check_box->setChecked (broadcast_to_n1mm_); - ui_->udpWindowToFront->setChecked(udpWindowToFront_); + ui_->tcpEnable->setChecked(tcpEnabled_); ui_->udpEnable->setChecked(udpEnabled_); - ui_->udpWindowRestore->setChecked(udpWindowRestore_); + ui_->tcp_max_connections_spin_box->setValue(tcpMaxConnections_); ui_->calibration_intercept_spin_box->setValue (calibration_.intercept); ui_->calibration_slope_ppm_spin_box->setValue (calibration_.slope_ppm); @@ -2069,6 +2078,8 @@ void Configuration::impl::read_settings () aprs_server_port_ = settings_->value ("aprsServerPort", 14580).toUInt (); udp_server_name_ = settings_->value ("UDPServer", "127.0.0.1").toString (); udp_server_port_ = settings_->value ("UDPServerPort", 2242).toUInt (); + tcp_server_name_ = settings_->value ("TCPServer", "127.0.0.1").toString (); + tcp_server_port_ = settings_->value ("TCPServerPort", 2442).toUInt (); n3fjp_server_name_ = settings_->value ("N3FJPServer", "127.0.0.1").toString (); n3fjp_server_port_ = settings_->value ("N3FJPServerPort", 1100).toUInt (); broadcast_to_n3fjp_ = settings_->value ("BroadcastToN3FJP", false).toBool (); @@ -2076,9 +2087,10 @@ void Configuration::impl::read_settings () n1mm_server_port_ = settings_->value ("N1MMServerPort", 2333).toUInt (); broadcast_to_n1mm_ = settings_->value ("BroadcastToN1MM", false).toBool (); accept_udp_requests_ = settings_->value ("AcceptUDPRequests", false).toBool (); + accept_tcp_requests_ = settings_->value ("AcceptTCPRequests", false).toBool (); udpEnabled_ = settings_->value("UDPEnabled", false).toBool(); - udpWindowToFront_ = settings_->value ("udpWindowToFront",false).toBool (); - udpWindowRestore_ = settings_->value ("udpWindowRestore",false).toBool (); + tcpEnabled_ = settings_->value("TCPEnabled", false).toBool(); + tcpMaxConnections_ = settings_->value("TCPMaxConnections", 1).toInt(); calibration_.intercept = settings_->value ("CalibrationIntercept", 0.).toDouble (); calibration_.slope_ppm = settings_->value ("CalibrationSlopePPM", 0.).toDouble (); pwrBandTxMemory_ = settings_->value("pwrBandTxMemory",false).toBool (); @@ -2255,6 +2267,8 @@ void Configuration::impl::write_settings () settings_->setValue ("aprsServerPort", aprs_server_port_); settings_->setValue ("UDPServer", udp_server_name_); settings_->setValue ("UDPServerPort", udp_server_port_); + settings_->setValue ("TCPServer", tcp_server_name_); + settings_->setValue ("TCPServerPort", tcp_server_port_); settings_->setValue ("N3FJPServer", n3fjp_server_name_); settings_->setValue ("N3FJPServerPort", n3fjp_server_port_); settings_->setValue ("BroadcastToN3FJP", broadcast_to_n3fjp_); @@ -2262,9 +2276,10 @@ void Configuration::impl::write_settings () settings_->setValue ("N1MMServerPort", n1mm_server_port_); settings_->setValue ("BroadcastToN1MM", broadcast_to_n1mm_); settings_->setValue ("AcceptUDPRequests", accept_udp_requests_); + settings_->setValue ("AcceptTCPRequests", accept_tcp_requests_); settings_->setValue ("UDPEnabled", udpEnabled_); - settings_->setValue ("udpWindowToFront", udpWindowToFront_); - settings_->setValue ("udpWindowRestore", udpWindowRestore_); + settings_->setValue ("TCPEnabled", tcpEnabled_); + settings_->setValue ("TCPMaxConnections", tcpMaxConnections_); settings_->setValue ("CalibrationIntercept", calibration_.intercept); settings_->setValue ("CalibrationSlopePPM", calibration_.slope_ppm); settings_->setValue ("pwrBandTxMemory", pwrBandTxMemory_); @@ -2870,23 +2885,48 @@ void Configuration::impl::accept () aprs_server_port_ = ui_->aprs_server_port_spin_box->value(); auto newUdpEnabled = ui_->udpEnable->isChecked(); - auto new_server = ui_->udp_server_line_edit->text (); - if (new_server != udp_server_name_ || newUdpEnabled != udpEnabled_) + auto newUdpServer = ui_->udp_server_line_edit->text (); + if (newUdpServer != udp_server_name_ || newUdpEnabled != udpEnabled_) { - udp_server_name_ = new_server; + udp_server_name_ = newUdpServer; udpEnabled_ = newUdpEnabled; - Q_EMIT self_->udp_server_changed (udpEnabled_ ? new_server : ""); + Q_EMIT self_->udp_server_changed (udpEnabled_ ? newUdpServer : ""); } - auto new_port = ui_->udp_server_port_spin_box->value (); - if (new_port != udp_server_port_) + auto newUdpPort = ui_->udp_server_port_spin_box->value (); + if (newUdpPort != udp_server_port_) { - udp_server_port_ = new_port; - Q_EMIT self_->udp_server_port_changed (new_port); + udp_server_port_ = newUdpPort; + Q_EMIT self_->udp_server_port_changed (newUdpPort); } + auto newTcpEnabled = ui_->tcpEnable->isChecked(); + auto newTcpServer = ui_->tcp_server_line_edit->text (); + if (newTcpServer != tcp_server_name_ || newTcpEnabled != tcpEnabled_) + { + tcp_server_name_ = newTcpServer; + tcpEnabled_ = newTcpEnabled; + + Q_EMIT self_->tcp_server_changed (tcpEnabled_ ? newTcpServer : ""); + } + + auto newTcpPort = ui_->tcp_server_port_spin_box->value (); + if (newTcpPort != tcp_server_port_) + { + tcp_server_port_ = newTcpPort; + Q_EMIT self_->tcp_server_port_changed (newTcpPort); + } + + auto newTcpMaxConnections = ui_->tcp_max_connections_spin_box->value(); + if(newTcpMaxConnections != tcpMaxConnections_){ + tcpMaxConnections_ = newTcpMaxConnections; + Q_EMIT self_->tcp_max_connections_changed (newTcpMaxConnections); + } + accept_udp_requests_ = ui_->accept_udp_requests_check_box->isChecked (); + accept_tcp_requests_ = ui_->accept_tcp_requests_check_box->isChecked (); + auto new_n3fjp_server = ui_->n3fjp_server_name_line_edit->text (); n3fjp_server_name_ = new_n3fjp_server; auto new_n3fjp_port = ui_->n3fjp_server_port_spin_box->value (); @@ -2899,10 +2939,6 @@ void Configuration::impl::accept () n1mm_server_port_ = new_n1mm_port; broadcast_to_n1mm_ = ui_->enable_n1mm_broadcast_check_box->isChecked (); - udpWindowToFront_ = ui_->udpWindowToFront->isChecked (); - udpWindowRestore_ = ui_->udpWindowRestore->isChecked (); - - if (macros_.stringList () != next_macros_.stringList ()) { macros_.setStringList (next_macros_.stringList ()); diff --git a/Configuration.hpp b/Configuration.hpp index 3327b36..3f704d6 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -188,6 +188,8 @@ public: port_type aprs_server_port () const; QString udp_server_name () const; port_type udp_server_port () const; + QString tcp_server_name () const; + port_type tcp_server_port () const; QString n1mm_server_name () const; port_type n1mm_server_port () const; bool valid_n1mm_info () const; @@ -197,9 +199,10 @@ public: bool valid_n3fjp_info () const; bool broadcast_to_n3fjp() const; bool accept_udp_requests () const; - bool udpWindowToFront () const; - bool udpWindowRestore () const; + bool accept_tcp_requests () const; bool udpEnabled () const; + bool tcpEnabled () const; + int tcp_max_connections () const; Bands * bands (); Bands const * bands () const; IARURegions::Region region () const; @@ -334,6 +337,7 @@ public: Q_SIGNAL void udp_server_port_changed (port_type port); Q_SIGNAL void tcp_server_changed (QString const& host); Q_SIGNAL void tcp_server_port_changed (port_type port); + Q_SIGNAL void tcp_max_connections_changed (int n); // This signal is emitted when the band schedule changes Q_SIGNAL void band_schedule_changed (StationList &stations); diff --git a/Configuration.ui b/Configuration.ui index cc2c8a6..b7f25e1 100644 --- a/Configuration.ui +++ b/Configuration.ui @@ -2350,6 +2350,97 @@ both here. Reporting and logging settings + + + + Logging + + + + + + + + false + + + false + + + Some logging programs will not accept the type of reports +saved by this program. +Check this option to save the sent and received reports in the +comments field. + + + d&B reports to comments + + + + + + + true + + + false + + + Check this option to force deselect callsign after logging. + + + Deselect callsign after logging + + + + + + + Operator Callsign (if different than Station Callsign): + + + + + + + false + + + false + + + The program will pop up a partially completed Log QSO dialog when you send a 73 or free text message. + + + Promp&t me to log QSO + + + + + + + <html><head/><body><p>The callsign of the operator, if different from the station callsign.</p></body></html> + + + + + + + false + + + Some logging programs will not accept JT-65 or JT9 as a recognized mode. + + + Con&vert mode to DATA + + + + + + + + @@ -2370,7 +2461,7 @@ both here. 0 0 746 - 667 + 722 @@ -2386,223 +2477,6 @@ both here. 0 - - - - Logging - - - - - - - - false - - - false - - - Some logging programs will not accept the type of reports -saved by this program. -Check this option to save the sent and received reports in the -comments field. - - - d&B reports to comments - - - - - - - true - - - false - - - Check this option to force deselect callsign after logging. - - - Deselect callsign after logging - - - - - - - Operator Callsign (if different than Station Callsign): - - - - - - - false - - - false - - - The program will pop up a partially completed Log QSO dialog when you send a 73 or free text message. - - - Promp&t me to log QSO - - - - - - - <html><head/><body><p>The callsign of the operator, if different from the station callsign.</p></body></html> - - - - - - - false - - - Some logging programs will not accept JT-65 or JT9 as a recognized mode. - - - Con&vert mode to DATA - - - - - - - - - - - - UDP API - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - UDP Server: - - - udp_server_line_edit - - - - - - - - 0 - 0 - - - - <html><head/><body><p>Optional hostname of network service to receive decodes.</p><p>Formats:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">hostname</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv4 address</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv6 address</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv4 multicast group address</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv6 multicast group address</li></ul><p>Clearing this field will disable the broadcasting of UDP status updates.</p></body></html> - - - Qt::ImhDigitsOnly - - - - - - - UDP Server Port: - - - udp_server_port_spin_box - - - - - - - <html><head/><body><p>Enter the service port number of the UDP server that should receive updates. If this is zero no updates will be broadcast.</p></body></html> - - - 0 - - - 65534 - - - - - - - - - - - Enable UDP Server API - - - - - - - <html><head/><body><p>With this enabled the app will accept certain requests back from a UDP server that receives decode messages.</p></body></html> - - - Accept UDP requests - - - - - - - - - <html><head/><body><p>Check to allow changes to grid, qtc, etc from external programs</p></body></html> - - - Accept Dynamic Station Information (Grid, Info, Status, etc) - - - - - - - - - false - - - <html><head/><body><p>Indicate acceptance of an incoming UDP request. The effect of this option varies depending on the operating system and window manager, its intent is to notify the acceptance of an incoming UDP request even if this application is minimized or hidden.</p></body></html> - - - Notify on accepted UDP request - - - - - - - false - - - <html><head/><body><p>Restore the window from minimized if an UDP request is accepted.</p></body></html> - - - Accepted UDP request restores window - - - - - - - - @@ -2700,6 +2574,225 @@ for assessing propagation and system performance. + + + + API + + + + + + + + <html><head/><body><p>Enable the application to send API information to UDP Servers</p></body></html> + + + Enable UDP Server API + + + + + + + <html><head/><body><p>With this enabled the app will accept certain requests back from a UDP server that receives decode messages.</p></body></html>ch + + + Accept UDP Requests + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + + + <html><head/><body><p>Enable the application to send API information over a TCP Server</p></body></html> + + + Enable TCP Server API + + + + + + + <html><head/><body><p>With this enabled the app will accept certain requests back from a TCP client that receives decode messages.</p></body></html> + + + Accept TCP Requests + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + TCP Server Hostname: + + + + + + + TCP Server Port: + + + + + + + <html><head/><body><p>Enter the service port number of the TCP server. If this is zero then TCP server will not be started.</p></body></html> + + + 65534 + + + + + + + <html><head/><body><p>Enter the maximum number of API connections allowed to the TCP server</p></body></html> + + + 1 + + + 100 + + + + + + + TCP Max Connections: + + + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + UDP Server Hostname: + + + udp_server_line_edit + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Optional hostname of network service to receive decodes.</p><p>Formats:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">hostname</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv4 address</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv6 address</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv4 multicast group address</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">IPv6 multicast group address</li></ul><p>Clearing this field will disable the broadcasting of UDP status updates.</p></body></html> + + + Qt::ImhDigitsOnly + + + + + + + UDP Server Port: + + + udp_server_port_spin_box + + + + + + + <html><head/><body><p>Enter the service port number of the UDP server that should receive updates. If this is zero no updates will be broadcast.</p></body></html> + + + 0 + + + 65534 + + + + + + + + + <html><head/><body><p>Check to allow changes to grid, qtc, etc from external programs</p></body></html> + + + Allow setting station information (Grid, Info, Status, etc) from the APIs + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + @@ -4508,7 +4601,6 @@ soundcard changes udp_server_port_spin_box udpEnable accept_udp_requests_check_box - use_dynamic_grid psk_reporter_check_box aprs_server_line_edit aprs_server_port_spin_box @@ -4646,11 +4738,11 @@ soundcard changes - - + - + + diff --git a/MessageServer.cpp b/MessageServer.cpp index 22f7a89..e9b30ac 100644 --- a/MessageServer.cpp +++ b/MessageServer.cpp @@ -20,11 +20,16 @@ bool MessageServer::start() } auto address = QHostAddress(); - if(!address.setAddress(m_host)){ + if(m_host.isEmpty() || !address.setAddress(m_host)){ qDebug() << "MessageServer address invalid:" << m_host << m_port; return false; } + if(m_port <= 0){ + qDebug() << "MessageServer port invalid:" << m_host << m_port; + return false; + } + bool listening = listen(address, m_port); qDebug() << "MessageServer listening:" << listening << m_host << m_port; @@ -67,6 +72,33 @@ void MessageServer::setPause(bool paused) } } +void MessageServer::setMaxConnections(int n){ + // set the maximum number of connections allowed + m_maxConnections = n; + + // then, prune old ones greater than the max (fifo) + pruneConnections(); +} + +int MessageServer::activeConnections(){ + int i = 0; + foreach(auto client, m_clients){ + if(client->isConnected()) i++; + } + return i; +} + +void MessageServer::pruneConnections(){ + // keep only the n most recent connections (fifo) + if(m_maxConnections && m_maxConnections < activeConnections()){ + for(int i = m_maxConnections; i < activeConnections(); i++){ + auto client = m_clients.first(); + client->close(); + m_clients.removeFirst(); + } + } +} + void MessageServer::send(const Message &message){ foreach(auto client, m_clients){ if(!client->awaitingResponse(message.id())){ @@ -91,6 +123,13 @@ void MessageServer::incomingConnection(qintptr handle) } #endif + if(m_maxConnections && m_maxConnections <= activeConnections()){ + qDebug() << "MessageServer connections full, dropping incoming connection"; + client->send(Message("API.ERROR", "Connections Full")); + client->close(); + return; + } + m_clients.append(client); } @@ -167,12 +206,12 @@ void Client::readyRead(){ QJsonParseError e; QJsonDocument d = QJsonDocument::fromJson(msg, &e); if(e.error != QJsonParseError::NoError){ - //Q_EMIT self_->error(QString {"MessageClient json parse error: %1"}.arg(e.errorString())); + send({"API.ERROR", "Invalid JSON (unparsable)"}); return; } if(!d.isObject()){ - //Q_EMIT self_->error(QString {"MessageClient json parse error: json is not an object"}); + send({"API.ERROR", "Invalid JSON (not an object)"}); return; } diff --git a/MessageServer.h b/MessageServer.h index 7dd8e9c..50ab5cf 100644 --- a/MessageServer.h +++ b/MessageServer.h @@ -19,6 +19,8 @@ public: virtual ~MessageServer(); protected: + int activeConnections(); + void pruneConnections(); void incomingConnection(qintptr handle); signals: @@ -30,6 +32,7 @@ public slots: void setPause(bool paused); bool start(); void stop(); + void setMaxConnections(int n); void setServerHost(const QString &host){ setServer(host, m_port); } void setServerPort(quint16 port){ setServer(m_host, port); } void send(Message const &message); @@ -38,6 +41,7 @@ private: bool m_paused; QString m_host; quint16 m_port; + int m_maxConnections; QList m_clients; }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 6e1e834..4d6601f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -488,11 +488,13 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, // hook up the message server slots and signals and disposal connect (m_messageServer, &MessageServer::error, this, &MainWindow::udpNetworkError); connect (m_messageServer, &MessageServer::message, this, &MainWindow::networkMessage); + connect (this, &MainWindow::apiSetMaxConnections, m_messageServer, &MessageServer::setMaxConnections); connect (this, &MainWindow::apiSetServer, m_messageServer, &MessageServer::setServer); connect (this, &MainWindow::apiStartServer, m_messageServer, &MessageServer::start); connect (this, &MainWindow::apiStopServer, m_messageServer, &MessageServer::stop); connect (&m_config, &Configuration::tcp_server_changed, m_messageServer, &MessageServer::setServerHost); connect (&m_config, &Configuration::tcp_server_port_changed, m_messageServer, &MessageServer::setServerPort); + connect (&m_config, &Configuration::tcp_max_connections_changed, m_messageServer, &MessageServer::setMaxConnections); connect (&m_networkThread, &QThread::finished, m_messageServer, &QObject::deleteLater); // hook up the aprs client slots and signals and disposal @@ -3180,9 +3182,13 @@ void MainWindow::openSettings(int tab){ } void MainWindow::prepareApi(){ - bool enabled = true; + // the udp api is prepared by default (always listening) + + // so, we just need to prepare the tcp api + bool enabled = m_config.tcpEnabled(); if(enabled){ - emit apiSetServer("0.0.0.0", 2442); + emit apiSetMaxConnections(m_config.tcp_max_connections()); + emit apiSetServer(m_config.tcp_server_name(), m_config.tcp_server_port()); emit apiStartServer(); } else { emit apiStopServer(); @@ -12624,13 +12630,13 @@ void MainWindow::udpNetworkMessage(Message const &message) void MainWindow::tcpNetworkMessage(Message const &message) { - // if(!m_config.tcpEnabled()){ - // return; - // } - // - // if(!m_config.accept_tcp_requests()){ - // return; - // } + if(!m_config.tcpEnabled()){ + return; + } + + if(!m_config.accept_tcp_requests()){ + return; + } networkMessage(message); } @@ -12888,7 +12894,7 @@ void MainWindow::networkMessage(Message const &message) } bool MainWindow::canSendNetworkMessage(){ - return m_config.udpEnabled(); + return m_config.udpEnabled() || m_config.tcpEnabled(); } void MainWindow::sendNetworkMessage(QString const &type, QString const &message){ @@ -12897,8 +12903,14 @@ void MainWindow::sendNetworkMessage(QString const &type, QString const &message) } auto m = Message(type, message); - m_messageClient->send(m); - m_messageServer->send(m); + + if(m_config.udpEnabled()){ + m_messageClient->send(m); + } + + if(m_config.tcpEnabled()){ + m_messageServer->send(m); + } } void MainWindow::sendNetworkMessage(QString const &type, QString const &message, QMap const ¶ms) @@ -12908,12 +12920,19 @@ void MainWindow::sendNetworkMessage(QString const &type, QString const &message, } auto m = Message(type, message, params); - m_messageClient->send(m); - m_messageServer->send(m); + + if(m_config.udpEnabled()){ + m_messageClient->send(m); + } + + if(m_config.tcpEnabled()){ + m_messageServer->send(m); + } } void MainWindow::udpNetworkError (QString const& e) { + /* if(!m_config.udpEnabled()){ return; } @@ -12934,6 +12953,7 @@ void MainWindow::udpNetworkError (QString const& e) // retry server lookup m_messageClient->set_server (m_config.udp_server_name ()); } + */ } void MainWindow::tcpNetworkError (QString const& e) diff --git a/mainwindow.h b/mainwindow.h index 265dc39..8e9f58e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -441,6 +441,7 @@ private slots: void refreshTextDisplay(); private: + Q_SIGNAL void apiSetMaxConnections(int n); Q_SIGNAL void apiSetServer(QString host, quint16 port); Q_SIGNAL void apiStartServer(); Q_SIGNAL void apiStopServer();