Skip to content

Commit 850c76d

Browse files
0x416c69qaisjpbotder
authored
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 <[email protected]> Co-authored-by: Marek Kulik <[email protected]>
1 parent 2d68519 commit 850c76d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2449
-1206
lines changed

Client/core/CClientVariables.cpp

Lines changed: 374 additions & 373 deletions
Large diffs are not rendered by default.

Client/core/CConnectManager.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ CConnectManager::~CConnectManager()
4646
g_pConnectManager = NULL;
4747
}
4848

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

103+
if (szSecret)
104+
m_strDiscordSecretJoin = szSecret;
105+
else
106+
m_strDiscordSecretJoin.clear();
107+
103108
m_strLastHost = m_strHost;
104109
m_usLastPort = m_usPort;
105110
m_strLastPassword = m_strPassword;
@@ -489,3 +494,10 @@ void CConnectManager::OpenServerFirewall(in_addr Address, ushort usHttpPort, boo
489494
g_pCore->GetNetwork()->GetHTTPDownloadManager(EDownloadMode::CONNECT_TCP_SEND)->QueueFile(strDummyUrl, NULL, NULL, NULL, options);
490495
}
491496
}
497+
498+
SString CConnectManager::GetJoinSecret()
499+
{
500+
SString dummy = m_strDiscordSecretJoin;
501+
m_strDiscordSecretJoin.clear();
502+
return dummy;
503+
}

Client/core/CConnectManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CConnectManager
2121
CConnectManager();
2222
~CConnectManager();
2323

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

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

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

37+
SString GetJoinSecret();
38+
3739
std::string m_strLastHost;
3840
unsigned short m_usLastPort;
3941
std::string m_strLastPassword;
@@ -52,6 +54,7 @@ class CConnectManager
5254
bool m_bSave;
5355
time_t m_tConnectStarted;
5456
bool m_bHasTriedSecondConnect;
57+
SString m_strDiscordSecretJoin;
5558

5659
GUI_CALLBACK* m_pOnCancelClick;
5760

Client/core/CCore.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "CModelCacheManager.h"
2222
#include "detours/include/detours.h"
2323
#include <ServerBrowser/CServerCache.h>
24+
#include "CDiscordManager.h"
2425

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

37-
CCore::CCore()
38+
CCore::CCore() : m_DiscordManager(new CDiscordManager())
3839
{
3940
// Initialize the global pointer
4041
g_pCore = this;
@@ -565,6 +566,9 @@ void CCore::SetConnected(bool bConnected)
565566
{
566567
m_pLocalGUI->GetMainMenu()->SetIsIngame(bConnected);
567568
UpdateIsWindowMinimized(); // Force update of stuff
569+
570+
if (bConnected) m_DiscordManager->RegisterPlay(true);
571+
else ResetDiscordRichPresence();
568572
}
569573

570574
bool CCore::IsConnected()
@@ -779,6 +783,7 @@ void CCore::ApplyHooks2()
779783
CCore::GetSingleton().CreateMultiplayer();
780784
CCore::GetSingleton().CreateXML();
781785
CCore::GetSingleton().CreateGUI();
786+
CCore::GetSingleton().ResetDiscordRichPresence();
782787
}
783788
}
784789
}
@@ -1980,6 +1985,28 @@ uint CCore::GetMaxStreamingMemory()
19801985
return m_fMaxStreamingMemory;
19811986
}
19821987

1988+
//
1989+
// ResetDiscordRichPresence
1990+
//
1991+
void CCore::ResetDiscordRichPresence()
1992+
{
1993+
time_t currentTime;
1994+
time(&currentTime);
1995+
1996+
// Set default parameters
1997+
SDiscordActivity activity;
1998+
activity.m_details = "In Main Menu";
1999+
activity.m_startTimestamp = currentTime;
2000+
2001+
m_DiscordManager->UpdateActivity(activity, [](EDiscordRes res) {
2002+
if (res == DiscordRes_Ok)
2003+
WriteDebugEvent("[DISCORD]: Rich presence default parameters reset.");
2004+
else
2005+
WriteErrorEvent("[DISCORD]: Unable to reset rich presence default parameters.");
2006+
});
2007+
m_DiscordManager->RegisterPlay(false);
2008+
}
2009+
19832010
//
19842011
// OnCrashAverted
19852012
//

Client/core/CCore.h

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,26 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
8383
~CCore();
8484

8585
// Subsystems (query)
86-
eCoreVersion GetVersion();
87-
CConsoleInterface* GetConsole();
88-
CCommandsInterface* GetCommands();
89-
CConnectManager* GetConnectManager() { return m_pConnectManager; };
90-
CGame* GetGame();
91-
CGUI* GetGUI();
92-
CGraphicsInterface* GetGraphics();
93-
CModManagerInterface* GetModManager();
94-
CMultiplayer* GetMultiplayer();
95-
CNet* GetNetwork();
96-
CXML* GetXML() { return m_pXML; };
97-
CXMLNode* GetConfig();
98-
CClientVariables* GetCVars() { return &m_ClientVariables; };
99-
CKeyBindsInterface* GetKeyBinds();
100-
CMouseControl* GetMouseControl() { return m_pMouseControl; };
101-
CLocalGUI* GetLocalGUI();
102-
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
103-
CWebCoreInterface* GetWebCore();
104-
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
86+
eCoreVersion GetVersion();
87+
CConsoleInterface* GetConsole();
88+
CCommandsInterface* GetCommands();
89+
CConnectManager* GetConnectManager() { return m_pConnectManager; };
90+
CGame* GetGame();
91+
CGUI* GetGUI();
92+
CGraphicsInterface* GetGraphics();
93+
CModManagerInterface* GetModManager();
94+
CMultiplayer* GetMultiplayer();
95+
CNet* GetNetwork();
96+
CXML* GetXML() { return m_pXML; };
97+
CXMLNode* GetConfig();
98+
CClientVariables* GetCVars() { return &m_ClientVariables; };
99+
CKeyBindsInterface* GetKeyBinds();
100+
CMouseControl* GetMouseControl() { return m_pMouseControl; };
101+
CLocalGUI* GetLocalGUI();
102+
CLocalizationInterface* GetLocalization() { return g_pLocalization; };
103+
CWebCoreInterface* GetWebCore();
104+
CTrayIconInterface* GetTrayIcon() { return m_pTrayIcon; };
105+
CDiscordManagerInterface* GetDiscordManager() { return reinterpret_cast<CDiscordManagerInterface*>(m_DiscordManager.get()); }
105106

106107
void SaveConfig(bool bWaitUntilFinished = false);
107108

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

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

302+
std::unique_ptr<class CDiscordManager> m_DiscordManager;
303+
299304
// Hook interfaces.
300305
CMessageLoopHook* m_pMessageLoopHook;
301306
CDirectInputHookManager* m_pDirectInputHookManager;

0 commit comments

Comments
 (0)