mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Allow to select server type in FSD settings
Summary: With this change the server type is a dynamic setting per server and replaces the hardcoded global server type in CNetworkVatlib. This allows the user to select the server type in settings ui and configures the vatlib session accordingly. This also removes the command line argument to set the server type since it doesn't make sense anymore. Reviewers: msutcliffe Reviewed By: msutcliffe Subscribers: jenkins Differential Revision: https://dev.swift-project.org/D24
This commit is contained in:
@@ -23,8 +23,8 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections)
|
||||
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections) {}
|
||||
CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections, ServerType serverType)
|
||||
: m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections), m_serverType(serverType) {}
|
||||
|
||||
QString CServer::convertToQString(bool i18n) const
|
||||
{
|
||||
@@ -71,6 +71,17 @@ namespace BlackMisc
|
||||
return m_port > 0 && !m_address.isEmpty();
|
||||
}
|
||||
|
||||
QString CServer::getServerTypeAsString() const
|
||||
{
|
||||
switch (m_serverType)
|
||||
{
|
||||
case CServer::ServerVatsim: return QStringLiteral("VATSIM");
|
||||
case CServer::ServerFSC: return QStringLiteral("FSC");
|
||||
case CServer::ServerLegacyFSD: return QStringLiteral("Legacy FSD");
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
bool CServer::isConnected() const
|
||||
{
|
||||
return this->m_timestampMSecsSinceEpoch >= 0;
|
||||
@@ -119,6 +130,10 @@ namespace BlackMisc
|
||||
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);
|
||||
}
|
||||
@@ -153,6 +168,9 @@ namespace BlackMisc
|
||||
case IndexIsAcceptingConnections:
|
||||
this->setIsAcceptingConnections(variant.value<bool>());
|
||||
break;
|
||||
case IndexServerType:
|
||||
this->setServerType(static_cast<ServerType>(variant.toInt()));
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
|
||||
@@ -44,14 +44,25 @@ namespace BlackMisc
|
||||
IndexPort,
|
||||
IndexUser,
|
||||
IndexFsdSetup,
|
||||
IndexIsAcceptingConnections
|
||||
IndexIsAcceptingConnections,
|
||||
IndexServerType,
|
||||
IndexServerTypeAsString
|
||||
};
|
||||
|
||||
//! Server Type
|
||||
enum ServerType
|
||||
{
|
||||
ServerVatsim,
|
||||
ServerFSC,
|
||||
ServerLegacyFSD
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CServer() {}
|
||||
|
||||
//! Constructor.
|
||||
CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections = true);
|
||||
CServer(const QString &name, const QString &description, const QString &address, int port,
|
||||
const CUser &user, bool isAcceptingConnections = true, ServerType serverType = ServerVatsim);
|
||||
|
||||
//! Get address.
|
||||
const QString &getAddress() const { return m_address; }
|
||||
@@ -110,6 +121,15 @@ namespace BlackMisc
|
||||
//! Set setup
|
||||
void setFsdSetup(const CFsdSetup &setup) { this->m_fsdSetup = setup; }
|
||||
|
||||
//! Set server type
|
||||
void setServerType(ServerType serverType) { m_serverType = serverType; }
|
||||
|
||||
//! Get server type
|
||||
ServerType getServerType() const { return m_serverType; }
|
||||
|
||||
//! Get server type as string
|
||||
QString getServerTypeAsString() const;
|
||||
|
||||
//! Connected since
|
||||
QDateTime getConnectedSince() const { return this->getUtcTimestamp(); }
|
||||
|
||||
@@ -148,6 +168,7 @@ namespace BlackMisc
|
||||
CUser m_user;
|
||||
CFsdSetup m_fsdSetup;
|
||||
bool m_isAcceptingConnections = true; //!< disable server for connections
|
||||
ServerType m_serverType = ServerVatsim;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CServer,
|
||||
@@ -158,6 +179,7 @@ namespace BlackMisc
|
||||
BLACK_METAMEMBER(user),
|
||||
BLACK_METAMEMBER(fsdSetup),
|
||||
BLACK_METAMEMBER(isAcceptingConnections),
|
||||
BLACK_METAMEMBER(serverType),
|
||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison)
|
||||
);
|
||||
};
|
||||
@@ -165,5 +187,6 @@ namespace BlackMisc
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CServer)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CServer::ServerType)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user