mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18: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;
|
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)
|
void CClient::HandleConnectLink(const char *pLink)
|
||||||
{
|
{
|
||||||
str_copy(m_aCmdConnect, pLink + sizeof(CONNECTLINK) - 1, sizeof(m_aCmdConnect));
|
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();
|
IEngineTextRender *pEngineTextRender = CreateEngineTextRender();
|
||||||
IEngineMap *pEngineMap = CreateEngineMap();
|
IEngineMap *pEngineMap = CreateEngineMap();
|
||||||
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
|
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
|
||||||
|
ISteam *pSteam = CreateSteam();
|
||||||
|
|
||||||
if(RandInitFailed)
|
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(CreateEditor(), false);
|
||||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateGameClient(), false);
|
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateGameClient(), false);
|
||||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
|
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
|
||||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateSteam());
|
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pSteam);
|
||||||
|
|
||||||
if(RegisterFail)
|
if(RegisterFail)
|
||||||
{
|
{
|
||||||
|
@ -4215,6 +4221,11 @@ 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())
|
||||||
|
{
|
||||||
|
pClient->HandleConnectAddress(pSteam->GetLaunchConnectAddress());
|
||||||
|
}
|
||||||
|
|
||||||
pClient->Engine()->InitLogfile();
|
pClient->Engine()->InitLogfile();
|
||||||
|
|
||||||
#if defined(CONF_FAMILY_WINDOWS)
|
#if defined(CONF_FAMILY_WINDOWS)
|
||||||
|
|
|
@ -427,6 +427,7 @@ public:
|
||||||
|
|
||||||
void ServerBrowserUpdate();
|
void ServerBrowserUpdate();
|
||||||
|
|
||||||
|
void HandleConnectAddress(const NETADDR *pAddr);
|
||||||
void HandleConnectLink(const char *pLink);
|
void HandleConnectLink(const char *pLink);
|
||||||
void HandleDemoPath(const char *pPath);
|
void HandleDemoPath(const char *pPath);
|
||||||
void HandleMapPath(const char *pPath);
|
void HandleMapPath(const char *pPath);
|
||||||
|
|
|
@ -7,6 +7,8 @@ class CSteam : public ISteam
|
||||||
ISteamApps *m_pSteamApps;
|
ISteamApps *m_pSteamApps;
|
||||||
ISteamFriends *m_pSteamFriends;
|
ISteamFriends *m_pSteamFriends;
|
||||||
char m_aPlayerName[16];
|
char m_aPlayerName[16];
|
||||||
|
bool m_GotConnectAddr;
|
||||||
|
NETADDR m_ConnectAddr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CSteam()
|
CSteam()
|
||||||
|
@ -14,14 +16,25 @@ public:
|
||||||
m_pSteamApps = SteamAPI_SteamApps_v008();
|
m_pSteamApps = SteamAPI_SteamApps_v008();
|
||||||
m_pSteamFriends = SteamAPI_SteamFriends_v017();
|
m_pSteamFriends = SteamAPI_SteamFriends_v017();
|
||||||
|
|
||||||
char aCmdLine[128];
|
char aConnect[NETADDR_MAXSTRSIZE];
|
||||||
int CmdLineSize = SteamAPI_ISteamApps_GetLaunchCommandLine(m_pSteamApps, aCmdLine, sizeof(aCmdLine));
|
int ConnectSize = SteamAPI_ISteamApps_GetLaunchCommandLine(m_pSteamApps, aConnect, sizeof(aConnect));
|
||||||
if(CmdLineSize >= 128)
|
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));
|
str_copy(m_aPlayerName, SteamAPI_ISteamFriends_GetPersonaName(m_pSteamFriends), sizeof(m_aPlayerName));
|
||||||
}
|
}
|
||||||
~CSteam()
|
~CSteam()
|
||||||
|
@ -34,21 +47,38 @@ public:
|
||||||
return m_aPlayerName;
|
return m_aPlayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NETADDR *GetLaunchConnectAddress()
|
||||||
|
{
|
||||||
|
if(m_GotConnectAddr)
|
||||||
|
{
|
||||||
|
return &m_ConnectAddr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ClearGameInfo()
|
void ClearGameInfo()
|
||||||
{
|
{
|
||||||
SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends);
|
SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends);
|
||||||
}
|
}
|
||||||
void SetGameInfo(NETADDR ServerAddr, const char *pMapName)
|
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, "status", pMapName);
|
||||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "steam_display", "#Status");
|
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "steam_display", "#Status");
|
||||||
SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "map", pMapName);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CSteamStub : public ISteam
|
class CSteamStub : public ISteam
|
||||||
{
|
{
|
||||||
const char *GetPlayerName() { return 0; }
|
const char *GetPlayerName() { return 0; }
|
||||||
|
const NETADDR *GetLaunchConnectAddress() { return 0; }
|
||||||
void ClearGameInfo() { }
|
void ClearGameInfo() { }
|
||||||
void SetGameInfo(NETADDR ServerAddr, const char *pMapName) { }
|
void SetGameInfo(NETADDR ServerAddr, const char *pMapName) { }
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,9 @@ public:
|
||||||
// Returns NULL if the name cannot be determined.
|
// Returns NULL if the name cannot be determined.
|
||||||
virtual const char *GetPlayerName() = 0;
|
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 ClearGameInfo() = 0;
|
||||||
virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0;
|
virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue