mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-20 04:10:00 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
62 lines
1.1 KiB
C#
62 lines
1.1 KiB
C#
using Sandbox.Utility;
|
|
|
|
namespace Sandbox.Services.Players;
|
|
|
|
/// <summary>
|
|
/// Player profile
|
|
/// </summary>
|
|
public sealed class Profile
|
|
{
|
|
public SteamId Id { get; init; }
|
|
public string Name { get; init; }
|
|
public string Url { get; init; }
|
|
public bool Online { get; init; }
|
|
public bool Private { get; init; }
|
|
public int Score { get; init; }
|
|
public string Avatar => $"avatar:{Id}";
|
|
public bool IsFriend => Steam.IsFriend( Id );
|
|
|
|
public static Profile Local
|
|
{
|
|
get
|
|
{
|
|
return new Profile
|
|
{
|
|
Id = Steam.SteamId,
|
|
Name = Steam.PersonaName,
|
|
Url = "",
|
|
Online = true,
|
|
Private = false,
|
|
Score = (int)AccountInformation.Score,
|
|
};
|
|
}
|
|
}
|
|
|
|
public static async Task<Profile> Get( SteamId steamid )
|
|
{
|
|
try
|
|
{
|
|
return From( await Sandbox.Backend.Players.Get( steamid ) );
|
|
}
|
|
catch ( Exception )
|
|
{
|
|
return default;
|
|
}
|
|
}
|
|
|
|
internal static Profile From( Sandbox.Services.Player p )
|
|
{
|
|
if ( p is null ) return default;
|
|
|
|
return new Profile
|
|
{
|
|
Id = p.Id,
|
|
Name = p.Name,
|
|
Url = p.Url,
|
|
Online = p.Online,
|
|
Private = p.Private,
|
|
Score = p.Score
|
|
};
|
|
}
|
|
}
|