Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6358b21
Add Discord Game SDK library
0x416c69 Jul 24, 2019
bf7a7d1
Add shared part of discord game sdk integration
0x416c69 Jul 24, 2019
caf7a50
Add client part of discord game sdk integration
0x416c69 Jul 24, 2019
9b63cf5
Add server part of discord game sdk integration
0x416c69 Jul 24, 2019
a0c001d
Resolve conflicts created by 4244ec52a5155d624cd5ec8dca1bdca067309358
0x416c69 Jul 24, 2019
8e0bd9e
Make changes/Correct mistakes according to reviews
0x416c69 Jul 30, 2019
f0792de
Merge branch 'master' into feature/discord-rich-presence
qaisjp Aug 4, 2019
14979e4
Merge branch 'master' into discordintegration
qaisjp Aug 18, 2019
1e6e308
Move DISCORD_CLIENT_ID to CDiscordManager.cpp
qaisjp Aug 18, 2019
323fb64
discord: change SetLargeImage asset key
qaisjp Aug 18, 2019
1901c11
discord: change neutral activity message
qaisjp Aug 18, 2019
58aeddd
discord: add start timestamp to main menu
qaisjp Aug 18, 2019
1ef02be
discord: use time(&time_t)
qaisjp Aug 18, 2019
5b3a347
addendum to 1ef02be
qaisjp Aug 18, 2019
1344873
Minor style improvements
qaisjp Aug 18, 2019
4c867a9
Run format document/selection on changed files
qaisjp Aug 18, 2019
0d1f1d6
Remove unnecessary null check
qaisjp Aug 18, 2019
765a82f
Add discord game sdk library
0x416c69 Aug 18, 2019
129b84c
Merge branch 'discordintegration' of https://github.com/0x416c69/mtas…
0x416c69 Aug 18, 2019
a174747
Merge branch 'master' into discordintegration
qaisjp Sep 5, 2019
009190e
Avoid code duplication and fix grammar when setting discord state
0x416c69 Sep 5, 2019
5978ca9
Move UpdateDiscordState to CClientGame and avoid code duplication
0x416c69 Sep 6, 2019
3107dce
Addendum 009190eeca5c6cbe5eb53475860aba1e293ef211
0x416c69 Sep 6, 2019
daf1415
Merge 'master' branch into discordintegration
botder Sep 8, 2019
e7d4518
Disallow space character on setDiscordJoinParams
0x416c69 Sep 10, 2019
715375f
Merge branch 'master' into feature/discord-rich-presence
qaisjp Oct 22, 2019
64bf9c8
Merge branch 'master' into discordintegration
qaisjp Jan 13, 2020
573b221
Merge branch 'master' into discordintegration
qaisjp Jan 26, 2020
0596d5e
update vendor
qaisjp Jan 26, 2020
51bf853
Merge branch 'master' into discordintegration
qaisjp Jan 30, 2020
156cdf9
Join secret is no longer used on argument parser
0x416c69 Jan 31, 2020
f7f74d8
Fix a minor mistake
0x416c69 Jan 31, 2020
d473604
Use luaL_error
0x416c69 Feb 11, 2020
75ee065
update out of date dll
qaisjp Feb 11, 2020
8273615
Add discord download script
qaisjp Feb 11, 2020
1515f9d
Link correct library
0x416c69 Feb 12, 2020
3c0443e
Add discord dll to installer
qaisjp Feb 12, 2020
f7a19d2
Merge branch 'master' into discordintegration
qaisjp Feb 12, 2020
858bbab
Update DISCORD_BASEURL
qaisjp Mar 14, 2020
b642481
Merge branch 'master' into discordintegration
qaisjp Mar 14, 2020
6d8d7ef
Merge branch 'master' into discordintegration
qaisjp Mar 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
747 changes: 374 additions & 373 deletions Client/core/CClientVariables.cpp

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion Client/core/CConnectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion Client/core/CConnectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -52,6 +54,7 @@ class CConnectManager
bool m_bSave;
time_t m_tConnectStarted;
bool m_bHasTriedSecondConnect;
SString m_strDiscordSecretJoin;

GUI_CALLBACK* m_pOnCancelClick;

Expand Down
29 changes: 28 additions & 1 deletion Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -779,6 +783,7 @@ void CCore::ApplyHooks2()
CCore::GetSingleton().CreateMultiplayer();
CCore::GetSingleton().CreateXML();
CCore::GetSingleton().CreateGUI();
CCore::GetSingleton().ResetDiscordRichPresence();
}
}
}
Expand Down Expand Up @@ -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
//
Expand Down
43 changes: 24 additions & 19 deletions Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading