Nuget package updates

- Newtonsoft.Json
- changed arkdata code to only check NON STEAM players 10 times, then stop.
This commit is contained in:
Brett Hewitson 2022-06-21 21:36:55 +10:00
parent e069ecdfe7
commit e5327ac946
13 changed files with 35 additions and 24 deletions

View file

@ -11,7 +11,7 @@
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />

View file

@ -60,12 +60,13 @@ namespace ArkData
/// <returns>The async task context.</returns>
public async Task<DateTime> LoadSteamAsync(string apiKey, int steamUpdateInterval = 0)
{
const int MAX_STEAM_IDS = 100;
// need to make multiple calls of 100 steam id's.
var lastSteamUpdateUtc = DateTime.UtcNow;
var startIndex = 0;
var playerSteamIds = Players.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow).Select(p => p.PlayerId);
var playerSteamIds = Players
.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow && p.NoUpdateCount < MAX_INVALID_COUNT)
.Select(p => p.PlayerId)
.ToArray();
while (true)
{
@ -78,7 +79,7 @@ namespace ArkData
using (var client = new HttpClient())
{
client.BaseAddress = new System.Uri("https://api.steampowered.com/");
client.BaseAddress = new Uri("https://api.steampowered.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
@ -86,7 +87,7 @@ namespace ArkData
if (response.IsSuccessStatusCode)
using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync()))
{
LinkSteamProfiles(await reader.ReadToEndAsync(), lastSteamUpdateUtc);
LinkSteamProfiles(await reader.ReadToEndAsync(), lastSteamUpdateUtc, playerSteamIds);
}
else
throw new System.Net.WebException("The Steam API request was unsuccessful. Are you using a valid key?");

View file

@ -13,6 +13,9 @@ namespace ArkData
{
public partial class DataContainer
{
const int MAX_STEAM_IDS = 100;
const int MAX_INVALID_COUNT = 10;
/// <summary>
/// A list of all players registered on the server.
/// </summary>
@ -86,7 +89,7 @@ namespace ArkData
/// Deserializes JSON from Steam API and links Steam profile to player profile.
/// </summary>
/// <param name="jsonString">The JSON data string.</param>
private void LinkSteamProfiles(string jsonString, DateTime lastSteamUpdateUtc)
private void LinkSteamProfiles(string jsonString, DateTime lastSteamUpdateUtc, string[] playerSteamIds)
{
var profiles = JsonConvert.DeserializeObject<Models.SteamResponse<Models.SteamProfile>>(jsonString).response.players;
@ -96,6 +99,13 @@ namespace ArkData
player.PlayerName = profiles[i].personaname;
player.LastPlatformUpdateUtc = lastSteamUpdateUtc;
}
for (var i = 0; i < playerSteamIds.Length; i++)
{
var player = Players.SingleOrDefault(p => p.PlayerId == playerSteamIds[i]);
if (player != null && player.LastPlatformUpdateUtc == DateTime.MinValue)
player.NoUpdateCount = Math.Min(MAX_INVALID_COUNT, player.NoUpdateCount + 1);
}
}
}
}

View file

@ -58,12 +58,13 @@ namespace ArkData
/// <param name="apiKey">The Steam API key</param>
public DateTime LoadSteam(string apiKey, int steamUpdateInterval = 0)
{
const int MAX_STEAM_IDS = 100;
// need to make multiple calls of 100 steam id's.
var lastSteamUpdateUtc = DateTime.UtcNow;
var startIndex = 0;
var playerSteamIds = Players.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow).Select(p => p.PlayerId);
var playerSteamIds = Players
.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow && p.NoUpdateCount < MAX_INVALID_COUNT)
.Select(p => p.PlayerId)
.ToArray();
while (true)
{
@ -76,7 +77,7 @@ namespace ArkData
using (var client = new HttpClient())
{
client.BaseAddress = new System.Uri("https://api.steampowered.com/");
client.BaseAddress = new Uri("https://api.steampowered.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
@ -84,7 +85,7 @@ namespace ArkData
if (response.IsSuccessStatusCode)
using (var reader = new StreamReader(response.Content.ReadAsStreamAsync().Result))
{
LinkSteamProfiles(reader.ReadToEnd(), lastSteamUpdateUtc);
LinkSteamProfiles(reader.ReadToEnd(), lastSteamUpdateUtc, playerSteamIds);
}
else
throw new System.Net.WebException("The Steam API request was unsuccessful. Are you using a valid key?");

View file

@ -20,5 +20,6 @@ namespace ArkData
public virtual List<TribeData> OwnedTribes { get; set; }
public DateTime LastPlatformUpdateUtc { get; set; }
}
public int NoUpdateCount { get; set; }
}
}