mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Begin the groundwork to set a custom status on Steam
Currently, this just shows the current map in the status. Might need localization data in Steamworks to be available to work in languages other than English. CC #2642
This commit is contained in:
parent
ea7b2671bc
commit
674d7856fd
|
@ -600,6 +600,15 @@ void CClient::SetState(int s)
|
|||
else if(g_Config.m_ClReconnectTimeout > 0 && (str_find_nocase(ErrorString(), "Timeout") || str_find_nocase(ErrorString(), "Too weak connection")))
|
||||
m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectTimeout;
|
||||
}
|
||||
|
||||
if(s == IClient::STATE_ONLINE)
|
||||
{
|
||||
Steam()->SetGameInfo(m_ServerAddress, m_aCurrentMap);
|
||||
}
|
||||
else if(Old == IClient::STATE_ONLINE)
|
||||
{
|
||||
Steam()->ClearGameInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,32 +4,53 @@
|
|||
|
||||
class CSteam : public ISteam
|
||||
{
|
||||
ISteamApps *m_pSteamApps;
|
||||
ISteamFriends *m_pSteamFriends;
|
||||
char m_aPlayerName[16];
|
||||
|
||||
public:
|
||||
CSteam()
|
||||
{
|
||||
ISteamFriends *pSteamFriends = SteamAPI_SteamFriends_v017();
|
||||
str_copy(m_aPlayerName, SteamAPI_ISteamFriends_GetPersonaName(pSteamFriends), sizeof(m_aPlayerName));
|
||||
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)
|
||||
{
|
||||
CmdLineSize = 127;
|
||||
}
|
||||
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()
|
||||
{
|
||||
SteamAPI_Shutdown();
|
||||
}
|
||||
|
||||
|
||||
const char *GetPlayerName()
|
||||
{
|
||||
return m_aPlayerName;
|
||||
}
|
||||
|
||||
void ClearGameInfo()
|
||||
{
|
||||
SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends);
|
||||
}
|
||||
void SetGameInfo(NETADDR ServerAddr, const char *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 char *GetPlayerName() { return 0; }
|
||||
void ClearGameInfo() { }
|
||||
void SetGameInfo(NETADDR ServerAddr, const char *pMapName) { }
|
||||
};
|
||||
|
||||
ISteam *CreateSteam()
|
||||
|
|
|
@ -9,6 +9,9 @@ class ISteam : public IInterface
|
|||
public:
|
||||
// Returns NULL if the name cannot be determined.
|
||||
virtual const char *GetPlayerName() = 0;
|
||||
|
||||
virtual void ClearGameInfo() = 0;
|
||||
virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0;
|
||||
};
|
||||
|
||||
ISteam *CreateSteam();
|
||||
|
|
|
@ -10,12 +10,20 @@
|
|||
extern "C"
|
||||
{
|
||||
|
||||
struct ISteamApps;
|
||||
struct ISteamFriends;
|
||||
|
||||
STEAMAPI bool SteamAPI_Init(); // Returns true on success.
|
||||
STEAMAPI void SteamAPI_Shutdown();
|
||||
|
||||
STEAMAPI ISteamApps *SteamAPI_SteamApps_v008();
|
||||
STEAMAPI int SteamAPI_ISteamApps_GetLaunchCommandLine(ISteamApps *pSelf, char *pBuffer, int BufferSize);
|
||||
STEAMAPI const char *SteamAPI_ISteamApps_GetLaunchQueryParam(ISteamApps *pSelf, const char *pKey);
|
||||
|
||||
STEAMAPI ISteamFriends *SteamAPI_SteamFriends_v017();
|
||||
STEAMAPI void SteamAPI_ISteamFriends_ClearRichPresence(ISteamFriends *pSelf);
|
||||
STEAMAPI const char *SteamAPI_ISteamFriends_GetPersonaName(ISteamFriends *pSelf);
|
||||
STEAMAPI bool SteamAPI_ISteamFriends_SetRichPresence(ISteamFriends *pSelf, const char *pKey, const char *pValue);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,12 @@ extern "C"
|
|||
|
||||
bool SteamAPI_Init() { return false; }
|
||||
void SteamAPI_Shutdown() { abort(); }
|
||||
ISteamApps *SteamAPI_SteamApps_v008() { abort(); }
|
||||
int SteamAPI_ISteamApps_GetLaunchCommandLine(ISteamApps *pSelf, char *pBuffer, int BufferSize) { abort(); }
|
||||
const char *SteamAPI_ISteamApps_GetLaunchQueryParam(ISteamApps *pSelf, const char *pKey) { abort(); }
|
||||
ISteamFriends *SteamAPI_SteamFriends_v017() { abort(); }
|
||||
const char *SteamAPI_ISteamFriends_GetPersonaName(ISteamFriends *pSelf) { abort(); }
|
||||
bool SteamAPI_ISteamFriends_SetRichPresence(ISteamFriends *pSelf, const char *pKey, const char *pValue) { abort(); }
|
||||
void SteamAPI_ISteamFriends_ClearRichPresence(ISteamFriends *pSelf) { abort(); }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue