mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
Allow joining and inviting others via Steam friend list while ingame
Fixes #2642.
This commit is contained in:
parent
7162ded266
commit
435137d79e
|
@ -2844,6 +2844,15 @@ void CClient::Update()
|
||||||
if(!m_EditorActive)
|
if(!m_EditorActive)
|
||||||
GameClient()->OnUpdate();
|
GameClient()->OnUpdate();
|
||||||
|
|
||||||
|
Steam()->Update();
|
||||||
|
if(Steam()->GetConnectAddress())
|
||||||
|
{
|
||||||
|
char aAddress[NETADDR_MAXSTRSIZE];
|
||||||
|
net_addr_str(Steam()->GetConnectAddress(), aAddress, sizeof(aAddress), true);
|
||||||
|
Connect(aAddress);
|
||||||
|
Steam()->ClearConnectAddress();
|
||||||
|
}
|
||||||
|
|
||||||
if(m_ReconnectTime > 0 && time_get() > m_ReconnectTime)
|
if(m_ReconnectTime > 0 && time_get() > m_ReconnectTime)
|
||||||
{
|
{
|
||||||
Connect(m_aServerAddressStr);
|
Connect(m_aServerAddressStr);
|
||||||
|
@ -4220,9 +4229,10 @@ int main(int argc, const char **argv) // ignore_convention
|
||||||
else if(argc > 1) // ignore_convention
|
else if(argc > 1) // ignore_convention
|
||||||
pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention
|
pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention
|
||||||
|
|
||||||
if(pSteam->GetLaunchConnectAddress())
|
if(pSteam->GetConnectAddress())
|
||||||
{
|
{
|
||||||
pClient->HandleConnectAddress(pSteam->GetLaunchConnectAddress());
|
pClient->HandleConnectAddress(pSteam->GetConnectAddress());
|
||||||
|
pSteam->ClearConnectAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
pClient->Engine()->InitLogfile();
|
pClient->Engine()->InitLogfile();
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#include <engine/steam.h>
|
#include <engine/steam.h>
|
||||||
|
|
||||||
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
#include <steam/steam_api_flat.h>
|
#include <steam/steam_api_flat.h>
|
||||||
|
|
||||||
class CSteam : public ISteam
|
class CSteam : public ISteam
|
||||||
{
|
{
|
||||||
|
HSteamPipe m_SteamPipe;
|
||||||
ISteamApps *m_pSteamApps;
|
ISteamApps *m_pSteamApps;
|
||||||
ISteamFriends *m_pSteamFriends;
|
ISteamFriends *m_pSteamFriends;
|
||||||
char m_aPlayerName[16];
|
char m_aPlayerName[16];
|
||||||
|
@ -13,9 +16,38 @@ class CSteam : public ISteam
|
||||||
public:
|
public:
|
||||||
CSteam()
|
CSteam()
|
||||||
{
|
{
|
||||||
|
SteamAPI_ManualDispatch_Init();
|
||||||
|
m_SteamPipe = SteamAPI_GetHSteamPipe();
|
||||||
m_pSteamApps = SteamAPI_SteamApps_v008();
|
m_pSteamApps = SteamAPI_SteamApps_v008();
|
||||||
m_pSteamFriends = SteamAPI_SteamFriends_v017();
|
m_pSteamFriends = SteamAPI_SteamFriends_v017();
|
||||||
|
|
||||||
|
ReadLaunchCommandLine();
|
||||||
|
str_copy(m_aPlayerName, SteamAPI_ISteamFriends_GetPersonaName(m_pSteamFriends), sizeof(m_aPlayerName));
|
||||||
|
}
|
||||||
|
~CSteam()
|
||||||
|
{
|
||||||
|
SteamAPI_Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParseConnectString(const char *pConnect)
|
||||||
|
{
|
||||||
|
if(pConnect[0])
|
||||||
|
{
|
||||||
|
NETADDR Connect;
|
||||||
|
if(net_addr_from_str(&Connect, pConnect) == 0)
|
||||||
|
{
|
||||||
|
m_ConnectAddr = Connect;
|
||||||
|
m_GotConnectAddr = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dbg_msg("steam", "got unparsable connect string: '%s'", pConnect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadLaunchCommandLine()
|
||||||
|
{
|
||||||
char aConnect[NETADDR_MAXSTRSIZE];
|
char aConnect[NETADDR_MAXSTRSIZE];
|
||||||
int ConnectSize = SteamAPI_ISteamApps_GetLaunchCommandLine(m_pSteamApps, aConnect, sizeof(aConnect));
|
int ConnectSize = SteamAPI_ISteamApps_GetLaunchCommandLine(m_pSteamApps, aConnect, sizeof(aConnect));
|
||||||
if(ConnectSize >= NETADDR_MAXSTRSIZE)
|
if(ConnectSize >= NETADDR_MAXSTRSIZE)
|
||||||
|
@ -24,22 +56,12 @@ public:
|
||||||
}
|
}
|
||||||
aConnect[ConnectSize] = 0;
|
aConnect[ConnectSize] = 0;
|
||||||
m_GotConnectAddr = false;
|
m_GotConnectAddr = false;
|
||||||
if(aConnect[0])
|
ParseConnectString(aConnect);
|
||||||
{
|
|
||||||
if(net_addr_from_str(&m_ConnectAddr, aConnect) == 0)
|
|
||||||
{
|
|
||||||
m_GotConnectAddr = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dbg_msg("steam", "got unparsable launch connect string: '%s'", aConnect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
str_copy(m_aPlayerName, SteamAPI_ISteamFriends_GetPersonaName(m_pSteamFriends), sizeof(m_aPlayerName));
|
|
||||||
}
|
}
|
||||||
~CSteam()
|
|
||||||
|
void OnGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t *pEvent)
|
||||||
{
|
{
|
||||||
SteamAPI_Shutdown();
|
ParseConnectString(pEvent->m_rgchConnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetPlayerName()
|
const char *GetPlayerName()
|
||||||
|
@ -47,7 +69,7 @@ public:
|
||||||
return m_aPlayerName;
|
return m_aPlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NETADDR *GetLaunchConnectAddress()
|
const NETADDR *GetConnectAddress()
|
||||||
{
|
{
|
||||||
if(m_GotConnectAddr)
|
if(m_GotConnectAddr)
|
||||||
{
|
{
|
||||||
|
@ -58,7 +80,34 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void ClearConnectAddress()
|
||||||
|
{
|
||||||
|
m_GotConnectAddr = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
SteamAPI_ManualDispatch_RunFrame(m_SteamPipe);
|
||||||
|
CallbackMsg_t Callback;
|
||||||
|
while(SteamAPI_ManualDispatch_GetNextCallback(m_SteamPipe, &Callback))
|
||||||
|
{
|
||||||
|
switch(Callback.m_iCallback)
|
||||||
|
{
|
||||||
|
case NewUrlLaunchParameters_t::k_iCallback:
|
||||||
|
ReadLaunchCommandLine();
|
||||||
|
break;
|
||||||
|
case GameRichPresenceJoinRequested_t::k_iCallback:
|
||||||
|
OnGameRichPresenceJoinRequested((GameRichPresenceJoinRequested_t *)Callback.m_pubParam);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(g_Config.m_Debug)
|
||||||
|
{
|
||||||
|
dbg_msg("steam/dbg", "unhandled callback id=%d", Callback.m_iCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SteamAPI_ManualDispatch_FreeLastCallback(m_SteamPipe);
|
||||||
|
}
|
||||||
|
}
|
||||||
void ClearGameInfo()
|
void ClearGameInfo()
|
||||||
{
|
{
|
||||||
SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends);
|
SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends);
|
||||||
|
@ -79,7 +128,9 @@ public:
|
||||||
class CSteamStub : public ISteam
|
class CSteamStub : public ISteam
|
||||||
{
|
{
|
||||||
const char *GetPlayerName() { return 0; }
|
const char *GetPlayerName() { return 0; }
|
||||||
const NETADDR *GetLaunchConnectAddress() { return 0; }
|
const NETADDR *GetConnectAddress() { return 0; }
|
||||||
|
void ClearConnectAddress() { }
|
||||||
|
void Update() { }
|
||||||
void ClearGameInfo() { }
|
void ClearGameInfo() { }
|
||||||
void SetGameInfo(NETADDR ServerAddr, const char *pMapName) { }
|
void SetGameInfo(NETADDR ServerAddr, const char *pMapName) { }
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,11 @@ public:
|
||||||
virtual const char *GetPlayerName() = 0;
|
virtual const char *GetPlayerName() = 0;
|
||||||
|
|
||||||
// Returns NULL if the no server needs to be joined.
|
// Returns NULL if the no server needs to be joined.
|
||||||
virtual const NETADDR *GetLaunchConnectAddress() = 0;
|
// Can change while the game is running.
|
||||||
|
virtual const NETADDR *GetConnectAddress() = 0;
|
||||||
|
virtual void ClearConnectAddress() = 0;
|
||||||
|
|
||||||
|
virtual void Update() = 0;
|
||||||
|
|
||||||
virtual void ClearGameInfo() = 0;
|
virtual void ClearGameInfo() = 0;
|
||||||
virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0;
|
virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0;
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <base/dynamic.h>
|
#include <base/dynamic.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef STEAMAPI
|
#ifndef STEAMAPI
|
||||||
#define STEAMAPI DYNAMIC_IMPORT
|
#define STEAMAPI DYNAMIC_IMPORT
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,12 +12,43 @@
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|
||||||
|
typedef uint64_t CSteamID;
|
||||||
|
typedef int32_t HSteamPipe;
|
||||||
|
typedef int32_t HSteamUser;
|
||||||
|
|
||||||
|
struct CallbackMsg_t
|
||||||
|
{
|
||||||
|
HSteamUser m_hSteamUser;
|
||||||
|
int m_iCallback;
|
||||||
|
unsigned char *m_pubParam;
|
||||||
|
int m_cubParam;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GameRichPresenceJoinRequested_t
|
||||||
|
{
|
||||||
|
enum { k_iCallback = 337 };
|
||||||
|
CSteamID m_steamIDFriend;
|
||||||
|
char m_rgchConnect[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NewUrlLaunchParameters_t
|
||||||
|
{
|
||||||
|
enum { k_iCallback = 1014 };
|
||||||
|
unsigned char m_EmptyStructDontUse;
|
||||||
|
};
|
||||||
|
|
||||||
struct ISteamApps;
|
struct ISteamApps;
|
||||||
struct ISteamFriends;
|
struct ISteamFriends;
|
||||||
|
|
||||||
STEAMAPI bool SteamAPI_Init(); // Returns true on success.
|
STEAMAPI bool SteamAPI_Init(); // Returns true on success.
|
||||||
|
STEAMAPI HSteamPipe SteamAPI_GetHSteamPipe();
|
||||||
STEAMAPI void SteamAPI_Shutdown();
|
STEAMAPI void SteamAPI_Shutdown();
|
||||||
|
|
||||||
|
STEAMAPI void SteamAPI_ManualDispatch_Init();
|
||||||
|
STEAMAPI void SteamAPI_ManualDispatch_FreeLastCallback(HSteamPipe SteamPipe);
|
||||||
|
STEAMAPI bool SteamAPI_ManualDispatch_GetNextCallback(HSteamPipe SteamPipe, CallbackMsg_t *pCallbackMsg);
|
||||||
|
STEAMAPI void SteamAPI_ManualDispatch_RunFrame(HSteamPipe SteamPipe);
|
||||||
|
|
||||||
STEAMAPI ISteamApps *SteamAPI_SteamApps_v008();
|
STEAMAPI ISteamApps *SteamAPI_SteamApps_v008();
|
||||||
STEAMAPI int SteamAPI_ISteamApps_GetLaunchCommandLine(ISteamApps *pSelf, char *pBuffer, int BufferSize);
|
STEAMAPI int SteamAPI_ISteamApps_GetLaunchCommandLine(ISteamApps *pSelf, char *pBuffer, int BufferSize);
|
||||||
STEAMAPI const char *SteamAPI_ISteamApps_GetLaunchQueryParam(ISteamApps *pSelf, const char *pKey);
|
STEAMAPI const char *SteamAPI_ISteamApps_GetLaunchQueryParam(ISteamApps *pSelf, const char *pKey);
|
||||||
|
|
|
@ -8,7 +8,12 @@ extern "C"
|
||||||
{
|
{
|
||||||
|
|
||||||
bool SteamAPI_Init() { return false; }
|
bool SteamAPI_Init() { return false; }
|
||||||
|
HSteamPipe SteamAPI_GetHSteamPipe() { abort(); }
|
||||||
void SteamAPI_Shutdown() { abort(); }
|
void SteamAPI_Shutdown() { abort(); }
|
||||||
|
void SteamAPI_ManualDispatch_Init() { abort(); }
|
||||||
|
void SteamAPI_ManualDispatch_FreeLastCallback(HSteamPipe SteamPipe) { abort(); }
|
||||||
|
bool SteamAPI_ManualDispatch_GetNextCallback(HSteamPipe SteamPipe, CallbackMsg_t *pCallbackMsg) { abort(); }
|
||||||
|
void SteamAPI_ManualDispatch_RunFrame(HSteamPipe SteamPipe) { abort(); }
|
||||||
ISteamApps *SteamAPI_SteamApps_v008() { abort(); }
|
ISteamApps *SteamAPI_SteamApps_v008() { abort(); }
|
||||||
int SteamAPI_ISteamApps_GetLaunchCommandLine(ISteamApps *pSelf, char *pBuffer, int BufferSize) { abort(); }
|
int SteamAPI_ISteamApps_GetLaunchCommandLine(ISteamApps *pSelf, char *pBuffer, int BufferSize) { abort(); }
|
||||||
const char *SteamAPI_ISteamApps_GetLaunchQueryParam(ISteamApps *pSelf, const char *pKey) { abort(); }
|
const char *SteamAPI_ISteamApps_GetLaunchQueryParam(ISteamApps *pSelf, const char *pKey) { abort(); }
|
||||||
|
|
Loading…
Reference in a new issue