mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Make it possible to join via the Steam friend list
This commit is contained in:
parent
ef9260601e
commit
f682a79d5f
|
@ -4048,6 +4048,11 @@ static CClient *CreateClient()
|
|||
return new(pClient) CClient;
|
||||
}
|
||||
|
||||
void CClient::HandleConnectAddress(const NETADDR *pAddr)
|
||||
{
|
||||
net_addr_str(pAddr, m_aCmdConnect, sizeof(m_aCmdConnect), true);
|
||||
}
|
||||
|
||||
void CClient::HandleConnectLink(const char *pLink)
|
||||
{
|
||||
str_copy(m_aCmdConnect, pLink + sizeof(CONNECTLINK) - 1, sizeof(m_aCmdConnect));
|
||||
|
@ -4118,6 +4123,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
IEngineTextRender *pEngineTextRender = CreateEngineTextRender();
|
||||
IEngineMap *pEngineMap = CreateEngineMap();
|
||||
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
|
||||
ISteam *pSteam = CreateSteam();
|
||||
|
||||
if(RandInitFailed)
|
||||
{
|
||||
|
@ -4150,7 +4156,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateEditor(), false);
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateGameClient(), false);
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateSteam());
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pSteam);
|
||||
|
||||
if(RegisterFail)
|
||||
{
|
||||
|
@ -4215,6 +4221,11 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
else if(argc > 1) // ignore_convention
|
||||
pConsole->ParseArguments(argc-1, &argv[1]); // ignore_convention
|
||||
|
||||
if(pSteam->GetLaunchConnectAddress())
|
||||
{
|
||||
pClient->HandleConnectAddress(pSteam->GetLaunchConnectAddress());
|
||||
}
|
||||
|
||||
pClient->Engine()->InitLogfile();
|
||||
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
|
|
|
@ -427,6 +427,7 @@ public:
|
|||
|
||||
void ServerBrowserUpdate();
|
||||
|
||||
void HandleConnectAddress(const NETADDR *pAddr);
|
||||
void HandleConnectLink(const char *pLink);
|
||||
void HandleDemoPath(const char *pPath);
|
||||
void HandleMapPath(const char *pPath);
|
||||
|
|
|
@ -7,6 +7,8 @@ class CSteam : public ISteam
|
|||
ISteamApps *m_pSteamApps;
|
||||
ISteamFriends *m_pSteamFriends;
|
||||
char m_aPlayerName[16];
|
||||
bool m_GotConnectAddr;
|
||||
NETADDR m_ConnectAddr;
|
||||
|
||||
public:
|
||||
CSteam()
|
||||
|
@ -14,14 +16,25 @@ public:
|
|||
m_pSteamApps = SteamAPI_SteamApps_v008();
|
||||
m_pSteamFriends = SteamAPI_SteamFriends_v017();
|
||||
|
||||
char aCmdLine[128];
|
||||
int CmdLineSize = SteamAPI_ISteamApps_GetLaunchCommandLine(m_pSteamApps, aCmdLine, sizeof(aCmdLine));
|
||||
if(CmdLineSize >= 128)
|
||||
char aConnect[NETADDR_MAXSTRSIZE];
|
||||
int ConnectSize = SteamAPI_ISteamApps_GetLaunchCommandLine(m_pSteamApps, aConnect, sizeof(aConnect));
|
||||
if(ConnectSize >= NETADDR_MAXSTRSIZE)
|
||||
{
|
||||
CmdLineSize = 127;
|
||||
ConnectSize = NETADDR_MAXSTRSIZE - 1;
|
||||
}
|
||||
aConnect[ConnectSize] = 0;
|
||||
m_GotConnectAddr = false;
|
||||
if(aConnect[0])
|
||||
{
|
||||
if(net_addr_from_str(&m_ConnectAddr, aConnect) == 0)
|
||||
{
|
||||
m_GotConnectAddr = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
dbg_msg("steam", "got unparsable launch connect string: '%s'", aConnect);
|
||||
}
|
||||
}
|
||||
aCmdLine[CmdLineSize] = 0;
|
||||
dbg_msg("steam", "cmdline='%s' param_connect='%s'", aCmdLine, SteamAPI_ISteamApps_GetLaunchQueryParam(m_pSteamApps, "connect"));
|
||||
str_copy(m_aPlayerName, SteamAPI_ISteamFriends_GetPersonaName(m_pSteamFriends), sizeof(m_aPlayerName));
|
||||
}
|
||||
~CSteam()
|
||||
|
@ -34,21 +47,38 @@ public:
|
|||
return m_aPlayerName;
|
||||
}
|
||||
|
||||
const NETADDR *GetLaunchConnectAddress()
|
||||
{
|
||||
if(m_GotConnectAddr)
|
||||
{
|
||||
return &m_ConnectAddr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ClearGameInfo()
|
||||
{
|
||||
SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends);
|
||||
}
|
||||
void SetGameInfo(NETADDR ServerAddr, const char *pMapName)
|
||||
{
|
||||
char aServerAddr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&ServerAddr, aServerAddr, sizeof(aServerAddr), true);
|
||||
|
||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "connect", aServerAddr);
|
||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "map", pMapName);
|
||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "status", pMapName);
|
||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "steam_display", "#Status");
|
||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "map", pMapName);
|
||||
}
|
||||
};
|
||||
|
||||
class CSteamStub : public ISteam
|
||||
{
|
||||
const char *GetPlayerName() { return 0; }
|
||||
const NETADDR *GetLaunchConnectAddress() { return 0; }
|
||||
void ClearGameInfo() { }
|
||||
void SetGameInfo(NETADDR ServerAddr, const char *pMapName) { }
|
||||
};
|
||||
|
|
|
@ -10,6 +10,9 @@ public:
|
|||
// Returns NULL if the name cannot be determined.
|
||||
virtual const char *GetPlayerName() = 0;
|
||||
|
||||
// Returns NULL if the no server needs to be joined.
|
||||
virtual const NETADDR *GetLaunchConnectAddress() = 0;
|
||||
|
||||
virtual void ClearGameInfo() = 0;
|
||||
virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue