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,8 +129,10 @@ namespace Steamworks
var leaderboard = await SteamUserStats.FindLeaderboard( "Testleaderboard" ); var leaderboard = await SteamUserStats.FindLeaderboard( "Testleaderboard" );
Assert.IsTrue( leaderboard.HasValue ); Assert.IsTrue( leaderboard.HasValue );
for ( int i = 1; i < 10; i++ )
{
// Get entries around user // Get entries around user
var relativeScores = await leaderboard.Value.GetScoresAroundUserAsync( -5, 5 ); var relativeScores = await leaderboard.Value.GetScoresAroundUserAsync( -i, i );
Assert.IsNotNull( relativeScores ); Assert.IsNotNull( relativeScores );
Console.WriteLine( $"" ); Console.WriteLine( $"" );
@ -140,6 +142,7 @@ namespace Steamworks
Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" ); Console.WriteLine( $"{e.GlobalRank}: {e.Score} {e.User}" );
} }
} }
}
[TestMethod] [TestMethod]
public async Task GetScoresAsync() public async Task GetScoresAsync()

View File

@ -102,13 +102,13 @@ namespace Steamworks.Data
#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 ) )
{ {