PlayerCountAsync

This commit is contained in:
Garry Newman 2019-04-16 21:22:46 +01:00
parent 650fb08522
commit f18de016b1
2 changed files with 21 additions and 0 deletions

View File

@ -29,6 +29,14 @@ public void AchievementList()
}
}
[TestMethod]
public async Task PlayerCountAsync()
{
var players = await SteamUserStats.PlayerCountAsync();
Assert.AreNotEqual( players, -1 );
Console.WriteLine( $"players: {players}" );
}
}
}

View File

@ -34,5 +34,18 @@ public static IEnumerable<Achievement> Achievements
}
}
}
/// <summary>
/// Tries to get the number of players currently playing this game.
/// Or -1 if failed.
/// </summary>
public static async Task<int> PlayerCountAsync()
{
var result = await Internal.GetNumberOfCurrentPlayers();
if ( !result.HasValue || result.Value.Success == 0 )
return -1;
return result.Value.CPlayers;
}
}
}