Safeguards and tests regarding #248 in GetScoresAroundUserAsync

This commit is contained in:
Garry Newman 2019-05-01 08:45:11 +01:00
parent 51ab76893a
commit 38a29c6059
2 changed files with 13 additions and 10 deletions

View File

@ -129,15 +129,18 @@ public async Task GetScoresAroundUserAsync()
var leaderboard = await SteamUserStats.FindLeaderboard( "Testleaderboard" ); var leaderboard = await SteamUserStats.FindLeaderboard( "Testleaderboard" );
Assert.IsTrue( leaderboard.HasValue ); Assert.IsTrue( leaderboard.HasValue );
// Get entries around user for ( int i = 1; i < 10; i++ )
var relativeScores = await leaderboard.Value.GetScoresAroundUserAsync( -5, 5 );
Assert.IsNotNull( relativeScores );
Console.WriteLine( $"" );
Console.WriteLine( $"Relative Scores:" );
foreach ( var e in relativeScores )
{ {
Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" ); // Get entries around user
var relativeScores = await leaderboard.Value.GetScoresAroundUserAsync( -i, i );
Assert.IsNotNull( relativeScores );
Console.WriteLine( $"" );
Console.WriteLine( $"Relative Scores:" );
foreach ( var e in relativeScores )
{
Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" );
}
} }
} }

View File

@ -102,13 +102,13 @@ public async Task<LeaderboardEntry[]> GetScoresFromFriends()
#region util #region util
internal async Task<LeaderboardEntry[]> LeaderboardResultToEntries( LeaderboardScoresDownloaded_t r ) internal async Task<LeaderboardEntry[]> LeaderboardResultToEntries( LeaderboardScoresDownloaded_t r )
{ {
if ( r.CEntryCount == 0 ) if ( r.CEntryCount <= 0 )
return null; return null;
var output = new LeaderboardEntry[r.CEntryCount]; var output = new LeaderboardEntry[r.CEntryCount];
var e = default( LeaderboardEntry_t ); var e = default( LeaderboardEntry_t );
for ( int i = 0; i < r.CEntryCount; i++ ) for ( int i = 0; i < output.Length; i++ )
{ {
if ( SteamUserStats.Internal.GetDownloadedLeaderboardEntry( r.SteamLeaderboardEntries, i, ref e, detailsBuffer, detailsBuffer.Length ) ) if ( SteamUserStats.Internal.GetDownloadedLeaderboardEntry( r.SteamLeaderboardEntries, i, ref e, detailsBuffer, detailsBuffer.Length ) )
{ {