Skip to content
Permalink
Browse files

Add initial Discord Game SDK Integration (#1031)

This is just Rich Presence & Join features for now.

* Add Discord Game SDK library

* Add shared part of discord game sdk integration

* Add client part of discord game sdk integration

* Add server part of discord game sdk integration

* Resolve conflicts created by 4244ec5

* Make changes/Correct mistakes according to reviews

* Move DISCORD_CLIENT_ID to CDiscordManager.cpp

* discord: change SetLargeImage asset key

* discord: change neutral activity message

* discord: add start timestamp to main menu

* discord: use time(&time_t)

* addendum to 1ef02be

* Minor style improvements

* Run format document/selection on changed files

* Remove unnecessary null check

* Add discord game sdk library

Also allow it through .gitignore

* Avoid code duplication and fix grammar when setting discord state

* Move UpdateDiscordState to CClientGame and avoid code duplication

* Addendum 009190e

* Disallow space character on setDiscordJoinParams
This avoids messup on argument parser

* update vendor

* Join secret is no longer used on argument parser

* Fix a minor mistake

* Use luaL_error

Also disallow to use party max than the max players value

* update out of date dll

* Add discord download script

* Link correct library

Also do not download discord again when it is already up to date

* Add discord dll to installer

* Update DISCORD_BASEURL

Co-authored-by: Qais Patankar <qaisjp@gmail.com>
Co-authored-by: Marek Kulik <marek.kulik@hotmail.com>
  • Loading branch information
3 people committed Mar 25, 2020
1 parent 2d68519 commit 850c76d4cc88fe085d389d5a6e46f0cd2da1996e
Showing with 2,449 additions and 1,206 deletions.
  1. +374 −373 Client/core/CClientVariables.cpp
  2. +13 −1 Client/core/CConnectManager.cpp
  3. +4 −1 Client/core/CConnectManager.h
  4. +28 −1 Client/core/CCore.cpp
  5. +24 −19 Client/core/CCore.h
  6. +367 −0 Client/core/CDiscordManager.cpp
  7. +66 −0 Client/core/CDiscordManager.h
  8. +236 −0 Client/core/CQueryReceiver.cpp
  9. +71 −0 Client/core/CQueryReceiver.h
  10. +19 −0 Client/core/CSettings.cpp
  11. +1 −0 Client/core/CSettings.h
  12. +1 −0 Client/core/DXHook/CDirect3DHook9.cpp
  13. +1 −1 Client/core/ServerBrowser/CServerInfo.cpp
  14. +3 −3 Client/core/ServerBrowser/CServerInfo.h
  15. +31 −193 Client/core/ServerBrowser/CServerList.cpp
  16. +7 −17 Client/core/ServerBrowser/CServerList.h
  17. +1 −0 Client/core/StdInc.h
  18. +4 −2 Client/core/premake5.lua
  19. +23 −14 Client/mods/deathmatch/CClient.cpp
  20. +2 −0 Client/mods/deathmatch/CClient.h
  21. +1 −0 Client/mods/deathmatch/StdInc.h
  22. +34 −2 Client/mods/deathmatch/logic/CClientGame.cpp
  23. +8 −1 Client/mods/deathmatch/logic/CClientGame.h
  24. +27 −0 Client/mods/deathmatch/logic/CPacketHandler.cpp
  25. +1 −0 Client/mods/deathmatch/logic/CPacketHandler.h
  26. +23 −0 Client/mods/deathmatch/logic/CServerInfo.cpp
  27. +31 −0 Client/mods/deathmatch/logic/CServerInfo.h
  28. +16 −0 Client/mods/deathmatch/logic/rpc/CWorldRPCs.cpp
  29. +1 −0 Client/mods/deathmatch/logic/rpc/CWorldRPCs.h
  30. +2 −0 Client/sdk/core/CClientBase.h
  31. +3 −0 Client/sdk/core/CCoreInterface.h
  32. +113 −0 Client/sdk/core/CDiscordManagerInterface.h
  33. +2 −0 Server/mods/deathmatch/StdInc.h
  34. +34 −1 Server/mods/deathmatch/logic/CGame.cpp
  35. +1 −0 Server/mods/deathmatch/logic/CGame.h
  36. +4 −0 Server/mods/deathmatch/logic/CPacketTranslator.cpp
  37. +566 −565 Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp
  38. +9 −6 Server/mods/deathmatch/logic/CPlayer.h
  39. +29 −0 Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
  40. +1 −0 Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
  41. +34 −0 Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.cpp
  42. +1 −0 Server/mods/deathmatch/logic/luadefs/CLuaPlayerDefs.h
  43. +16 −0 Server/mods/deathmatch/logic/packets/CDiscordJoinPacket.cpp
  44. +30 −0 Server/mods/deathmatch/logic/packets/CDiscordJoinPacket.h
  45. +7 −0 Server/mods/deathmatch/logic/packets/CPlayerJoinDataPacket.cpp
  46. +5 −2 Server/mods/deathmatch/logic/packets/CPlayerJoinDataPacket.h
  47. +30 −0 Server/mods/deathmatch/logic/packets/CServerInfoSyncPacket.cpp
  48. +42 −0 Server/mods/deathmatch/logic/packets/CServerInfoSyncPacket.h
  49. +1 −0 Shared/data/MTA San Andreas/MTA/.gitignore
  50. +2 −0 Shared/data/data files installer.nsi
  51. +2 −0 Shared/installer/nightly.nsi
  52. +4 −0 Shared/mods/deathmatch/logic/Enums.cpp
  53. +5 −0 Shared/sdk/SharedUtil.Misc.h
  54. +1 −1 Shared/sdk/SharedUtil.Misc.hpp
  55. +2 −0 Shared/sdk/SharedUtil.Thread.h
  56. +2 −0 Shared/sdk/net/Packets.h
  57. +2 −0 Shared/sdk/net/rpc_enums.h
  58. +2 −0 premake5.lua
  59. +52 −0 utils/buildactions/install_discord.lua
  60. +3 −1 utils/buildactions/utils.lua
  61. +3 −0 vendor/discordgsdk/.gitignore
  62. +16 −0 vendor/discordgsdk/premake5.lua
  63. +5 −2 win-create-projects.bat

Large diffs are not rendered by default.

@@ -46,7 +46,7 @@ CConnectManager::~CConnectManager()
g_pConnectManager = NULL;
}

bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser)
bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser, const char* szSecret)
{
assert(szHost);
assert(szNick);
@@ -100,6 +100,11 @@ bool CConnectManager::Connect(const char* szHost, unsigned short usPort, const c
m_usPort = usPort;
m_bSave = true;

if (szSecret)
m_strDiscordSecretJoin = szSecret;
else
m_strDiscordSecretJoin.clear();

m_strLastHost = m_strHost;
m_usLastPort = m_usPort;
m_strLastPassword = m_strPassword;
@@ -489,3 +494,10 @@ void CConnectManager::OpenServerFirewall(in_addr Address, ushort usHttpPort, boo
g_pCore->GetNetwork()->GetHTTPDownloadManager(EDownloadMode::CONNECT_TCP_SEND)->QueueFile(strDummyUrl, NULL, NULL, NULL, options);
}
}

SString CConnectManager::GetJoinSecret()
{
SString dummy = m_strDiscordSecretJoin;
m_strDiscordSecretJoin.clear();
return dummy;
}
@@ -21,7 +21,7 @@ class CConnectManager
CConnectManager();
~CConnectManager();

bool Connect(const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser = false);
bool Connect(const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser = false, const char* szSecret = nullptr);
bool Reconnect(const char* szHost, unsigned short usPort, const char* szPassword, bool bSave = true);

bool Abort();
@@ -34,6 +34,8 @@ class CConnectManager

static bool StaticProcessPacket(unsigned char ucPacketID, class NetBitStreamInterface& bitStream);

SString GetJoinSecret();

std::string m_strLastHost;
unsigned short m_usLastPort;
std::string m_strLastPassword;
@@ -52,6 +54,7 @@ class CConnectManager
bool m_bSave;
time_t m_tConnectStarted;
bool m_bHasTriedSecondConnect;
SString m_strDiscordSecretJoin;

GUI_CALLBACK* m_pOnCancelClick;

@@ -21,6 +21,7 @@
#include "CModelCacheManager.h"
#include "detours/include/detours.h"
#include <ServerBrowser/CServerCache.h>
#include "CDiscordManager.h"

using SharedUtil::CalcMTASAPath;
using namespace std;
@@ -34,7 +35,7 @@ SString g_strJingleBells;
template <>
CCore* CSingleton<CCore>::m_pSingleton = NULL;

CCore::CCore()
CCore::CCore() : m_DiscordManager(new CDiscordManager())
{
// Initialize the global pointer
g_pCore = this;
@@ -565,6 +566,9 @@ void CCore::SetConnected(bool bConnected)
{
m_pLocalGUI->GetMainMenu()->SetIsIngame(bConnected);
UpdateIsWindowMinimized(); // Force update of stuff

if (bConnected) m_DiscordManager->RegisterPlay(true);
else ResetDiscordRichPresence();
}

bool CCore::IsConnected()
@@ -779,6 +783,7 @@ void CCore::ApplyHooks2()
CCore::GetSingleton().CreateMultiplayer();
CCore::GetSingleton().CreateXML();
CCore::GetSingleton().CreateGUI();
CCore::GetSingleton().ResetDiscordRichPresence();
}
}
}
@@ -1980,6 +1985,28 @@ uint CCore::GetMaxStreamingMemory()
return m_fMaxStreamingMemory;
}

//
// ResetDiscordRichPresence
//
void CCore::ResetDiscordRichPresence()
{
time_t currentTime;
time(&currentTime);

// Set default parameters
SDiscordActivity activity;
activity.m_details = "In Main Menu";
activity.m_startTimestamp = currentTime;

m_DiscordManager->UpdateActivity(activity, [](EDiscordRes res) {
if (res == DiscordRes_Ok)
WriteDebugEvent("[DISCORD]: Rich presence default parameters reset.");
else
WriteErrorEvent("[DISCORD]: Unable to reset rich presence default parameters.");
});
m_DiscordManager->RegisterPlay(false);
}

//
// OnCrashAverted
//
@@ -83,25 +83,26 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
~CCore();

// Subsystems (query)
eCoreVersion GetVersion();
CConsoleInterface* GetConsole();
CCommandsInterface* GetCommands();
CConnectManager* GetConnectManager() { return m_pConnectManager; };
CGame* GetGame();
CGUI* GetGUI();
CGraphicsInterface* GetGraphics();
CModManagerInterface* GetModManager();
CMultiplayer* GetMultiplayer();
CNet* GetNetwork();
CXML* GetXML() { return m_pXML; };
CXMLNode* GetConfig();
CClientVariables* GetCVars() { return &m_ClientVariables; };
CKeyBindsInterface* GetKeyBinds();
CMouseControl* GetMouseControl() { return m_pMouseControl; };
CLocalGUI* GetLocalGUI();
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
CWebCoreInterface* GetWebCore();
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
eCoreVersion GetVersion();
CConsoleInterface* GetConsole();
CCommandsInterface* GetCommands();
CConnectManager* GetConnectManager() { return m_pConnectManager; };
CGame* GetGame();
CGUI* GetGUI();
CGraphicsInterface* GetGraphics();
CModManagerInterface* GetModManager();
CMultiplayer* GetMultiplayer();
CNet* GetNetwork();
CXML* GetXML() { return m_pXML; };
CXMLNode* GetConfig();
CClientVariables* GetCVars() { return &m_ClientVariables; };
CKeyBindsInterface* GetKeyBinds();
CMouseControl* GetMouseControl() { return m_pMouseControl; };
CLocalGUI* GetLocalGUI();
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
CWebCoreInterface* GetWebCore();
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
CDiscordManagerInterface* GetDiscordManager() { return reinterpret_cast<CDiscordManagerInterface*>(m_DiscordManager.get()); }

void SaveConfig(bool bWaitUntilFinished = false);

@@ -226,6 +227,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
uint GetMinStreamingMemory();
uint GetMaxStreamingMemory();

void ResetDiscordRichPresence();

SString GetConnectCommandFromURI(const char* szURI);
void GetConnectParametersFromURI(const char* szURI, std::string& strHost, unsigned short& usPort, std::string& strNick, std::string& strPassword);
bool bScreenShot;
@@ -296,6 +299,8 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
CWebCoreInterface* m_pWebCore = nullptr;
CTrayIcon* m_pTrayIcon;

std::unique_ptr<class CDiscordManager> m_DiscordManager;

// Hook interfaces.
CMessageLoopHook* m_pMessageLoopHook;
CDirectInputHookManager* m_pDirectInputHookManager;

0 comments on commit 850c76d

Please sign in to comment.
You can’t perform that action at this time.