1
0
Fork 0

Initial MP support in the launcher.

This commit is contained in:
James Turner 2016-07-08 09:36:42 +01:00
parent 7e607b8403
commit 9650cf4e6a
3 changed files with 175 additions and 4 deletions

View file

@ -269,7 +269,7 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>8</number> <number>8</number>
</property> </property>
<item row="8" column="0"> <item row="9" column="0">
<widget class="QPushButton" name="restoreDefaultsButton"> <widget class="QPushButton" name="restoreDefaultsButton">
<property name="text"> <property name="text">
<string>Restore Defaults...</string> <string>Restore Defaults...</string>
@ -452,7 +452,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="7" column="0" colspan="2"> <item row="8" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>Additional options</string> <string>Additional options</string>
@ -480,7 +480,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="7" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -493,6 +493,64 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="0" colspan="2">
<widget class="QGroupBox" name="mpBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="title">
<string>Multi-player</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,2,0">
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Callsign:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Server:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mpCallsign">
<property name="maxLength">
<number>10</number>
</property>
<property name="placeholderText">
<string>G-FGFS</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>(Ten characters maximum)</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="mpServerCombo"/>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View file

@ -67,6 +67,7 @@
#include "PathsDialog.hxx" #include "PathsDialog.hxx"
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Navaids/NavDataCache.hxx> #include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx> #include <Navaids/navrecord.hxx>
#include <Navaids/SHPParser.hxx> #include <Navaids/SHPParser.hxx>
@ -75,6 +76,7 @@
#include <Main/fg_init.hxx> #include <Main/fg_init.hxx>
#include <Viewer/WindowBuilder.hxx> #include <Viewer/WindowBuilder.hxx>
#include <Network/HTTPClient.hxx> #include <Network/HTTPClient.hxx>
#include <Network/RemoteXMLRequest.hxx>
using namespace flightgear; using namespace flightgear;
using namespace simgear::pkg; using namespace simgear::pkg;
@ -495,7 +497,8 @@ QtLauncher::QtLauncher() :
QDialog(), QDialog(),
m_ui(NULL), m_ui(NULL),
m_subsystemIdleTimer(NULL), m_subsystemIdleTimer(NULL),
m_inAppMode(false) m_inAppMode(false),
m_doRestoreMPServer(false)
{ {
m_ui.reset(new Ui::Launcher); m_ui.reset(new Ui::Launcher);
m_ui->setupUi(this); m_ui->setupUi(this);
@ -627,6 +630,8 @@ QtLauncher::QtLauncher() :
checkOfficialCatalogMessage(); checkOfficialCatalogMessage();
restoreSettings(); restoreSettings();
onRefreshMPServers();
} }
QtLauncher::~QtLauncher() QtLauncher::~QtLauncher()
@ -719,6 +724,10 @@ void QtLauncher::restoreSettings()
maybeRestoreAircraftSelection(); maybeRestoreAircraftSelection();
m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString()); m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString());
m_ui->mpCallsign->setText(settings.value("mp-callsign").toString());
// don't restore MP server here, we do it after a refresh
m_doRestoreMPServer = true;
} }
void QtLauncher::delayedAircraftModelReset() void QtLauncher::delayedAircraftModelReset()
@ -757,6 +766,9 @@ void QtLauncher::saveSettings()
settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText()); settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText());
m_ui->location->saveSettings(); m_ui->location->saveSettings();
settings.setValue("mp-callsign", m_ui->mpCallsign->text());
settings.setValue("mp-server", m_ui->mpServerCombo->currentData());
} }
void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const
@ -831,6 +843,14 @@ void QtLauncher::onRun()
m_recentAircraft.pop_back(); m_recentAircraft.pop_back();
} }
if (m_ui->mpBox->isChecked()) {
opt->addOption("callsign", m_ui->mpCallsign->text().toStdString());
QString host = m_ui->mpServerCombo->currentData().toString();
globals->get_props()->setStringValue("/sim/multiplay/txhost", host.toStdString());
int port = findMPServerPort(host.toStdString());
globals->get_props()->setIntValue("/sim/multiplay/txport", port);
}
m_ui->location->setLocationOptions(); m_ui->location->setLocationOptions();
// time of day // time of day
@ -1257,6 +1277,86 @@ void QtLauncher::onOfficialCatalogMessageLink(QUrl link)
checkOfficialCatalogMessage(); checkOfficialCatalogMessage();
} }
void QtLauncher::onRefreshMPServers()
{
if (m_mpServerRequest.get()) {
return; // in-progress
}
string url(fgGetString("/sim/multiplay/serverlist-url",
"http://liveries.flightgear.org/mpstatus/mpservers.xml"));
if (url.empty()) {
SG_LOG(SG_IO, SG_ALERT, "do_multiplayer.refreshserverlist: no URL given");
return;
}
SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
m_mpServerRequest.reset(new RemoteXMLRequest(url, targetnode));
m_mpServerRequest->done(this, &QtLauncher::onRefreshMPServersDone);
m_mpServerRequest->fail(this, &QtLauncher::onRefreshMPServersFailed);
globals->get_subsystem<FGHTTPClient>()->makeRequest(m_mpServerRequest);
}
void QtLauncher::onRefreshMPServersDone(simgear::HTTP::Request*)
{
// parse the properties
SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
m_ui->mpServerCombo->clear();
for (int i=0; i<targetnode->nChildren(); ++i) {
SGPropertyNode* c = targetnode->getChild(i);
if (c->getName() != std::string("server")) {
continue;
}
QString name = QString::fromStdString(c->getStringValue("name"));
QString loc = QString::fromStdString(c->getStringValue("location"));
QString host = QString::fromStdString(c->getStringValue("hostname"));
m_ui->mpServerCombo->addItem(tr("%1 - %2").arg(name,loc), host);
}
if (m_doRestoreMPServer) {
QSettings settings;
int index = m_ui->mpServerCombo->findData(settings.value("mp-server"));
if (index >= 0) {
m_ui->mpServerCombo->setCurrentIndex(index);
}
}
m_mpServerRequest.clear();
}
void QtLauncher::onRefreshMPServersFailed(simgear::HTTP::Request*)
{
qWarning() << "refreshing MP servers failed:" << QString::fromStdString(m_mpServerRequest->responseReason());
m_mpServerRequest.clear();
}
void QtLauncher::onMPServerEdited(QString text)
{
// parse as server hostname + optional URL
}
int QtLauncher::findMPServerPort(const std::string& host)
{
SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
for (int i=0; i<targetnode->nChildren(); ++i) {
SGPropertyNode* c = targetnode->getChild(i);
if (c->getName() != std::string("server")) {
continue;
}
if (c->getStringValue("hostname") == host) {
return c->getIntValue("port");
}
}
return 0;
}
simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
{ {
if (uri.scheme() != "package") { if (uri.scheme() != "package") {

View file

@ -41,6 +41,7 @@ class AircraftProxyModel;
class AircraftItemModel; class AircraftItemModel;
class QCheckBox; class QCheckBox;
class CatalogListModel; class CatalogListModel;
class RemoteXMLRequest;
class QtLauncher : public QDialog class QtLauncher : public QDialog
{ {
@ -96,6 +97,11 @@ private slots:
void onRestoreDefaults(); void onRestoreDefaults();
void onDownloadDirChanged(); void onDownloadDirChanged();
void onRefreshMPServers();
void onMPServerEdited(QString text);
private: private:
/** /**
@ -118,6 +124,10 @@ private:
void checkOfficialCatalogMessage(); void checkOfficialCatalogMessage();
void onOfficialCatalogMessageLink(QUrl link); void onOfficialCatalogMessageLink(QUrl link);
void onRefreshMPServersDone(simgear::HTTP::Request*);
void onRefreshMPServersFailed(simgear::HTTP::Request*);
int findMPServerPort(const std::string& host);
// need to wait after a model reset before restoring selection and // need to wait after a model reset before restoring selection and
// scrolling, to give the view time it seems. // scrolling, to give the view time it seems.
void delayedAircraftModelReset(); void delayedAircraftModelReset();
@ -133,6 +143,9 @@ private:
bool m_inAppMode; bool m_inAppMode;
int m_ratingFilters[4]; int m_ratingFilters[4];
SGSharedPtr<RemoteXMLRequest> m_mpServerRequest;
bool m_doRestoreMPServer;
}; };
#endif // of FG_QTLAUNCHER_PRIVATE_HXX #endif // of FG_QTLAUNCHER_PRIVATE_HXX