mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-26 07:39:45 -06:00
Add Discord Join Net Play functionally
This commit is contained in:
@ -8,6 +8,7 @@ set(CMAKE_AUTOMOC ON)
|
||||
add_executable(dolphin-emu
|
||||
AboutDialog.cpp
|
||||
CheatsManager.cpp
|
||||
DiscordHandler.cpp
|
||||
FIFO/FIFOPlayerWindow.cpp
|
||||
FIFO/FIFOAnalyzer.cpp
|
||||
HotkeyScheduler.cpp
|
||||
|
@ -107,6 +107,7 @@
|
||||
<QtMoc Include="Config\PatchesWidget.h" />
|
||||
<QtMoc Include="Config\PropertiesDialog.h" />
|
||||
<QtMoc Include="Config\SettingsWindow.h" />
|
||||
<QtMoc Include="DiscordHandler.h" />
|
||||
<QtMoc Include="FIFO\FIFOAnalyzer.h" />
|
||||
<QtMoc Include="FIFO\FIFOPlayerWindow.h" />
|
||||
<QtMoc Include="TAS\GCTASInputWindow.h" />
|
||||
@ -175,6 +176,7 @@
|
||||
<ClCompile Include="$(QtMocOutPrefix)CodeViewWidget.cpp" />
|
||||
<ClCompile Include="$(QtMocOutPrefix)CodeWidget.cpp" />
|
||||
<ClCompile Include="$(QtMocOutPrefix)ControllersWindow.cpp" />
|
||||
<ClCompile Include="$(QtMocOutPrefix)DiscordHandler.cpp" />
|
||||
<ClCompile Include="$(QtMocOutPrefix)DoubleClickEventFilter.cpp" />
|
||||
<ClCompile Include="$(QtMocOutPrefix)ElidedButton.cpp" />
|
||||
<ClCompile Include="$(QtMocOutPrefix)FlowLayout.cpp" />
|
||||
@ -320,6 +322,7 @@
|
||||
<ClCompile Include="Debugger\JITWidget.cpp" />
|
||||
<ClCompile Include="Debugger\MemoryWidget.cpp" />
|
||||
<ClCompile Include="Debugger\MemoryViewWidget.cpp" />
|
||||
<ClCompile Include="DiscordHandler.cpp" />
|
||||
<ClCompile Include="FIFO\FIFOAnalyzer.cpp" />
|
||||
<ClCompile Include="FIFO\FIFOPlayerWindow.cpp" />
|
||||
<ClCompile Include="QtUtils\WinIconHelper.cpp" />
|
||||
|
@ -67,6 +67,7 @@
|
||||
#include "DolphinQt/Debugger/MemoryWidget.h"
|
||||
#include "DolphinQt/Debugger/RegisterWidget.h"
|
||||
#include "DolphinQt/Debugger/WatchWidget.h"
|
||||
#include "DolphinQt/DiscordHandler.h"
|
||||
#include "DolphinQt/FIFO/FIFOPlayerWindow.h"
|
||||
#include "DolphinQt/GCMemcardManager.h"
|
||||
#include "DolphinQt/GameList/GameList.h"
|
||||
@ -1043,7 +1044,12 @@ void MainWindow::BootWiiSystemMenu()
|
||||
void MainWindow::NetPlayInit()
|
||||
{
|
||||
m_netplay_setup_dialog = new NetPlaySetupDialog(this);
|
||||
<<<<<<< HEAD:Source/Core/DolphinQt/MainWindow.cpp
|
||||
m_netplay_dialog = new NetPlayDialog;
|
||||
=======
|
||||
m_netplay_dialog = new NetPlayDialog(this);
|
||||
m_netplay_discord = new DiscordHandler();
|
||||
>>>>>>> Add Discord Join Net Play functionally:Source/Core/DolphinQt2/MainWindow.cpp
|
||||
|
||||
connect(m_netplay_dialog, &NetPlayDialog::Boot, this,
|
||||
[this](const QString& path) { StartGame(path); });
|
||||
@ -1051,6 +1057,10 @@ void MainWindow::NetPlayInit()
|
||||
connect(m_netplay_dialog, &NetPlayDialog::rejected, this, &MainWindow::NetPlayQuit);
|
||||
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Join, this, &MainWindow::NetPlayJoin);
|
||||
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Host, this, &MainWindow::NetPlayHost);
|
||||
connect(m_netplay_discord, &DiscordHandler::Join, this, &MainWindow::NetPlayJoin);
|
||||
|
||||
Discord::InitNetPlayFunctionality([this] { m_netplay_discord->DiscordJoin(); });
|
||||
m_netplay_discord->Start();
|
||||
}
|
||||
|
||||
bool MainWindow::NetPlayJoin()
|
||||
@ -1169,6 +1179,7 @@ void MainWindow::NetPlayQuit()
|
||||
{
|
||||
Settings::Instance().ResetNetPlayClient();
|
||||
Settings::Instance().ResetNetPlayServer();
|
||||
Discord::UpdateDiscordPresence();
|
||||
}
|
||||
|
||||
void MainWindow::EnableScreenSaver(bool enable)
|
||||
|
@ -19,6 +19,7 @@ struct BootParameters;
|
||||
class CheatsManager;
|
||||
class CodeWidget;
|
||||
class ControllersWindow;
|
||||
class DiscordHandler;
|
||||
class DragEnterEvent;
|
||||
class FIFOPlayerWindow;
|
||||
class GameList;
|
||||
@ -183,6 +184,7 @@ private:
|
||||
ControllersWindow* m_controllers_window;
|
||||
SettingsWindow* m_settings_window;
|
||||
NetPlayDialog* m_netplay_dialog;
|
||||
DiscordHandler* m_netplay_discord;
|
||||
NetPlaySetupDialog* m_netplay_setup_dialog;
|
||||
GraphicsWindow* m_graphics_window;
|
||||
static constexpr int num_gc_controllers = 4;
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Common/HttpRequest.h"
|
||||
#include "Common/TraversalClient.h"
|
||||
|
||||
#include "Core/Config/GraphicsSettings.h"
|
||||
@ -49,6 +50,7 @@
|
||||
#include "DolphinQt/Resources.h"
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
#include "UICommon/DiscordPresence.h"
|
||||
#include "UICommon/GameFile.h"
|
||||
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
@ -418,6 +420,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
|
||||
m_nickname = nickname;
|
||||
m_use_traversal = use_traversal;
|
||||
m_buffer_size = 0;
|
||||
m_old_player_count = 0;
|
||||
|
||||
m_room_box->clear();
|
||||
m_chat_edit->clear();
|
||||
@ -565,6 +568,41 @@ void NetPlayDialog::UpdateGUI()
|
||||
m_hostcode_action_button->setText(tr("Copy"));
|
||||
m_hostcode_action_button->setEnabled(true);
|
||||
}
|
||||
|
||||
if (m_old_player_count != player_count)
|
||||
{
|
||||
if (m_use_traversal)
|
||||
{
|
||||
const auto host_id = g_TraversalClient->GetHostID();
|
||||
Discord::UpdateDiscordPresence(player_count, Discord::SecretType::RoomID,
|
||||
std::string(host_id.begin(), host_id.end()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Temporary soluation
|
||||
// To Do: Don't rely on a service that Dolphin devs aren't in control of. Ask one of the
|
||||
// project managers about this.
|
||||
|
||||
Common::HttpRequest request;
|
||||
Common::HttpRequest::Response response = request.Get("https://www.myexternalip.com/raw");
|
||||
|
||||
if (!response.has_value())
|
||||
return;
|
||||
|
||||
// The response ends with a /n and the - 1 removes that
|
||||
std::string exernalIPAddress = std::string(response->begin(), response->end() - 1);
|
||||
std::string port = std::to_string(Settings::Instance().GetNetPlayServer()->GetPort());
|
||||
std::string secret;
|
||||
secret.reserve(exernalIPAddress.length() + 1 + port.length());
|
||||
secret += exernalIPAddress;
|
||||
secret += ':';
|
||||
secret += port;
|
||||
|
||||
Discord::UpdateDiscordPresence(player_count, Discord::SecretType::IPAddress, secret);
|
||||
}
|
||||
|
||||
m_old_player_count = player_count;
|
||||
}
|
||||
}
|
||||
|
||||
// NetPlayUI methods
|
||||
|
Reference in New Issue
Block a user