Force IPv4 on external IP addresses
This commit is contained in:
parent
c2aedb7649
commit
158c0d54b1
|
@ -29,6 +29,7 @@ public:
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
void SetCookies(const std::string& cookies);
|
void SetCookies(const std::string& cookies);
|
||||||
|
void UseIPv4();
|
||||||
Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload,
|
Response Fetch(const std::string& url, Method method, const Headers& headers, const u8* payload,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
|
@ -62,6 +63,11 @@ void HttpRequest::SetCookies(const std::string& cookies)
|
||||||
m_impl->SetCookies(cookies);
|
m_impl->SetCookies(cookies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpRequest::UseIPv4()
|
||||||
|
{
|
||||||
|
m_impl->UseIPv4();
|
||||||
|
}
|
||||||
|
|
||||||
HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers)
|
HttpRequest::Response HttpRequest::Get(const std::string& url, const Headers& headers)
|
||||||
{
|
{
|
||||||
return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0);
|
return m_impl->Fetch(url, Impl::Method::GET, headers, nullptr, 0);
|
||||||
|
@ -136,6 +142,11 @@ void HttpRequest::Impl::SetCookies(const std::string& cookies)
|
||||||
curl_easy_setopt(m_curl.get(), CURLOPT_COOKIE, cookies.c_str());
|
curl_easy_setopt(m_curl.get(), CURLOPT_COOKIE, cookies.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HttpRequest::Impl::UseIPv4()
|
||||||
|
{
|
||||||
|
curl_easy_setopt(m_curl.get(), CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||||
|
}
|
||||||
|
|
||||||
static size_t CurlWriteCallback(char* data, size_t size, size_t nmemb, void* userdata)
|
static size_t CurlWriteCallback(char* data, size_t size, size_t nmemb, void* userdata)
|
||||||
{
|
{
|
||||||
auto* buffer = static_cast<std::vector<u8>*>(userdata);
|
auto* buffer = static_cast<std::vector<u8>*>(userdata);
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
using Headers = std::map<std::string, std::optional<std::string>>;
|
using Headers = std::map<std::string, std::optional<std::string>>;
|
||||||
|
|
||||||
void SetCookies(const std::string& cookies);
|
void SetCookies(const std::string& cookies);
|
||||||
|
void UseIPv4();
|
||||||
Response Get(const std::string& url, const Headers& headers = {});
|
Response Get(const std::string& url, const Headers& headers = {});
|
||||||
Response Post(const std::string& url, const std::vector<u8>& payload,
|
Response Post(const std::string& url, const std::vector<u8>& payload,
|
||||||
const Headers& headers = {});
|
const Headers& headers = {});
|
||||||
|
|
|
@ -4,16 +4,19 @@
|
||||||
|
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
|
|
||||||
|
#include "DolphinQt/DiscordHandler.h"
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "DolphinQt/DiscordHandler.h"
|
|
||||||
|
|
||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
|
|
||||||
#include "UICommon/DiscordPresence.h"
|
#include "UICommon/DiscordPresence.h"
|
||||||
|
|
||||||
|
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
||||||
|
#include "DolphinQt/QtUtils/RunOnObject.h"
|
||||||
|
|
||||||
DiscordHandler::DiscordHandler(QWidget* parent) : QObject{parent}, m_parent{parent}
|
DiscordHandler::DiscordHandler(QWidget* parent) : QObject{parent}, m_parent{parent}
|
||||||
{
|
{
|
||||||
connect(this, &DiscordHandler::JoinRequest, this, &DiscordHandler::ShowNewJoinRequest);
|
connect(this, &DiscordHandler::JoinRequest, this, &DiscordHandler::ShowNewJoinRequest);
|
||||||
|
@ -41,8 +44,7 @@ void DiscordHandler::Stop()
|
||||||
void DiscordHandler::DiscordJoinRequest(const char* id, const std::string& discord_tag,
|
void DiscordHandler::DiscordJoinRequest(const char* id, const std::string& discord_tag,
|
||||||
const char* avatar)
|
const char* avatar)
|
||||||
{
|
{
|
||||||
m_request_dialogs.emplace_front(m_parent, id, discord_tag, avatar);
|
emit DiscordHandler::JoinRequest(id, discord_tag, avatar);
|
||||||
emit DiscordHandler::JoinRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordHandler::DiscordJoin()
|
void DiscordHandler::DiscordJoin()
|
||||||
|
@ -50,9 +52,15 @@ void DiscordHandler::DiscordJoin()
|
||||||
emit DiscordHandler::Join();
|
emit DiscordHandler::Join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordHandler::ShowNewJoinRequest()
|
void DiscordHandler::ShowNewJoinRequest(const std::string& id, const std::string& discord_tag,
|
||||||
|
const std::string& avatar)
|
||||||
{
|
{
|
||||||
m_request_dialogs.front().show();
|
std::lock_guard<std::mutex> lock(m_request_dialogs_mutex);
|
||||||
|
m_request_dialogs.emplace_front(m_parent, id, discord_tag, avatar);
|
||||||
|
DiscordJoinRequestDialog& request_dialog = m_request_dialogs.front();
|
||||||
|
request_dialog.show();
|
||||||
|
request_dialog.raise();
|
||||||
|
request_dialog.activateWindow();
|
||||||
QApplication::alert(nullptr, DiscordJoinRequestDialog::s_max_lifetime_seconds * 1000);
|
QApplication::alert(nullptr, DiscordJoinRequestDialog::s_max_lifetime_seconds * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,14 +72,23 @@ void DiscordHandler::Run()
|
||||||
Discord::CallPendingCallbacks();
|
Discord::CallPendingCallbacks();
|
||||||
|
|
||||||
// close and remove dead requests
|
// close and remove dead requests
|
||||||
for (auto request_dialog = m_request_dialogs.rbegin();
|
|
||||||
request_dialog != m_request_dialogs.rend(); ++request_dialog)
|
|
||||||
{
|
{
|
||||||
if (std::time(nullptr) < request_dialog->GetCloseTimestamp())
|
std::lock_guard<std::mutex> lock(m_request_dialogs_mutex);
|
||||||
continue;
|
for (auto request_dialog = m_request_dialogs.begin();
|
||||||
request_dialog->close();
|
request_dialog != m_request_dialogs.end();)
|
||||||
std::advance(request_dialog, 1);
|
{
|
||||||
m_request_dialogs.erase(request_dialog.base());
|
if (std::time(nullptr) < request_dialog->GetCloseTimestamp())
|
||||||
|
{
|
||||||
|
++request_dialog;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RunOnObject(m_parent, [this, &request_dialog] {
|
||||||
|
request_dialog->close();
|
||||||
|
request_dialog = m_request_dialogs.erase(request_dialog);
|
||||||
|
return nullptr;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::SleepCurrentThread(1000 * 2);
|
Common::SleepCurrentThread(1000 * 2);
|
||||||
|
|
|
@ -4,22 +4,22 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Note using a ifdef around this class causes link issues with qt
|
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "Common/Flag.h"
|
#include "Common/Flag.h"
|
||||||
|
|
||||||
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
|
||||||
|
|
||||||
#include "UICommon/DiscordPresence.h"
|
#include "UICommon/DiscordPresence.h"
|
||||||
|
|
||||||
|
class DiscordJoinRequestDialog;
|
||||||
|
|
||||||
class DiscordHandler : public QObject, public Discord::Handler
|
class DiscordHandler : public QObject, public Discord::Handler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
public:
|
public:
|
||||||
explicit DiscordHandler(QWidget* parent);
|
explicit DiscordHandler(QWidget* parent);
|
||||||
~DiscordHandler();
|
~DiscordHandler();
|
||||||
|
@ -29,15 +29,21 @@ public:
|
||||||
void DiscordJoin() override;
|
void DiscordJoin() override;
|
||||||
void DiscordJoinRequest(const char* id, const std::string& discord_tag,
|
void DiscordJoinRequest(const char* id, const std::string& discord_tag,
|
||||||
const char* avatar) override;
|
const char* avatar) override;
|
||||||
void ShowNewJoinRequest();
|
void ShowNewJoinRequest(const std::string& id, const std::string& discord_tag,
|
||||||
|
const std::string& avatar);
|
||||||
|
#endif
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Join();
|
void Join();
|
||||||
void JoinRequest();
|
void JoinRequest(const std::string id, const std::string discord_tag, const std::string avatar);
|
||||||
|
|
||||||
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
private:
|
private:
|
||||||
void Run();
|
void Run();
|
||||||
QWidget* m_parent;
|
QWidget* m_parent;
|
||||||
Common::Flag m_stop_requested;
|
Common::Flag m_stop_requested;
|
||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
std::list<DiscordJoinRequestDialog> m_request_dialogs;
|
std::list<DiscordJoinRequestDialog> m_request_dialogs;
|
||||||
|
std::mutex m_request_dialogs_mutex;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
|
|
||||||
|
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
||||||
|
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
@ -14,11 +16,9 @@
|
||||||
#include "Common/HttpRequest.h"
|
#include "Common/HttpRequest.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
#include "DolphinQt/DiscordJoinRequestDialog.h"
|
DiscordJoinRequestDialog::DiscordJoinRequestDialog(QWidget* parent, const std::string& id,
|
||||||
|
|
||||||
DiscordJoinRequestDialog::DiscordJoinRequestDialog(QWidget* parent, const char* id,
|
|
||||||
const std::string& discord_tag,
|
const std::string& discord_tag,
|
||||||
const char* avatar)
|
const std::string& avatar)
|
||||||
: QDialog(parent), m_user_id(id), m_close_timestamp(std::time(nullptr) + s_max_lifetime_seconds)
|
: QDialog(parent), m_user_id(id), m_close_timestamp(std::time(nullptr) + s_max_lifetime_seconds)
|
||||||
{
|
{
|
||||||
setWindowTitle(tr("Request to Join Your Party"));
|
setWindowTitle(tr("Request to Join Your Party"));
|
||||||
|
@ -26,10 +26,10 @@ DiscordJoinRequestDialog::DiscordJoinRequestDialog(QWidget* parent, const char*
|
||||||
|
|
||||||
QPixmap avatar_pixmap;
|
QPixmap avatar_pixmap;
|
||||||
|
|
||||||
if (avatar[0] != '\0')
|
if (!avatar.empty())
|
||||||
{
|
{
|
||||||
const std::string avatar_endpoint =
|
const std::string avatar_endpoint = StringFromFormat(
|
||||||
StringFromFormat("https://cdn.discordapp.com/avatars/%s/%s.png", id, avatar);
|
"https://cdn.discordapp.com/avatars/%s/%s.png", id.c_str(), avatar.c_str());
|
||||||
|
|
||||||
Common::HttpRequest request;
|
Common::HttpRequest request;
|
||||||
Common::HttpRequest::Response response = request.Get(avatar_endpoint);
|
Common::HttpRequest::Response response = request.Get(avatar_endpoint);
|
||||||
|
@ -38,7 +38,7 @@ DiscordJoinRequestDialog::DiscordJoinRequestDialog(QWidget* parent, const char*
|
||||||
avatar_pixmap.loadFromData(response->data(), static_cast<uint>(response->size()), "png");
|
avatar_pixmap.loadFromData(response->data(), static_cast<uint>(response->size()), "png");
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateMainLayout(discord_tag, avatar_pixmap);
|
CreateLayout(discord_tag, avatar_pixmap);
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +47,18 @@ std::time_t DiscordJoinRequestDialog::GetCloseTimestamp() const
|
||||||
return m_close_timestamp;
|
return m_close_timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordJoinRequestDialog::CreateMainLayout(const std::string& discord_tag,
|
void DiscordJoinRequestDialog::CreateLayout(const std::string& discord_tag, const QPixmap& avatar)
|
||||||
const QPixmap& avatar)
|
|
||||||
{
|
{
|
||||||
m_main_layout = new QGridLayout;
|
m_main_layout = new QGridLayout;
|
||||||
|
|
||||||
m_invite_button = new QPushButton(QString::fromWCharArray(L"\u2714 Invite"));
|
m_invite_button = new QPushButton(tr("\u2714 Invite"));
|
||||||
m_decline_button = new QPushButton(QString::fromWCharArray(L"\u2716 Decline"));
|
m_decline_button = new QPushButton(tr("\u2716 Decline"));
|
||||||
m_ignore_button = new QPushButton(tr("Ignore"));
|
m_ignore_button = new QPushButton(tr("Ignore"));
|
||||||
|
|
||||||
|
QLabel* text =
|
||||||
|
new QLabel(tr("%1\nwants to join your party.").arg(QString::fromStdString(discord_tag)));
|
||||||
|
text->setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
if (!avatar.isNull())
|
if (!avatar.isNull())
|
||||||
{
|
{
|
||||||
QLabel* picture = new QLabel();
|
QLabel* picture = new QLabel();
|
||||||
|
@ -63,9 +66,7 @@ void DiscordJoinRequestDialog::CreateMainLayout(const std::string& discord_tag,
|
||||||
m_main_layout->addWidget(picture, 1, 0, 1, 3, Qt::AlignHCenter);
|
m_main_layout->addWidget(picture, 1, 0, 1, 3, Qt::AlignHCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_main_layout->addWidget(new QLabel(tr(discord_tag.c_str())), 2, 0, 3, 3, Qt::AlignHCenter);
|
m_main_layout->addWidget(text, 2, 0, 3, 3, Qt::AlignHCenter);
|
||||||
m_main_layout->addWidget(new QLabel(tr("wants to join your party.")), 4, 0, 4, 3,
|
|
||||||
Qt::AlignHCenter);
|
|
||||||
m_main_layout->addWidget(m_invite_button, 8, 0);
|
m_main_layout->addWidget(m_invite_button, 8, 0);
|
||||||
m_main_layout->addWidget(m_decline_button, 8, 1);
|
m_main_layout->addWidget(m_decline_button, 8, 1);
|
||||||
m_main_layout->addWidget(m_ignore_button, 8, 2);
|
m_main_layout->addWidget(m_ignore_button, 8, 2);
|
||||||
|
@ -75,15 +76,15 @@ void DiscordJoinRequestDialog::CreateMainLayout(const std::string& discord_tag,
|
||||||
|
|
||||||
void DiscordJoinRequestDialog::ConnectWidgets()
|
void DiscordJoinRequestDialog::ConnectWidgets()
|
||||||
{
|
{
|
||||||
connect(m_invite_button, &QPushButton::clicked, [this] { Reply(DISCORD_REPLY_YES); });
|
connect(m_invite_button, &QPushButton::pressed, [this] { Reply(DISCORD_REPLY_YES); });
|
||||||
connect(m_decline_button, &QPushButton::clicked, [this] { Reply(DISCORD_REPLY_NO); });
|
connect(m_decline_button, &QPushButton::pressed, [this] { Reply(DISCORD_REPLY_NO); });
|
||||||
connect(m_ignore_button, &QPushButton::clicked, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
connect(m_ignore_button, &QPushButton::pressed, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
||||||
connect(this, &QDialog::rejected, this, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
connect(this, &QDialog::rejected, this, [this] { Reply(DISCORD_REPLY_IGNORE); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordJoinRequestDialog::Reply(int reply)
|
void DiscordJoinRequestDialog::Reply(int reply)
|
||||||
{
|
{
|
||||||
Discord_Respond(m_user_id, reply);
|
Discord_Respond(m_user_id.c_str(), reply);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,14 @@ class DiscordJoinRequestDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit DiscordJoinRequestDialog(QWidget* parent, const char* id, const std::string& discord_tag,
|
explicit DiscordJoinRequestDialog(QWidget* parent, const std::string& id,
|
||||||
const char* avatar);
|
const std::string& discord_tag, const std::string& avatar);
|
||||||
std::time_t GetCloseTimestamp() const;
|
std::time_t GetCloseTimestamp() const;
|
||||||
|
|
||||||
static constexpr std::time_t s_max_lifetime_seconds = 30;
|
static constexpr std::time_t s_max_lifetime_seconds = 30;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateMainLayout(const std::string& discord_tag, const QPixmap& avatar);
|
void CreateLayout(const std::string& discord_tag, const QPixmap& avatar);
|
||||||
void ConnectWidgets();
|
void ConnectWidgets();
|
||||||
void Reply(int reply);
|
void Reply(int reply);
|
||||||
|
|
||||||
|
@ -30,6 +30,6 @@ private:
|
||||||
QPushButton* m_decline_button;
|
QPushButton* m_decline_button;
|
||||||
QPushButton* m_ignore_button;
|
QPushButton* m_ignore_button;
|
||||||
|
|
||||||
const char* const m_user_id;
|
const std::string m_user_id;
|
||||||
const std::time_t m_close_timestamp;
|
const std::time_t m_close_timestamp;
|
||||||
};
|
};
|
||||||
|
|
|
@ -640,7 +640,8 @@ void MainWindow::OnStopComplete()
|
||||||
HideRenderWidget();
|
HideRenderWidget();
|
||||||
EnableScreenSaver(true);
|
EnableScreenSaver(true);
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
Discord::UpdateDiscordPresence();
|
if (!m_netplay_dialog->isVisible())
|
||||||
|
Discord::UpdateDiscordPresence();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SetFullScreenResolution(false);
|
SetFullScreenResolution(false);
|
||||||
|
@ -794,7 +795,8 @@ void MainWindow::StartGame(std::unique_ptr<BootParameters>&& parameters)
|
||||||
|
|
||||||
ShowRenderWidget();
|
ShowRenderWidget();
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
Discord::UpdateDiscordPresence();
|
if (!NetPlay::IsNetPlayRunning())
|
||||||
|
Discord::UpdateDiscordPresence();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SConfig::GetInstance().bFullscreen)
|
if (SConfig::GetInstance().bFullscreen)
|
||||||
|
@ -1045,7 +1047,6 @@ void MainWindow::NetPlayInit()
|
||||||
{
|
{
|
||||||
m_netplay_setup_dialog = new NetPlaySetupDialog(this);
|
m_netplay_setup_dialog = new NetPlaySetupDialog(this);
|
||||||
m_netplay_dialog = new NetPlayDialog;
|
m_netplay_dialog = new NetPlayDialog;
|
||||||
m_netplay_dialog = new NetPlayDialog(this);
|
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
m_netplay_discord = new DiscordHandler(this);
|
m_netplay_discord = new DiscordHandler(this);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1180,7 +1181,9 @@ void MainWindow::NetPlayQuit()
|
||||||
{
|
{
|
||||||
Settings::Instance().ResetNetPlayClient();
|
Settings::Instance().ResetNetPlayClient();
|
||||||
Settings::Instance().ResetNetPlayServer();
|
Settings::Instance().ResetNetPlayServer();
|
||||||
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
Discord::UpdateDiscordPresence();
|
Discord::UpdateDiscordPresence();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::EnableScreenSaver(bool enable)
|
void MainWindow::EnableScreenSaver(bool enable)
|
||||||
|
|
|
@ -473,40 +473,44 @@ void NetPlayDialog::UpdateDiscordPresence()
|
||||||
Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::Empty, "", m_current_game);
|
Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::Empty, "", m_current_game);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (g_TraversalClient)
|
if (Core::IsRunning())
|
||||||
{
|
return use_default();
|
||||||
const auto host_id = g_TraversalClient->GetHostID();
|
|
||||||
if (host_id == decltype(host_id)())
|
|
||||||
return use_default();
|
|
||||||
|
|
||||||
Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::RoomID,
|
if (IsHosting())
|
||||||
std::string(host_id.begin(), host_id.end()), m_current_game);
|
|
||||||
}
|
|
||||||
else if (IsHosting())
|
|
||||||
{
|
{
|
||||||
if (m_exernal_ip_address.empty())
|
if (g_TraversalClient)
|
||||||
{
|
{
|
||||||
Common::HttpRequest request;
|
const auto host_id = g_TraversalClient->GetHostID();
|
||||||
Common::HttpRequest::Response response =
|
if (host_id[0] == '\0')
|
||||||
request.Get("https://ip.dolphin-emu.org/", {{"X-Is-Dolphin", "1"}});
|
|
||||||
|
|
||||||
if (!response.has_value())
|
|
||||||
return use_default();
|
return use_default();
|
||||||
m_exernal_ip_address = std::string(response->begin(), response->end());
|
|
||||||
}
|
|
||||||
const int port = Settings::Instance().GetNetPlayServer()->GetPort();
|
|
||||||
|
|
||||||
Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::IPAddress,
|
Discord::UpdateDiscordPresence(m_player_count, Discord::SecretType::RoomID,
|
||||||
Discord::CreateSecretFromIPAddress(m_exernal_ip_address, port),
|
std::string(host_id.begin(), host_id.end()), m_current_game);
|
||||||
m_current_game);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_external_ip_address.empty())
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
Discord::UpdateDiscordPresence(
|
||||||
|
m_player_count, Discord::SecretType::IPAddress,
|
||||||
|
Discord::CreateSecretFromIPAddress(m_external_ip_address, port), m_current_game);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Discord::UpdateDiscordPresence(
|
use_default();
|
||||||
m_player_count, Discord::SecretType::IPAddress,
|
|
||||||
Discord::CreateSecretFromIPAddress(Config::Get(Config::NETPLAY_HOST_CODE),
|
|
||||||
Config::Get(Config::NETPLAY_HOST_PORT)),
|
|
||||||
m_current_game);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -729,11 +733,13 @@ void NetPlayDialog::OnMsgStartGame()
|
||||||
auto client = Settings::Instance().GetNetPlayClient();
|
auto client = Settings::Instance().GetNetPlayClient();
|
||||||
if (client)
|
if (client)
|
||||||
client->StartGame(FindGame(m_current_game));
|
client->StartGame(FindGame(m_current_game));
|
||||||
|
UpdateDiscordPresence();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetPlayDialog::OnMsgStopGame()
|
void NetPlayDialog::OnMsgStopGame()
|
||||||
{
|
{
|
||||||
|
QueueOnObject(this, [this] { UpdateDiscordPresence(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
|
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
|
||||||
|
|
|
@ -115,7 +115,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_exernal_ip_address;
|
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;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "UICommon/DiscordPresence.h"
|
||||||
|
|
||||||
#include "Common/Hash.h"
|
#include "Common/Hash.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
|
@ -9,8 +11,6 @@
|
||||||
#include "Core/Config/UISettings.h"
|
#include "Core/Config/UISettings.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
|
||||||
#include "UICommon/DiscordPresence.h"
|
|
||||||
|
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
@ -44,7 +44,7 @@ static void HandleDiscordJoin(const char* join_secret)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Config::Get(Config::NETPLAY_NICKNAME) == Config::NETPLAY_NICKNAME.default_value)
|
if (Config::Get(Config::NETPLAY_NICKNAME) == Config::NETPLAY_NICKNAME.default_value)
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_NICKNAME, username);
|
Config::SetCurrent(Config::NETPLAY_NICKNAME, username);
|
||||||
|
|
||||||
std::string secret(join_secret);
|
std::string secret(join_secret);
|
||||||
|
|
||||||
|
@ -59,22 +59,23 @@ static void HandleDiscordJoin(const char* join_secret)
|
||||||
|
|
||||||
case SecretType::IPAddress:
|
case SecretType::IPAddress:
|
||||||
{
|
{
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_CHOICE, "direct");
|
// SetBaseOrCurrent will save the ip address, which isn't what's wanted in this situation
|
||||||
|
Config::SetCurrent(Config::NETPLAY_TRAVERSAL_CHOICE, "direct");
|
||||||
|
|
||||||
std::string host = secret.substr(offset, secret.find_last_of(':') - offset);
|
std::string host = secret.substr(offset, secret.find_last_of(':') - offset);
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_HOST_CODE, host);
|
Config::SetCurrent(Config::NETPLAY_ADDRESS, host);
|
||||||
|
|
||||||
offset += host.length();
|
offset += host.length();
|
||||||
if (secret[offset] == ':')
|
if (secret[offset] == ':')
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_CONNECT_PORT, std::stoul(secret.substr(offset + 1)));
|
Config::SetCurrent(Config::NETPLAY_CONNECT_PORT, std::stoul(secret.substr(offset + 1)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SecretType::RoomID:
|
case SecretType::RoomID:
|
||||||
{
|
{
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_TRAVERSAL_CHOICE, "traversal");
|
Config::SetCurrent(Config::NETPLAY_TRAVERSAL_CHOICE, "traversal");
|
||||||
|
|
||||||
Config::SetBaseOrCurrent(Config::NETPLAY_HOST_CODE, secret.substr(offset));
|
Config::SetCurrent(Config::NETPLAY_HOST_CODE, secret.substr(offset));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +121,7 @@ void InitNetPlayFunctionality(Handler& handler)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDiscordPresence(const int party_size, SecretType type, const std::string& secret,
|
void UpdateDiscordPresence(int party_size, SecretType type, const std::string& secret,
|
||||||
const std::string& current_game)
|
const std::string& current_game)
|
||||||
{
|
{
|
||||||
#ifdef USE_DISCORD_PRESENCE
|
#ifdef USE_DISCORD_PRESENCE
|
||||||
|
@ -136,7 +137,7 @@ void UpdateDiscordPresence(const int party_size, SecretType type, const std::str
|
||||||
discord_presence.details = title.empty() ? "Not in-game" : title.c_str();
|
discord_presence.details = title.empty() ? "Not in-game" : title.c_str();
|
||||||
discord_presence.startTimestamp = std::time(nullptr);
|
discord_presence.startTimestamp = std::time(nullptr);
|
||||||
|
|
||||||
if (0 < party_size)
|
if (party_size > 0)
|
||||||
{
|
{
|
||||||
if (party_size < 4)
|
if (party_size < 4)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,13 +5,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
using JoinFunction = std::function<void()>;
|
|
||||||
using JoinRequestFunction =
|
|
||||||
std::function<void(const char* id, const std::string& discord_tag, const char* avatar)>;
|
|
||||||
|
|
||||||
class Handler
|
class Handler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue