mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Ref T172, added ecosystem in CServer class
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/verify.h"
|
||||
|
||||
#include <Qt>
|
||||
#include <QtGlobal>
|
||||
@@ -25,19 +26,52 @@ namespace BlackMisc
|
||||
{
|
||||
const QList<int> &CServer::allServerTypes()
|
||||
{
|
||||
static const QList<int> all({ FSDServerVatsim, FSDServerFSC, FSDServerLegacy, WebService, Unspecified });
|
||||
static const QList<int> all({ FSDServerVatsim, VoiceServerVatsim, FSDServer, VoiceServer, WebService, Unspecified });
|
||||
return all;
|
||||
}
|
||||
|
||||
CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, ServerType serverType, bool isAcceptingConnections)
|
||||
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_serverType(serverType), m_isAcceptingConnections(isAcceptingConnections) {}
|
||||
CServer::CServer(
|
||||
const QString &name, const QString &description, const QString &address, int port, const CUser &user,
|
||||
const CFsdSetup &setup, const CEcosystem &ecosytem, ServerType serverType, bool isAcceptingConnections)
|
||||
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user),
|
||||
m_fsdSetup(setup), m_ecosystem(ecosytem),
|
||||
m_serverType(serverType), m_isAcceptingConnections(isAcceptingConnections)
|
||||
{}
|
||||
|
||||
CServer::CServer(
|
||||
const QString &address, int port, const CUser &user)
|
||||
: m_name("no name"), m_description("min.configuration"), m_address(address), m_port(port), m_user(user)
|
||||
{}
|
||||
|
||||
CServer::CServer(const CEcosystem &ecosystem)
|
||||
{
|
||||
this->setEcosystem(ecosystem);
|
||||
}
|
||||
|
||||
CServer::CServer(CServer::ServerType serverType)
|
||||
{
|
||||
this->setServerType(serverType);
|
||||
}
|
||||
|
||||
QString CServer::convertToQString(bool i18n) const
|
||||
{
|
||||
static const QString str("%1 %2 %3:%4 %5 accepting: %6 FSD: %7 con.since: %8");
|
||||
static const QString str("%1 %2 %3:%4 %5 %6 accepting: %7 FSD: %8 con.since: %9");
|
||||
return str.
|
||||
arg(this->m_name, this->m_description, this->m_address).arg(this->m_port).
|
||||
arg(this->m_user.toQString(i18n), boolToYesNo(this->m_isAcceptingConnections), this->m_fsdSetup.toQString(i18n), this->isConnected() ? this->getFormattedUtcTimestampHms() : "not con.");
|
||||
arg(m_name, m_description, m_address).arg(m_port).
|
||||
arg(m_user.toQString(i18n), m_ecosystem.getSystemString(),
|
||||
boolToYesNo(m_isAcceptingConnections), m_fsdSetup.toQString(i18n), this->isConnected() ? this->getFormattedUtcTimestampHms() : "not con.");
|
||||
}
|
||||
|
||||
const CServer &CServer::swiftFsdTestServer(bool withPw)
|
||||
{
|
||||
// CUser("guest", "Guest Client project", "", "guest")
|
||||
static const CServer dvp("Testserver", "Client project testserver", "fsd.swift-project.org", 6809,
|
||||
CUser("1234567", "Test User", "", "123456"),
|
||||
CFsdSetup(), CEcosystem(CEcosystem::swiftTest()), CServer::FSDServerVatsim);
|
||||
static const CServer dvnp("Testserver", "Client project testserver", "fsd.swift-project.org", 6809,
|
||||
CUser("1234567", "Test User", "", ""),
|
||||
CFsdSetup(), CEcosystem(CEcosystem::swiftTest()), CServer::FSDServerVatsim);
|
||||
return withPw ? dvp : dvnp;
|
||||
}
|
||||
|
||||
bool CServer::matchesName(const QString &name) const
|
||||
@@ -58,9 +92,21 @@ namespace BlackMisc
|
||||
m_address.startsWith(address, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool CServer::setEcosystem(const CEcosystem &ecosystem)
|
||||
{
|
||||
if (m_ecosystem == ecosystem) { return false; } // avoid cross dependency
|
||||
m_ecosystem = ecosystem;
|
||||
|
||||
// cross dependency
|
||||
if (ecosystem.isSystem(CEcosystem::VATSIM)) { m_serverType = FSDServerVatsim; }
|
||||
if (ecosystem.isSystem(CEcosystem::PrivateFSD)) { m_serverType = FSDServer; }
|
||||
if (ecosystem.isSystem(CEcosystem::SwiftTest)) { m_serverType = FSDServerVatsim; }
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CServer::isValidForLogin() const
|
||||
{
|
||||
return this->m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
|
||||
return m_user.hasValidCredentials() && this->hasAddressAndPort() && this->isAcceptingConnections();
|
||||
}
|
||||
|
||||
bool CServer::hasAddressAndPort() const
|
||||
@@ -71,18 +117,39 @@ namespace BlackMisc
|
||||
bool CServer::isFsdServer() const
|
||||
{
|
||||
return (this->getServerType() == FSDServerVatsim ||
|
||||
this->getServerType() == FSDServerLegacy ||
|
||||
this->getServerType() == FSDServerFSC);
|
||||
this->getServerType() == FSDServer);
|
||||
}
|
||||
|
||||
bool CServer::setServerType(CServer::ServerType serverType)
|
||||
{
|
||||
if (m_serverType == serverType) { return false; } // avoid x-dependency
|
||||
m_serverType = static_cast<int>(serverType);
|
||||
switch (m_serverType)
|
||||
{
|
||||
case FSDServerVatsim : m_ecosystem = CEcosystem(CEcosystem::VATSIM); break;
|
||||
case FSDServer: m_ecosystem = CEcosystem(CEcosystem::PrivateFSD); break;
|
||||
case VoiceServerVatsim: m_ecosystem = CEcosystem(CEcosystem::VATSIM); break;
|
||||
case VoiceServer: m_ecosystem = CEcosystem(CEcosystem::PrivateFSD); break;
|
||||
case WebService: m_ecosystem = CEcosystem(CEcosystem::NoSystem); break;
|
||||
case Unspecified: m_ecosystem = CEcosystem(CEcosystem::Unspecified); break;
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CServer::hasUnspecifiedServerType() const
|
||||
{
|
||||
return this->getServerType() == Unspecified;
|
||||
}
|
||||
|
||||
const QString &CServer::getServerTypeAsString() const
|
||||
{
|
||||
return serverTypeToString(getServerType());
|
||||
return CServer::serverTypeToString(getServerType());
|
||||
}
|
||||
|
||||
bool CServer::isConnected() const
|
||||
{
|
||||
return this->m_timestampMSecsSinceEpoch >= 0;
|
||||
return m_timestampMSecsSinceEpoch >= 0;
|
||||
}
|
||||
|
||||
CStatusMessageList CServer::validate() const
|
||||
@@ -107,7 +174,7 @@ namespace BlackMisc
|
||||
return session.arg(this->getName(), this->getAddress()).arg(this->getPort()).arg(this->getUser().getRealName(), this->getFormattedUtcTimestampHms());
|
||||
}
|
||||
|
||||
CVariant CServer::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
CVariant CServer::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||
@@ -115,26 +182,17 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAddress:
|
||||
return CVariant::fromValue(this->m_address);
|
||||
case IndexDescription:
|
||||
return CVariant::fromValue(this->m_description);
|
||||
case IndexName:
|
||||
return CVariant::fromValue(this->m_name);
|
||||
case IndexPort:
|
||||
return CVariant::fromValue(this->m_port);
|
||||
case IndexUser:
|
||||
return this->m_user.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexFsdSetup:
|
||||
return this->m_fsdSetup.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIsAcceptingConnections:
|
||||
return CVariant::fromValue(this->m_isAcceptingConnections);
|
||||
case IndexServerType:
|
||||
return CVariant::fromValue(this->m_serverType);
|
||||
case IndexServerTypeAsString:
|
||||
return CVariant::fromValue(getServerTypeAsString());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
case IndexAddress: return CVariant::fromValue(m_address);
|
||||
case IndexDescription: return CVariant::fromValue(m_description);
|
||||
case IndexName: return CVariant::fromValue(m_name);
|
||||
case IndexPort: return CVariant::fromValue(m_port);
|
||||
case IndexUser: return m_user.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexFsdSetup: return m_fsdSetup.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexEcosystem: return m_ecosystem.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIsAcceptingConnections: return CVariant::fromValue(m_isAcceptingConnections);
|
||||
case IndexServerType: return CVariant::fromValue(m_serverType);
|
||||
case IndexServerTypeAsString: return CVariant::fromValue(getServerTypeAsString());
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,33 +204,16 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAddress:
|
||||
this->setAddress(variant.value<QString>());
|
||||
break;
|
||||
case IndexPort:
|
||||
this->setPort(variant.value<qint32>());
|
||||
break;
|
||||
case IndexDescription:
|
||||
this->setDescription(variant.value<QString>());
|
||||
break;
|
||||
case IndexName:
|
||||
this->setName(variant.value<QString>());
|
||||
break;
|
||||
case IndexUser:
|
||||
this->m_user.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexFsdSetup:
|
||||
this->m_fsdSetup.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexIsAcceptingConnections:
|
||||
this->setIsAcceptingConnections(variant.value<bool>());
|
||||
break;
|
||||
case IndexServerType:
|
||||
this->setServerType(static_cast<ServerType>(variant.toInt()));
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
case IndexAddress: this->setAddress(variant.value<QString>()); break;
|
||||
case IndexPort: this->setPort(variant.value<qint32>()); break;
|
||||
case IndexDescription: this->setDescription(variant.value<QString>()); break;
|
||||
case IndexName: this->setName(variant.value<QString>()); break;
|
||||
case IndexUser: m_user.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexFsdSetup: m_fsdSetup.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexEcosystem: m_ecosystem.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexIsAcceptingConnections: this->setIsAcceptingConnections(variant.value<bool>()); break;
|
||||
case IndexServerType: this->setServerType(static_cast<ServerType>(variant.toInt())); break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,45 +224,40 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAddress:
|
||||
return this->getAddress().compare(compareValue.getAddress(), Qt::CaseInsensitive);
|
||||
case IndexDescription:
|
||||
return this->getDescription().compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
||||
case IndexFsdSetup:
|
||||
return this->getFsdSetup().toQString().compare(compareValue.getFsdSetup().toQString());
|
||||
case IndexName:
|
||||
return this->getName().compare(compareValue.getName(), Qt::CaseInsensitive);
|
||||
case IndexIsAcceptingConnections:
|
||||
return Compare::compare(this->isAcceptingConnections(), compareValue.isAcceptingConnections());
|
||||
case IndexPort:
|
||||
return Compare::compare(this->getPort(), compareValue.getPort());
|
||||
case IndexUser:
|
||||
return this->getUser().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getUser());
|
||||
case IndexAddress: return this->getAddress().compare(compareValue.getAddress(), Qt::CaseInsensitive);
|
||||
case IndexDescription: return this->getDescription().compare(compareValue.getDescription(), Qt::CaseInsensitive);
|
||||
case IndexFsdSetup: return this->getFsdSetup().toQString().compare(compareValue.getFsdSetup().toQString());
|
||||
case IndexName: return this->getName().compare(compareValue.getName(), Qt::CaseInsensitive);
|
||||
case IndexIsAcceptingConnections: return Compare::compare(this->isAcceptingConnections(), compareValue.isAcceptingConnections());
|
||||
case IndexPort: return Compare::compare(this->getPort(), compareValue.getPort());
|
||||
case IndexUser: return this->getUser().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getUser());
|
||||
case IndexEcosystem: return this->getEcosystem().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getEcosystem());
|
||||
case IndexServerType:
|
||||
case IndexServerTypeAsString:
|
||||
return this->getServerTypeAsString().compare(compareValue.getServerTypeAsString(), Qt::CaseInsensitive);
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No compare function");
|
||||
BLACK_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
const QString &CServer::serverTypeToString(CServer::ServerType server)
|
||||
{
|
||||
static const QString fsdVatsim("FSD [VATSIM]");
|
||||
static const QString fsdFsc("FSD [FSC]");
|
||||
static const QString voiceVatsim("voice [VATSIM]");
|
||||
static const QString fsdLegacy("FSD (legacy)");
|
||||
static const QString voice("voice");
|
||||
static const QString webService("web service");
|
||||
static const QString unspecified("unspecified");
|
||||
|
||||
switch (server)
|
||||
{
|
||||
case FSDServerVatsim: return fsdVatsim;
|
||||
case FSDServerFSC: return fsdFsc;
|
||||
case FSDServerLegacy: return fsdLegacy;
|
||||
case VoiceServerVatsim: return voiceVatsim;
|
||||
case FSDServer: return fsdLegacy;
|
||||
case VoiceServer: return voice;
|
||||
case WebService: return webService;
|
||||
case Unspecified: return unspecified;
|
||||
case Unspecified:
|
||||
default: return unspecified;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user