Merge pull request #7573 from Techjar/netplay-dialog-external-ip
Qt/NetPlayDialog: Add external IP to interface combo box
This commit is contained in:
commit
749367794b
|
@ -69,6 +69,7 @@ NetPlayDialog::NetPlayDialog(QWidget* parent)
|
||||||
m_pad_mapping = new PadMappingDialog(this);
|
m_pad_mapping = new PadMappingDialog(this);
|
||||||
m_md5_dialog = new MD5Dialog(this);
|
m_md5_dialog = new MD5Dialog(this);
|
||||||
|
|
||||||
|
ResetExternalIP();
|
||||||
CreateChatLayout();
|
CreateChatLayout();
|
||||||
CreatePlayersLayout();
|
CreatePlayersLayout();
|
||||||
CreateMainLayout();
|
CreateMainLayout();
|
||||||
|
@ -497,6 +498,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
|
||||||
{
|
{
|
||||||
if (use_traversal)
|
if (use_traversal)
|
||||||
m_room_box->addItem(tr("Room ID"));
|
m_room_box->addItem(tr("Room ID"));
|
||||||
|
m_room_box->addItem(tr("External"));
|
||||||
|
|
||||||
for (const auto& iface : Settings::Instance().GetNetPlayServer()->GetInterfaceSet())
|
for (const auto& iface : Settings::Instance().GetNetPlayServer()->GetInterfaceSet())
|
||||||
{
|
{
|
||||||
|
@ -528,6 +530,21 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetPlayDialog::ResetExternalIP()
|
||||||
|
{
|
||||||
|
m_external_ip_address = Common::Lazy<std::string>([]() -> std::string {
|
||||||
|
Common::HttpRequest request;
|
||||||
|
// ENet does not support IPv6, so IPv4 has to be used
|
||||||
|
request.UseIPv4();
|
||||||
|
Common::HttpRequest::Response response =
|
||||||
|
request.Get("https://ip.dolphin-emu.org/", {{"X-Is-Dolphin", "1"}});
|
||||||
|
|
||||||
|
if (response.has_value())
|
||||||
|
return std::string(response->begin(), response->end());
|
||||||
|
return "";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void NetPlayDialog::UpdateDiscordPresence()
|
void NetPlayDialog::UpdateDiscordPresence()
|
||||||
{
|
{
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
|
@ -555,23 +572,13 @@ void NetPlayDialog::UpdateDiscordPresence()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_external_ip_address.empty())
|
if (m_external_ip_address->empty())
|
||||||
{
|
return use_default();
|
||||||
Common::HttpRequest request;
|
|
||||||
// ENet does not support IPv6, so IPv4 has to be used
|
|
||||||
request.UseIPv4();
|
|
||||||
Common::HttpRequest::Response response =
|
|
||||||
request.Get("https://ip.dolphin-emu.org/", {{"X-Is-Dolphin", "1"}});
|
|
||||||
|
|
||||||
if (!response.has_value())
|
|
||||||
return use_default();
|
|
||||||
m_external_ip_address = std::string(response->begin(), response->end());
|
|
||||||
}
|
|
||||||
const int port = Settings::Instance().GetNetPlayServer()->GetPort();
|
const int port = Settings::Instance().GetNetPlayServer()->GetPort();
|
||||||
|
|
||||||
Discord::UpdateDiscordPresence(
|
Discord::UpdateDiscordPresence(
|
||||||
m_player_count, Discord::SecretType::IPAddress,
|
m_player_count, Discord::SecretType::IPAddress,
|
||||||
Discord::CreateSecretFromIPAddress(m_external_ip_address, port), m_current_game);
|
Discord::CreateSecretFromIPAddress(*m_external_ip_address, port), m_current_game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -683,10 +690,30 @@ void NetPlayDialog::UpdateGUI()
|
||||||
}
|
}
|
||||||
else if (server)
|
else if (server)
|
||||||
{
|
{
|
||||||
m_hostcode_label->setText(QString::fromStdString(
|
if (m_room_box->currentIndex() == (m_use_traversal ? 1 : 0))
|
||||||
server->GetInterfaceHost(m_room_box->currentData().toString().toStdString())));
|
{
|
||||||
|
if (!m_external_ip_address->empty())
|
||||||
|
{
|
||||||
|
const int port = Settings::Instance().GetNetPlayServer()->GetPort();
|
||||||
|
m_hostcode_label->setText(QStringLiteral("%1:%2").arg(
|
||||||
|
QString::fromStdString(*m_external_ip_address), QString::number(port)));
|
||||||
|
m_hostcode_action_button->setEnabled(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_hostcode_label->setText(tr("Unknown"));
|
||||||
|
m_hostcode_action_button->setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_hostcode_label->setText(QString::fromStdString(
|
||||||
|
server->GetInterfaceHost(m_room_box->currentData().toString().toStdString())));
|
||||||
|
m_hostcode_action_button->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
m_hostcode_action_button->setText(tr("Copy"));
|
m_hostcode_action_button->setText(tr("Copy"));
|
||||||
m_hostcode_action_button->setEnabled(true);
|
m_is_copy_button_retry = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_old_player_count != m_player_count)
|
if (m_old_player_count != m_player_count)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
#include "Common/Lazy.h"
|
||||||
#include "Core/NetPlayClient.h"
|
#include "Core/NetPlayClient.h"
|
||||||
#include "VideoCommon/OnScreenDisplay.h"
|
#include "VideoCommon/OnScreenDisplay.h"
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ private:
|
||||||
void OnStart();
|
void OnStart();
|
||||||
void DisplayMessage(const QString& msg, const std::string& color,
|
void DisplayMessage(const QString& msg, const std::string& color,
|
||||||
int duration = OSD::Duration::NORMAL);
|
int duration = OSD::Duration::NORMAL);
|
||||||
|
void ResetExternalIP();
|
||||||
void UpdateDiscordPresence();
|
void UpdateDiscordPresence();
|
||||||
void UpdateGUI();
|
void UpdateGUI();
|
||||||
void GameStatusChanged(bool running);
|
void GameStatusChanged(bool running);
|
||||||
|
@ -122,7 +124,7 @@ private:
|
||||||
MD5Dialog* m_md5_dialog;
|
MD5Dialog* m_md5_dialog;
|
||||||
PadMappingDialog* m_pad_mapping;
|
PadMappingDialog* m_pad_mapping;
|
||||||
std::string m_current_game;
|
std::string m_current_game;
|
||||||
std::string m_external_ip_address;
|
Common::Lazy<std::string> m_external_ip_address;
|
||||||
std::string m_nickname;
|
std::string m_nickname;
|
||||||
GameListModel* m_game_list_model = nullptr;
|
GameListModel* m_game_list_model = nullptr;
|
||||||
bool m_use_traversal = false;
|
bool m_use_traversal = false;
|
||||||
|
|
Loading…
Reference in New Issue