Add accessors for other platform identities.

This is in the public SDK, it's not trade secret stuff.
This commit is contained in:
Fletcher Dunn
2024-03-13 11:42:58 -07:00
parent 2751115430
commit e4b7cdcf6a
5 changed files with 61 additions and 0 deletions
@@ -116,6 +116,8 @@ STEAMNETWORKINGSOCKETS_INTERFACE void SteamAPI_SteamNetworkingIdentity_SetSteamI
STEAMNETWORKINGSOCKETS_INTERFACE uint64_steamid SteamAPI_SteamNetworkingIdentity_GetSteamID( SteamNetworkingIdentity* self );
STEAMNETWORKINGSOCKETS_INTERFACE void SteamAPI_SteamNetworkingIdentity_SetSteamID64( SteamNetworkingIdentity* self, uint64 steamID );
STEAMNETWORKINGSOCKETS_INTERFACE uint64 SteamAPI_SteamNetworkingIdentity_GetSteamID64( SteamNetworkingIdentity* self );
STEAMNETWORKINGSOCKETS_INTERFACE bool SteamAPI_SteamNetworkingIdentity_SetXboxPairwiseID( SteamNetworkingIdentity* self, const char * pszString );
STEAMNETWORKINGSOCKETS_INTERFACE const char * SteamAPI_SteamNetworkingIdentity_GetXboxPairwiseID( SteamNetworkingIdentity* self );
STEAMNETWORKINGSOCKETS_INTERFACE void SteamAPI_SteamNetworkingIdentity_SetIPAddr( SteamNetworkingIdentity* self, const SteamNetworkingIPAddr & addr );
STEAMNETWORKINGSOCKETS_INTERFACE const SteamNetworkingIPAddr * SteamAPI_SteamNetworkingIdentity_GetIPAddr( SteamNetworkingIdentity* self );
STEAMNETWORKINGSOCKETS_INTERFACE void SteamAPI_SteamNetworkingIdentity_SetLocalHost( SteamNetworkingIdentity* self );
+16
View File
@@ -146,6 +146,8 @@ enum ESteamNetworkingIdentityType
// Basic platform-specific identifiers.
//
k_ESteamNetworkingIdentityType_SteamID = 16, // 64-bit CSteamID
k_ESteamNetworkingIdentityType_XboxPairwiseID = 17, // Publisher-specific user identity, as string
k_ESteamNetworkingIdentityType_SonyPSN = 18, // 64-bit ID
//
// Special identifiers.
@@ -274,6 +276,12 @@ struct SteamNetworkingIdentity
void SetSteamID64( uint64 steamID ); // Takes SteamID as raw 64-bit number
uint64 GetSteamID64() const; // Returns 0 if identity is not SteamID
bool SetXboxPairwiseID( const char *pszString ); // Returns false if invalid length
const char *GetXboxPairwiseID() const; // Returns nullptr if not Xbox ID
void SetPSNID( uint64 id );
uint64 GetPSNID() const; // Returns 0 if not PSN
void SetIPAddr( const SteamNetworkingIPAddr &addr ); // Set to specified IP:port
const SteamNetworkingIPAddr *GetIPAddr() const; // returns null if we are not an IP address.
void SetIPv4Addr( uint32 nIPv4, uint16 nPort ); // Set to specified IPv4:port
@@ -315,6 +323,7 @@ struct SteamNetworkingIdentity
enum {
k_cchMaxString = 128, // Max length of the buffer needed to hold any identity, formatted in string format by ToString
k_cchMaxGenericString = 32, // Max length of the string for generic string identities. Including terminating '\0'
k_cchMaxXboxPairwiseID = 33, // Including terminating '\0'
k_cbMaxGenericBytes = 32,
};
@@ -327,7 +336,9 @@ struct SteamNetworkingIdentity
int m_cbSize;
union {
uint64 m_steamID64;
uint64 m_PSNID;
char m_szGenericString[ k_cchMaxGenericString ];
char m_szXboxPairwiseID[ k_cchMaxXboxPairwiseID ];
uint8 m_genericBytes[ k_cbMaxGenericBytes ];
char m_szUnknownRawString[ k_cchMaxString ];
SteamNetworkingIPAddr m_ip;
@@ -1829,6 +1840,11 @@ inline void SteamNetworkingIdentity::SetSteamID( CSteamID steamID ) { SetSteamID
inline CSteamID SteamNetworkingIdentity::GetSteamID() const { return CSteamID( GetSteamID64() ); }
inline void SteamNetworkingIdentity::SetSteamID64( uint64 steamID ) { m_eType = k_ESteamNetworkingIdentityType_SteamID; m_cbSize = sizeof( m_steamID64 ); m_steamID64 = steamID; }
inline uint64 SteamNetworkingIdentity::GetSteamID64() const { return m_eType == k_ESteamNetworkingIdentityType_SteamID ? m_steamID64 : 0; }
inline bool SteamNetworkingIdentity::SetXboxPairwiseID( const char *pszString ) { size_t l = strlen( pszString ); if ( l < 1 || l >= sizeof(m_szXboxPairwiseID) ) return false;
m_eType = k_ESteamNetworkingIdentityType_XboxPairwiseID; m_cbSize = int(l+1); memcpy( m_szXboxPairwiseID, pszString, m_cbSize ); return true; }
inline const char *SteamNetworkingIdentity::GetXboxPairwiseID() const { return m_eType == k_ESteamNetworkingIdentityType_XboxPairwiseID ? m_szXboxPairwiseID : NULL; }
inline void SteamNetworkingIdentity::SetPSNID( uint64 id ) { m_eType = k_ESteamNetworkingIdentityType_SonyPSN; m_cbSize = sizeof( m_PSNID ); m_PSNID = id; }
inline uint64 SteamNetworkingIdentity::GetPSNID() const { return m_eType == k_ESteamNetworkingIdentityType_SonyPSN ? m_PSNID : 0; }
inline void SteamNetworkingIdentity::SetIPAddr( const SteamNetworkingIPAddr &addr ) { m_eType = k_ESteamNetworkingIdentityType_IPAddress; m_cbSize = (int)sizeof(m_ip); m_ip = addr; }
inline const SteamNetworkingIPAddr *SteamNetworkingIdentity::GetIPAddr() const { return m_eType == k_ESteamNetworkingIdentityType_IPAddress ? &m_ip : NULL; }
inline void SteamNetworkingIdentity::SetIPv4Addr( uint32 nIPv4, uint16 nPort ) { m_eType = k_ESteamNetworkingIdentityType_IPAddress; m_cbSize = (int)sizeof(m_ip); m_ip.SetIPv4( nIPv4, nPort ); }
@@ -390,6 +390,14 @@ STEAMNETWORKINGSOCKETS_INTERFACE uint64 SteamAPI_SteamNetworkingIdentity_GetStea
{
return self->GetSteamID64( );
}
STEAMNETWORKINGSOCKETS_INTERFACE bool SteamAPI_SteamNetworkingIdentity_SetXboxPairwiseID( SteamNetworkingIdentity* self, const char * pszString )
{
return self->SetXboxPairwiseID( pszString );
}
STEAMNETWORKINGSOCKETS_INTERFACE const char * SteamAPI_SteamNetworkingIdentity_GetXboxPairwiseID( SteamNetworkingIdentity* self )
{
return self->GetXboxPairwiseID( );
}
STEAMNETWORKINGSOCKETS_INTERFACE void SteamAPI_SteamNetworkingIdentity_SetIPAddr( SteamNetworkingIdentity* self, const SteamNetworkingIPAddr & addr )
{
self->SetIPAddr( addr );
@@ -213,6 +213,14 @@ STEAMNETWORKINGSOCKETS_INTERFACE void SteamNetworkingIdentity_ToString( const St
V_snprintf( buf, cbBuf, "steamid:%llu", (unsigned long long)pIdentity->m_steamID64 );
break;
case k_ESteamNetworkingIdentityType_XboxPairwiseID:
V_snprintf( buf, cbBuf, "xboxpwid:%s", pIdentity->m_szXboxPairwiseID );
break;
case k_ESteamNetworkingIdentityType_SonyPSN:
V_snprintf( buf, cbBuf, "psn:%llu", (unsigned long long)pIdentity->m_PSNID );
break;
case k_ESteamNetworkingIdentityType_IPAddress:
V_strncpy( buf, "ip:", cbBuf );
if ( cbBuf > 4 )
@@ -285,6 +293,25 @@ STEAMNETWORKINGSOCKETS_INTERFACE bool SteamNetworkingIdentity_ParseString( Steam
return true;
}
if ( V_strncmp( pszStr, "xboxpwid:", 9 ) == 0 )
{
pszStr += 9;
size_t l = strlen( pszStr );
if ( l >= sizeofData )
return false;
return pIdentity->SetXboxPairwiseID( pszStr );
}
if ( V_strncmp( pszStr, "psn:", 4 ) == 0 )
{
pszStr += 4;
unsigned long long temp;
if ( sscanf( pszStr, "%llu", &temp ) != 1 )
return false;
pIdentity->SetPSNID( (uint64)temp );
return true;
}
if ( V_strncmp( pszStr, "ip:", 3 ) == 0 )
{
pszStr += 3;
+8
View File
@@ -581,6 +581,14 @@ void Test_identity()
assert( id2.GetSteamID() == steamID );
}
{
const char *pszTempXBoxID = "8fg37rfsdf";
assert( id1.SetXboxPairwiseID( pszTempXBoxID ) );
id1.ToString( tempBuf, sizeof(tempBuf ) );
assert( id2.ParseString( tempBuf ) );
assert( strcmp( id2.GetXboxPairwiseID(), pszTempXBoxID ) == 0 );
}
{
const char *pszTempIPAddr = "ip:192.168.0.0:27015";
assert( id1.ParseString( pszTempIPAddr ) );