mirror of
https://github.com/Rosalie241/RMG.git
synced 2026-07-11 01:24:01 +02:00
RMG: add IPv4 resolver to NetplayCommon and use it
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QFileInfo>
|
||||
#include <QFile>
|
||||
#include <QHostInfo>
|
||||
|
||||
#include <RMG-Core/Settings.hpp>
|
||||
|
||||
@@ -254,17 +253,9 @@ void CreateNetplaySessionDialog::on_serverComboBox_currentIndexChanged(int index
|
||||
this->pingLineEdit->setText("Calculating...");
|
||||
|
||||
QString address = this->serverComboBox->itemData(index).toString();
|
||||
QUrl url(address);
|
||||
QHostInfo hostInfo = QHostInfo::fromName(url.host());
|
||||
for (const QHostAddress &resolvedAddr : hostInfo.addresses())
|
||||
if (!NetplayCommon::ConnectToIPv4Server(address, this->webSocket))
|
||||
{
|
||||
// mupen64plus-core only supports IPv4 (due to SDL2_net)
|
||||
if (resolvedAddr.protocol() == QAbstractSocket::IPv4Protocol)
|
||||
{
|
||||
url.setHost(resolvedAddr.toString());
|
||||
this->webSocket->open(url);
|
||||
return;
|
||||
}
|
||||
QtMessageBox::Error(this, "Failed to find IPv4 address of server");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <QByteArray>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include <QHostInfo>
|
||||
#include <QUrl>
|
||||
|
||||
#include <RMG-Core/Settings.hpp>
|
||||
#include <RMG-Core/Plugins.hpp>
|
||||
@@ -108,3 +110,23 @@ void NetplayCommon::RestoreSelectedServer(QComboBox* comboBox)
|
||||
comboBox->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool NetplayCommon::ConnectToIPv4Server(QString address, QWebSocket* webSocket)
|
||||
{
|
||||
QUrl addressUrl(address);
|
||||
QHostInfo hostInfo = QHostInfo::fromName(addressUrl.host());
|
||||
|
||||
for (const QHostAddress &resolvedAddr : hostInfo.addresses())
|
||||
{
|
||||
// mupen64plus-core only supports IPv4 (due to SDL2_net)
|
||||
if (resolvedAddr.protocol() == QAbstractSocket::IPv4Protocol)
|
||||
{
|
||||
addressUrl.setHost(resolvedAddr.toString());
|
||||
webSocket->open(addressUrl);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
webSocket->close();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QWebSocket>
|
||||
#include <QComboBox>
|
||||
#include <QString>
|
||||
|
||||
@@ -32,6 +33,9 @@ namespace NetplayCommon
|
||||
|
||||
// Restores previously selected server
|
||||
void RestoreSelectedServer(QComboBox* comboBox);
|
||||
|
||||
// Attempts to connect the web socket to the given address using IPv4
|
||||
bool ConnectToIPv4Server(QString address, QWebSocket* webSocket);
|
||||
}
|
||||
|
||||
#endif // NETPLAYCOMMON_HPP
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QFile>
|
||||
#include <QHostInfo>
|
||||
|
||||
#include <RMG-Core/Settings.hpp>
|
||||
#include <RMG-Core/Rom.hpp>
|
||||
@@ -325,21 +324,13 @@ void NetplaySessionBrowserDialog::on_serverComboBox_currentIndexChanged(int inde
|
||||
}
|
||||
|
||||
this->pingLineEdit->setText("Calculating...");
|
||||
|
||||
this->sessionBrowserWidget->StartRefresh();
|
||||
|
||||
QString address = this->serverComboBox->itemData(index).toString();
|
||||
QUrl url(address);
|
||||
QHostInfo hostInfo = QHostInfo::fromName(url.host());
|
||||
for (const QHostAddress &resolvedAddr : hostInfo.addresses())
|
||||
if (!NetplayCommon::ConnectToIPv4Server(address, this->webSocket))
|
||||
{
|
||||
// mupen64plus-core only supports IPv4 (due to SDL2_net)
|
||||
if (resolvedAddr.protocol() == QAbstractSocket::IPv4Protocol)
|
||||
{
|
||||
url.setHost(resolvedAddr.toString());
|
||||
this->webSocket->open(url);
|
||||
return;
|
||||
}
|
||||
this->sessionBrowserWidget->Reset();
|
||||
QtMessageBox::Error(this, "Failed to find IPv4 address of server");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user