mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-02-26 13:31:17 +03:00
Added a bunch of functions/properties to NetIdentity
This commit is contained in:
parent
13feee328d
commit
d900b6e217
@ -9,21 +9,104 @@ namespace Steamworks.Data
|
|||||||
internal IdentityType type;
|
internal IdentityType type;
|
||||||
|
|
||||||
[FieldOffset( 4 )]
|
[FieldOffset( 4 )]
|
||||||
internal int m_cbSize;
|
internal int size;
|
||||||
|
|
||||||
[FieldOffset( 8 )]
|
[FieldOffset( 8 )]
|
||||||
internal SteamId steamID;
|
internal ulong steamid;
|
||||||
|
|
||||||
|
[FieldOffset( 8 )]
|
||||||
|
internal NetAddress netaddress;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a NetIdentity that represents LocalHost
|
||||||
|
/// </summary>
|
||||||
|
public static NetIdentity LocalHost
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
NetIdentity id = default;
|
||||||
|
InternalSetLocalHost( ref id );
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool IsSteamId => type == IdentityType.SteamID;
|
||||||
|
public bool IsIpAddress => type == IdentityType.IPAddress;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if this identity is localhost
|
||||||
|
/// </summary>
|
||||||
|
public bool IsLocalHost
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
NetIdentity id = default;
|
||||||
|
return InternalIsLocalHost( ref id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert to a SteamId
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
public static implicit operator NetIdentity( SteamId value )
|
public static implicit operator NetIdentity( SteamId value )
|
||||||
{
|
{
|
||||||
return new NetIdentity { steamID = value, type = IdentityType.SteamID, m_cbSize = 8 };
|
NetIdentity id = default;
|
||||||
|
InternalSetSteamID( ref id, value );
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the specified Address
|
||||||
|
/// </summary>
|
||||||
|
public static implicit operator NetIdentity( NetAddress address )
|
||||||
|
{
|
||||||
|
NetIdentity id = default;
|
||||||
|
InternalSetIPAddr( ref id, ref address );
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Automatically convert to a SteamId
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
public static implicit operator SteamId( NetIdentity value )
|
public static implicit operator SteamId( NetIdentity value )
|
||||||
{
|
{
|
||||||
return value.steamID;
|
return value.SteamId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns NULL if we're not a SteamId
|
||||||
|
/// </summary>
|
||||||
|
public SteamId SteamId
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( type != IdentityType.SteamID ) return default;
|
||||||
|
var id = this;
|
||||||
|
return InternalGetSteamID( ref id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns NULL if we're not a NetAddress
|
||||||
|
/// </summary>
|
||||||
|
public NetAddress Address
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( type != IdentityType.IPAddress ) return default;
|
||||||
|
var id = this;
|
||||||
|
|
||||||
|
var addrptr = InternalGetIPAddr( ref id );
|
||||||
|
return addrptr.ToType<NetAddress>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// We override tostring to provide a sensible representation
|
||||||
|
/// </summary>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var id = this;
|
var id = this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user