2017-02-08 13:33:37 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
namespace Facepunch.Steamworks.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
[DeploymentItem( "steam_api.dll" )]
|
|
|
|
|
[DeploymentItem( "steam_api64.dll" )]
|
|
|
|
|
[DeploymentItem( "steam_appid.txt" )]
|
|
|
|
|
public class Leaderboard
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void GetLeaderboard()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
|
|
|
|
|
|
|
|
|
|
while ( !board.IsValid )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue( board.IsValid );
|
|
|
|
|
Assert.IsFalse( board.IsError );
|
|
|
|
|
Assert.IsNotNull( board.Name );
|
|
|
|
|
|
|
|
|
|
Console.WriteLine( $"Board name is \"{board.Name}\"" );
|
|
|
|
|
Console.WriteLine( $"Board has \"{board.TotalEntries}\" entries" );
|
|
|
|
|
|
2017-04-02 11:29:06 +01:00
|
|
|
|
board.AddScore( true, 86275309, 7, 8, 9 );
|
2017-02-08 13:33:37 +00:00
|
|
|
|
|
|
|
|
|
board.FetchScores( Steamworks.Leaderboard.RequestType.Global, 0, 20 );
|
|
|
|
|
|
|
|
|
|
while ( board.IsQuerying )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( var entry in board.Results )
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( $"{entry.GlobalRank}: {entry.SteamId} ({entry.Name}) with {entry.Score}" );
|
|
|
|
|
|
|
|
|
|
if ( entry.SubScores != null )
|
|
|
|
|
Console.WriteLine( " - " + string.Join( ";", entry.SubScores.Select( x => x.ToString() ).ToArray() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 13:23:19 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void GetLeaderboardCallback()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
|
|
|
|
|
|
|
|
|
|
while ( !board.IsValid )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue( board.IsValid );
|
|
|
|
|
Assert.IsFalse( board.IsError );
|
|
|
|
|
Assert.IsNotNull( board.Name );
|
|
|
|
|
|
|
|
|
|
board.AddScore( true, 86275309, 7, 8, 9 );
|
|
|
|
|
|
|
|
|
|
var done = false;
|
|
|
|
|
|
|
|
|
|
board.FetchScores( Steamworks.Leaderboard.RequestType.Global, 0, 20, ( success, results ) =>
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue( success );
|
|
|
|
|
|
2017-05-15 14:05:36 +01:00
|
|
|
|
foreach ( var entry in results )
|
2017-05-15 13:23:19 +01:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine( $"{entry.GlobalRank}: {entry.SteamId} ({entry.Name}) with {entry.Score}" );
|
|
|
|
|
|
|
|
|
|
if ( entry.SubScores != null )
|
|
|
|
|
Console.WriteLine( " - " + string.Join( ";", entry.SubScores.Select( x => x.ToString() ).ToArray() ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done = true;
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
while ( !done )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 13:33:37 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void AddScores()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
|
|
|
|
|
|
|
|
|
|
while ( !board.IsValid )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue( board.IsValid );
|
|
|
|
|
Assert.IsFalse( board.IsError );
|
|
|
|
|
|
2017-04-02 11:29:06 +01:00
|
|
|
|
board.AddScore( true, 1234 );
|
2017-02-08 13:33:37 +00:00
|
|
|
|
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
|
2017-04-02 11:29:06 +01:00
|
|
|
|
board.AddScore( true, 34566 );
|
2017-02-08 13:33:37 +00:00
|
|
|
|
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
|
2017-04-02 11:29:06 +01:00
|
|
|
|
board.AddScore( true, 86275309, 7, 8, 9, 7, 4, 7, 98, 24, 5, 76, 124, 6 );
|
2017-02-08 13:33:37 +00:00
|
|
|
|
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
|
2017-04-02 11:29:06 +01:00
|
|
|
|
board.AddScore( false, 86275309, 7, 8, 9, 7, 4, 7, 98, 24, 5, 76, 124, 6 );
|
2017-02-08 13:33:37 +00:00
|
|
|
|
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-15 14:05:36 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void AddScoresCallback()
|
|
|
|
|
{
|
|
|
|
|
using ( var client = new Steamworks.Client( 252490 ) )
|
|
|
|
|
{
|
|
|
|
|
var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
|
|
|
|
|
|
|
|
|
|
while ( !board.IsValid )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue( board.IsValid );
|
|
|
|
|
Assert.IsFalse( board.IsError );
|
|
|
|
|
|
|
|
|
|
var done = false;
|
|
|
|
|
|
|
|
|
|
const int score = 5678;
|
|
|
|
|
|
|
|
|
|
board.AddScore( false, score, null, ( success, result ) =>
|
|
|
|
|
{
|
|
|
|
|
Assert.IsTrue( success );
|
|
|
|
|
Assert.IsTrue( result.ScoreChanged );
|
|
|
|
|
Assert.AreEqual( result.Score, score );
|
2017-05-15 14:13:28 +01:00
|
|
|
|
|
|
|
|
|
done = true;
|
2017-05-15 14:05:36 +01:00
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
while ( !done )
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep( 10 );
|
|
|
|
|
client.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-08 13:33:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|