From 22ca6ae9220123ab29b8e0e87d2a7990ad79a1ba Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 6 Dec 2015 05:40:50 +0100 Subject: [PATCH] Fixed adding the hardcoded test servers in a dev. environment (issue found during debugging of #533) Added some functions to find similar servers by address/port --- src/blackgui/components/logincomponent.cpp | 4 +-- .../settingsnetworkserverscomponent.cpp | 15 ++++++++--- src/blackmisc/network/server.cpp | 21 ++++++++++++++- src/blackmisc/network/server.h | 9 +++++++ src/blackmisc/network/serverlist.cpp | 26 ++++++++++++++++++- src/blackmisc/network/serverlist.h | 10 ++++++- src/blackmisc/simulation/simulatedaircraft.h | 5 +++- 7 files changed, 80 insertions(+), 10 deletions(-) diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index cbdd8210b..e6f8ae1fc 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -144,8 +144,8 @@ namespace BlackGui // add a testserver when no servers can be loaded if (otherServers.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment()) { - otherServers.push_back(m_setup.get().fsdTestServers()); - CLogMessage(this).info("Added servers (other) for testing"); + otherServers.push_back(m_setup.get().fsdTestServersPlusHardcodedServers()); + CLogMessage(this).info("Added servers for testing"); } this->ui->cbp_OtherServers->setServers(otherServers); } diff --git a/src/blackgui/components/settingsnetworkserverscomponent.cpp b/src/blackgui/components/settingsnetworkserverscomponent.cpp index 455d391b7..7a4957e56 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.cpp +++ b/src/blackgui/components/settingsnetworkserverscomponent.cpp @@ -38,6 +38,8 @@ namespace BlackGui this->connect(this->ui->pb_SettingsTnServersRemoveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer); this->connect(this->ui->pb_SettingsTnServersSaveServer, &QPushButton::pressed, this, &CSettingsNetworkServersComponent::ps_alterTrafficServer); this->connect(this->ui->tvp_SettingsTnServers, &QTableView::clicked, this, &CSettingsNetworkServersComponent::ps_networkServerSelected); + + this->ps_reloadSettings(); } CSettingsNetworkServersComponent::~CSettingsNetworkServersComponent() @@ -47,11 +49,11 @@ namespace BlackGui { CServerList serverList(m_trafficNetworkServers.get()); - // add swift test server in case we have no servers: + // add swift test servers in case we have no servers: // this is debug/bootstrap feature we can continue to test when something goes wrong if (serverList.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment()) { - serverList.push_back(m_setup.get().fsdTestServers()); + serverList.push_back(m_setup.get().fsdTestServersPlusHardcodedServers()); } this->ui->tvp_SettingsTnServers->updateContainer(serverList); } @@ -69,7 +71,6 @@ namespace BlackGui if (!msgs.isEmpty()) { msgs.addCategories(this); - msgs.addCategory(CLogCategory::validation()); CLogMessage::preformatted(msgs); return; } @@ -84,7 +85,13 @@ namespace BlackGui { serverList.replaceOrAdd(&CServer::getName, server.getName(), server); } - m_trafficNetworkServers.set(serverList); + + CStatusMessage msg = m_trafficNetworkServers.set(serverList); + if (msg.isWarningOrAbove()) + { + msg.addCategories(this); + CLogMessage::preformatted(msg); + } } } // namespace diff --git a/src/blackmisc/network/server.cpp b/src/blackmisc/network/server.cpp index dc67350e3..99fc7d7ff 100644 --- a/src/blackmisc/network/server.cpp +++ b/src/blackmisc/network/server.cpp @@ -35,19 +35,38 @@ namespace BlackMisc m_name.startsWith(name, Qt::CaseInsensitive); } + bool CServer::matchesAddressPort(const CServer &server) const + { + return server.getPort() == this->getPort() && + server.matchesAddress(this->getAddress()); + } + + bool CServer::matchesAddress(const QString &address) const + { + return m_address.length() == address.length() && + m_address.startsWith(address, Qt::CaseInsensitive); + } + bool CServer::isValidForLogin() const { - return this->m_user.hasValidCredentials() && this->m_port > 0 && !this->m_address.isEmpty() && this->isAcceptingConnections(); + return this->m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections(); + } + + bool CServer::hasAddressAndPort() const + { + return m_port > 0 && !m_address.isEmpty(); } CStatusMessageList CServer::validate() const { + static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()})); CStatusMessageList msgs; if (this->getName().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing name")); } if (this->getAddress().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing address")); } if (this->getDescription().isEmpty()) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Missing description")); } if (this->getPort() < 1 || this->getPort() > 65535) { msgs.push_back(CStatusMessage(CStatusMessage::SeverityWarning, "Wrong port")); } msgs.push_back(this->getUser().validate()); + msgs.addCategories(cats); return msgs; } diff --git a/src/blackmisc/network/server.h b/src/blackmisc/network/server.h index 12cd7c553..9b3a7b0b6 100644 --- a/src/blackmisc/network/server.h +++ b/src/blackmisc/network/server.h @@ -64,6 +64,12 @@ namespace BlackMisc //! Matches server name? bool matchesName(const QString &name) const; + //! Same address and port? + bool matchesAddressPort(const CServer &server) const; + + //! Same address? + bool matchesAddress(const QString &address) const; + //! Get description const QString &getDescription() const { return m_description; } @@ -85,6 +91,9 @@ namespace BlackMisc //! Is valid for login? bool isValidForLogin() const; + //! Address and port? + bool hasAddressAndPort() const; + //! Validate, provide details about issues BlackMisc::CStatusMessageList validate() const; diff --git a/src/blackmisc/network/serverlist.cpp b/src/blackmisc/network/serverlist.cpp index ac41e3aa6..456a37b9c 100644 --- a/src/blackmisc/network/serverlist.cpp +++ b/src/blackmisc/network/serverlist.cpp @@ -13,7 +13,6 @@ namespace BlackMisc { namespace Network { - CServerList::CServerList() { } CServerList::CServerList(const CSequence &other) : @@ -29,5 +28,30 @@ namespace BlackMisc return false; } + bool CServerList::containsAddressPort(const CServer &server) + { + for (const CServer &s : *this) + { + if (s.matchesAddressPort(server)) { return true; } + } + return false; + } + + void CServerList::addIfAddressNotExists(const CServer &server) + { + if (!server.hasAddressAndPort() || server.getName().isEmpty()) { return; } + if (!this->containsAddressPort(server)) + { + this->push_back(server); + } + } + + void CServerList::addIfAddressNotExists(const CServerList &servers) + { + for (const CServer &s : servers) + { + this->addIfAddressNotExists(s); + } + } } // namespace } // namespace diff --git a/src/blackmisc/network/serverlist.h b/src/blackmisc/network/serverlist.h index 09b84d4bd..ca8002d1a 100644 --- a/src/blackmisc/network/serverlist.h +++ b/src/blackmisc/network/serverlist.h @@ -37,8 +37,16 @@ namespace BlackMisc //! Contains name bool containsName(const QString &name) const; - }; + //! Contains server with same address/port + bool containsAddressPort(const CServer &server); + + //! Add if address not already exists + void addIfAddressNotExists(const CServer &server); + + //! Add if address not already exists + void addIfAddressNotExists(const CServerList &servers); + }; } //namespace } // namespace diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index ab8c4ab42..4c04bc75c 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -139,9 +139,12 @@ namespace BlackMisc //! Valid designators? bool hasAircraftAndAirlineDesignator() const; - //! Valid callsign + //! Valid callsign? bool hasValidCallsign() const { return BlackMisc::Aviation::CCallsign::isValidCallsign(this->getCallsign().asString()); } + //! Callsign not empty, no further checks + bool hasCallsign() const { return !getCallsign().isEmpty(); } + //! Get position BlackMisc::Geo::CCoordinateGeodetic getPosition() const { return this->m_situation.getPosition(); }