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:
Roland Winklmeier
2017-05-16 16:06:40 +02:00
parent f1f7ee4709
commit 5d1b5dba38
7 changed files with 157 additions and 111 deletions

View File

@@ -125,8 +125,11 @@ namespace BlackCore
} }
VatServerType serverType; VatServerType serverType;
bool success = getCmdLineServerType(serverType); switch (m_server.getServerType())
if (!success) { serverType = CBuildConfig::isVatsimVersion() ? vatServerVatsim : vatServerLegacyFsd; } {
case CServer::ServerVatsim: serverType = vatServerVatsim; break;
default: serverType = vatServerLegacyFsd; break;
}
m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(), m_net.reset(Vat_CreateNetworkSession(serverType, sApp->swiftVersionChar(),
CBuildConfig::getVersion().majorVersion(), CBuildConfig::getVersion().minorVersion(), CBuildConfig::getVersion().majorVersion(), CBuildConfig::getVersion().minorVersion(),
@@ -389,6 +392,10 @@ namespace BlackCore
void CNetworkVatlib::presetServer(const CServer &server) void CNetworkVatlib::presetServer(const CServer &server)
{ {
Q_ASSERT_X(isDisconnected(), Q_FUNC_INFO, "Can't change server details while still connected"); Q_ASSERT_X(isDisconnected(), Q_FUNC_INFO, "Can't change server details while still connected");
// If the server type changed, we need to destroy the existing vatlib session
if (m_server.getServerType() != server.getServerType()) { m_net.reset(); }
m_server = server; m_server = server;
const QString codecName(server.getFsdSetup().getTextCodec()); const QString codecName(server.getFsdSetup().getTextCodec());
Q_ASSERT_X(!codecName.isEmpty(), Q_FUNC_INFO, "Missing code name"); Q_ASSERT_X(!codecName.isEmpty(), Q_FUNC_INFO, "Missing code name");
@@ -697,9 +704,7 @@ namespace BlackCore
static const QList<QCommandLineOption> opts static const QList<QCommandLineOption> opts
{ {
QCommandLineOption({ "idAndKey", "clientIdAndKey" }, QCommandLineOption({ "idAndKey", "clientIdAndKey" },
QCoreApplication::translate("networkvatlib", "Client id and key pair separated by ':', e.g. <id>:<key>."), "clientIdAndKey"), QCoreApplication::translate("networkvatlib", "Client id and key pair separated by ':', e.g. <id>:<key>."), "clientIdAndKey")
QCommandLineOption({ "s", "serverType" },
QCoreApplication::translate("networkvatlib", "FSD server type. Possible values: vatsim, fsd"), "serverType")
}; };
// only in not officially shipped versions // only in not officially shipped versions
@@ -719,23 +724,6 @@ namespace BlackCore
return true; return true;
} }
bool CNetworkVatlib::getCmdLineServerType(VatServerType &serverType) const
{
QString serverTypeAsString = sApp->getParserValue("serverType").toLower();
if (QString::compare(serverTypeAsString, "vatsim", Qt::CaseInsensitive) == 0)
{
serverType = vatServerVatsim;
return true;
}
if (QString::compare(serverTypeAsString, "fsd", Qt::CaseInsensitive) == 0)
{
serverType = vatServerLegacyFsd;
return true;
}
return false;
}
void CNetworkVatlib::sendCustomFsinnQuery(const BlackMisc::Aviation::CCallsign &callsign) void CNetworkVatlib::sendCustomFsinnQuery(const BlackMisc::Aviation::CCallsign &callsign)
{ {
Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected"); Q_ASSERT_X(isConnected(), Q_FUNC_INFO, "Can't send to server when disconnected");

View File

@@ -128,7 +128,6 @@ namespace BlackCore
private: private:
bool getCmdLineClientIdAndKey(int &id, QString &key) const; bool getCmdLineClientIdAndKey(int &id, QString &key) const;
bool getCmdLineServerType(VatServerType &serverType) const;
private slots: private slots:
void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign); void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign);

View File

@@ -26,6 +26,10 @@ namespace BlackGui
ui(new Ui::CNetworkServerForm) ui(new Ui::CNetworkServerForm)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cb_ServerType->clear();
ui->cb_ServerType->insertItem(0, QStringLiteral("VATSIM"), QVariant::fromValue(CServer::ServerVatsim));
ui->cb_ServerType->insertItem(1, QStringLiteral("FSC"), QVariant::fromValue(CServer::ServerFSC));
ui->cb_ServerType->insertItem(2, QStringLiteral("Legacy FSD"), QVariant::fromValue(CServer::ServerLegacyFSD));
ui->le_Port->setValidator(new QIntValidator(1, 65535, this)); ui->le_Port->setValidator(new QIntValidator(1, 65535, this));
} }
@@ -38,6 +42,12 @@ namespace BlackGui
ui->le_NetworkId->setText(user.getId()); ui->le_NetworkId->setText(user.getId());
ui->le_RealName->setText(user.getRealName()); ui->le_RealName->setText(user.getRealName());
ui->le_Name->setText(server.getName()); ui->le_Name->setText(server.getName());
switch (server.getServerType())
{
case CServer::ServerVatsim: ui->cb_ServerType->setCurrentIndex(0); break;
case CServer::ServerFSC: ui->cb_ServerType->setCurrentIndex(1); break;
case CServer::ServerLegacyFSD: ui->cb_ServerType->setCurrentIndex(2); break;
}
ui->le_Password->setText(user.getPassword()); ui->le_Password->setText(user.getPassword());
ui->le_Description->setText(server.getDescription()); ui->le_Description->setText(server.getDescription());
ui->le_Address->setText(server.getAddress()); ui->le_Address->setText(server.getAddress());
@@ -58,7 +68,9 @@ namespace BlackGui
ui->le_Description->text().trimmed().simplified(), ui->le_Description->text().trimmed().simplified(),
ui->le_Address->text().trimmed(), ui->le_Address->text().trimmed(),
ui->le_Port->text().trimmed().toInt(), ui->le_Port->text().trimmed().toInt(),
user user,
true,
ui->cb_ServerType->currentData().value<CServer::ServerType>()
); );
CFsdSetup setup(ui->form_ServerFsd->getValue()); CFsdSetup setup(ui->form_ServerFsd->getValue());
server.setFsdSetup(setup); server.setFsdSetup(setup);

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>275</width> <width>275</width>
<height>171</height> <height>172</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -75,75 +75,6 @@
<property name="spacing"> <property name="spacing">
<number>4</number> <number>4</number>
</property> </property>
<item row="2" column="1">
<widget class="QLineEdit" name="le_Address">
<property name="placeholderText">
<string>e.g. &quot;server.foo.com&quot;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="le_Description">
<property name="placeholderText">
<string>server description</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="le_RealName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>your name if required</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="le_Port">
<property name="text">
<string>6809</string>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_RealName">
<property name="text">
<string>Real name:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Address">
<property name="text">
<string>Addr./ port:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Description">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="le_Name">
<property name="placeholderText">
<string>server name</string>
</property>
</widget>
</item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="lbl_IdPassword"> <widget class="QLabel" name="lbl_IdPassword">
<property name="text"> <property name="text">
@@ -151,19 +82,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="2">
<widget class="QLineEdit" name="le_Password">
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>password</string>
</property>
</widget>
</item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="le_NetworkId"> <widget class="QLineEdit" name="le_NetworkId">
<property name="text"> <property name="text">
@@ -174,6 +92,91 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
<string>Name/Type:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_RealName">
<property name="text">
<string>Real name:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Description">
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Address">
<property name="text">
<string>Addr./ port:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="le_Name">
<property name="placeholderText">
<string>server name</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QComboBox" name="cb_ServerType"/>
</item>
<item row="1" column="1" colspan="3">
<widget class="QLineEdit" name="le_Description">
<property name="placeholderText">
<string>server description</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="le_Port">
<property name="text">
<string>6809</string>
</property>
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="le_Address">
<property name="placeholderText">
<string>e.g. &quot;server.foo.com&quot;</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QLineEdit" name="le_RealName">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>your name if required</string>
</property>
</widget>
</item>
<item row="4" column="2" colspan="2">
<widget class="QLineEdit" name="le_Password">
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>password</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@@ -222,6 +225,7 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>le_Name</tabstop> <tabstop>le_Name</tabstop>
<tabstop>cb_ServerType</tabstop>
<tabstop>le_Description</tabstop> <tabstop>le_Description</tabstop>
<tabstop>le_Address</tabstop> <tabstop>le_Address</tabstop>
<tabstop>le_Port</tabstop> <tabstop>le_Port</tabstop>

View File

@@ -29,6 +29,7 @@ namespace BlackGui
this->m_columns.addColumn(CColumn::standardString("port", CServer::IndexPort)); this->m_columns.addColumn(CColumn::standardString("port", CServer::IndexPort));
this->m_columns.addColumn(CColumn::standardString("realname", { CServer::IndexUser, CUser::IndexRealName})); this->m_columns.addColumn(CColumn::standardString("realname", { CServer::IndexUser, CUser::IndexRealName}));
this->m_columns.addColumn(CColumn::standardString("userid", { CServer::IndexUser, CUser::IndexId})); this->m_columns.addColumn(CColumn::standardString("userid", { CServer::IndexUser, CUser::IndexId}));
this->m_columns.addColumn(CColumn::standardString("type", CServer::IndexServerTypeAsString));
// force strings for translation in resource files // force strings for translation in resource files
(void)QT_TRANSLATE_NOOP("ServerListModel", "name"); (void)QT_TRANSLATE_NOOP("ServerListModel", "name");
@@ -37,6 +38,7 @@ namespace BlackGui
(void)QT_TRANSLATE_NOOP("ServerListModel", "port"); (void)QT_TRANSLATE_NOOP("ServerListModel", "port");
(void)QT_TRANSLATE_NOOP("ServerListModel", "realname"); (void)QT_TRANSLATE_NOOP("ServerListModel", "realname");
(void)QT_TRANSLATE_NOOP("ServerListModel", "userid"); (void)QT_TRANSLATE_NOOP("ServerListModel", "userid");
(void)QT_TRANSLATE_NOOP("ServerListModel", "type");
} }
} // class } // class

View File

@@ -23,8 +23,8 @@ namespace BlackMisc
{ {
namespace Network namespace Network
{ {
CServer::CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool 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_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 QString CServer::convertToQString(bool i18n) const
{ {
@@ -71,6 +71,17 @@ namespace BlackMisc
return m_port > 0 && !m_address.isEmpty(); 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 bool CServer::isConnected() const
{ {
return this->m_timestampMSecsSinceEpoch >= 0; return this->m_timestampMSecsSinceEpoch >= 0;
@@ -119,6 +130,10 @@ namespace BlackMisc
return this->m_fsdSetup.propertyByIndex(index.copyFrontRemoved()); return this->m_fsdSetup.propertyByIndex(index.copyFrontRemoved());
case IndexIsAcceptingConnections: case IndexIsAcceptingConnections:
return CVariant::fromValue(this->m_isAcceptingConnections); return CVariant::fromValue(this->m_isAcceptingConnections);
case IndexServerType:
return CVariant::fromValue(this->m_serverType);
case IndexServerTypeAsString:
return CVariant::fromValue(getServerTypeAsString());
default: default:
return CValueObject::propertyByIndex(index); return CValueObject::propertyByIndex(index);
} }
@@ -153,6 +168,9 @@ namespace BlackMisc
case IndexIsAcceptingConnections: case IndexIsAcceptingConnections:
this->setIsAcceptingConnections(variant.value<bool>()); this->setIsAcceptingConnections(variant.value<bool>());
break; break;
case IndexServerType:
this->setServerType(static_cast<ServerType>(variant.toInt()));
break;
default: default:
CValueObject::setPropertyByIndex(index, variant); CValueObject::setPropertyByIndex(index, variant);
break; break;

View File

@@ -44,14 +44,25 @@ namespace BlackMisc
IndexPort, IndexPort,
IndexUser, IndexUser,
IndexFsdSetup, IndexFsdSetup,
IndexIsAcceptingConnections IndexIsAcceptingConnections,
IndexServerType,
IndexServerTypeAsString
};
//! Server Type
enum ServerType
{
ServerVatsim,
ServerFSC,
ServerLegacyFSD
}; };
//! Default constructor. //! Default constructor.
CServer() {} CServer() {}
//! Constructor. //! 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. //! Get address.
const QString &getAddress() const { return m_address; } const QString &getAddress() const { return m_address; }
@@ -110,6 +121,15 @@ namespace BlackMisc
//! Set setup //! Set setup
void setFsdSetup(const CFsdSetup &setup) { this->m_fsdSetup = 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 //! Connected since
QDateTime getConnectedSince() const { return this->getUtcTimestamp(); } QDateTime getConnectedSince() const { return this->getUtcTimestamp(); }
@@ -148,6 +168,7 @@ namespace BlackMisc
CUser m_user; CUser m_user;
CFsdSetup m_fsdSetup; CFsdSetup m_fsdSetup;
bool m_isAcceptingConnections = true; //!< disable server for connections bool m_isAcceptingConnections = true; //!< disable server for connections
ServerType m_serverType = ServerVatsim;
BLACK_METACLASS( BLACK_METACLASS(
CServer, CServer,
@@ -158,6 +179,7 @@ namespace BlackMisc
BLACK_METAMEMBER(user), BLACK_METAMEMBER(user),
BLACK_METAMEMBER(fsdSetup), BLACK_METAMEMBER(fsdSetup),
BLACK_METAMEMBER(isAcceptingConnections), BLACK_METAMEMBER(isAcceptingConnections),
BLACK_METAMEMBER(serverType),
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison) BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForJson | DisabledForComparison)
); );
}; };
@@ -165,5 +187,6 @@ namespace BlackMisc
} // namespace } // namespace
Q_DECLARE_METATYPE(BlackMisc::Network::CServer) Q_DECLARE_METATYPE(BlackMisc::Network::CServer)
Q_DECLARE_METATYPE(BlackMisc::Network::CServer::ServerType)
#endif // guard #endif // guard