Skip to content

Commit

Permalink
- Updated game data for Season of Opportunity.
Browse files Browse the repository at this point in the history
- Temporarily disabled price info.
  • Loading branch information
josdemmers committed Oct 20, 2024
1 parent 6855dbc commit 7d0fabd
Show file tree
Hide file tree
Showing 42 changed files with 571,293 additions and 425,272 deletions.
2 changes: 1 addition & 1 deletion NewWorldCompanion.Entities/PriceServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace NewWorldCompanion.Entities
{
public class PriceServer
{
public string Id { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public int Id { get; set; } = 1;
public DateTime Updated { get; set; } = DateTime.MinValue;
}
}
2 changes: 1 addition & 1 deletion NewWorldCompanion.Entities/SettingsNWC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SettingsNWC
public bool TooltipEnabled { get; set; } = true;
public bool ExtendedTooltipEnabled { get; set; } = false;
public bool NamedItemsTooltipEnabled { get; set; } = false;
public int PriceServerId { get; set; } = 1;
public string PriceServerIdNwm { get; set; } = string.Empty;

// Shape detection
public int EmguAreaLower { get; set; } = 10000;
Expand Down
19 changes: 19 additions & 0 deletions NewWorldCompanion.Helpers/UnixTimeStamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWorldCompanion.Helpers
{
public class UnixTimeStamp
{
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
{
// Unix timestamp is seconds past epoch
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(unixTimeStamp).ToLocalTime();
return dateTime;
}
}
}
59 changes: 42 additions & 17 deletions NewWorldCompanion.Services/PriceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public PriceManager(IEventAggregator eventAggregator, ILogger<PriceManager> logg

#region Properties

public int ServerId { get => _settingsManager.Settings.PriceServerId; }
public string ServerId { get => _settingsManager.Settings.PriceServerIdNwm; }
public List<PriceServer> Servers { get => _servers; set => _servers = value; }

#endregion
Expand All @@ -80,20 +80,19 @@ private async void UpdateServerList()
{
try
{
string json = await _httpClientHandler.GetRequest("https://nwmarketprices.com/api/servers_updated/") ?? string.Empty;
var servers = JsonSerializer.Deserialize<UpdatedServers>(json);
string json = await _httpClientHandler.GetRequest("https://nwmpapi.gaming.tools/servers") ?? "{}";
var options = new JsonSerializerOptions();
options.Converters.Add(new BoolConverter());
options.Converters.Add(new DoubleConverter());
options.Converters.Add(new IntConverter());
var servers = JsonSerializer.Deserialize<List<ServerInfo>>(json, options);

_servers.Clear();
foreach (var server in servers?.ServersLastUpdated ?? new List<List<object>>())
foreach (var server in servers ?? new List<ServerInfo>())
{
var serverId = ((JsonElement)server[0]).GetInt32();
var serverName = ((JsonElement)server[1]).GetString() ?? string.Empty;
var updated = default(DateTime);
var updatedObj = server[2];
if (updatedObj != null)
{
updated = ((JsonElement)updatedObj).GetDateTime();
}
var serverId = server.Id;
var serverName = server.Name;
var updated = UnixTimeStamp.UnixTimeStampToDateTime(server.LastUpdated);

_servers.Add(new PriceServer()
{
Expand All @@ -120,7 +119,7 @@ private async void UpdateServerList()

public NwmarketpriceJson GetPriceData(string itemName)
{
var nwmarketpriceJson = new NwmarketpriceJson();
var nwmarketpriceJson = new NwmarketpriceJson();
return _priceCache.GetValueOrDefault(itemName, nwmarketpriceJson); ;
}

Expand Down Expand Up @@ -256,7 +255,7 @@ public void UpdatePriceData(string itemName)
if (!_priceCache.ContainsKey(itemName))
{
if (!_priceRequestQueue.Contains(itemName)) _priceRequestQueue.Add(itemName);
lock(priceRequestLock)
lock (priceRequestLock)
{
if (!_priceRequestQueueBusy)
{
Expand All @@ -269,8 +268,11 @@ public void UpdatePriceData(string itemName)
{
try
{
string uri = $"https://nwmarketprices.com/0/{ServerId}?cn_id={itemId.ToLower()}";
string json = await _httpClientHandler.GetRequest(uri);
// TODO Update with https://nwmp.gaming.tools/ API.
//string uri = $"https://nwmarketprices.com/0/{ServerId}?cn_id={itemId.ToLower()}";
//string json = await _httpClientHandler.GetRequest(uri);
string uri = string.Empty;
string json = string.Empty;

Debug.WriteLine($"uri: {uri}");
Debug.WriteLine($"json: {json}");
Expand Down Expand Up @@ -334,8 +336,31 @@ public void UpdatePriceData(string itemName)

private class UpdatedServers
{
[JsonPropertyName("server_last_updated")]
public List<List<object>> ServersLastUpdated { get; set; } = new List<List<object>> { };
}

private class ServerInfo
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;

[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;

[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;

[JsonPropertyName("region")]
public string Region { get; set; } = string.Empty;

[JsonPropertyName("last_updated")]
public double LastUpdated { get; set; } = 0;

[JsonPropertyName("json_url")]
public string JsonUrl { get; set; } = string.Empty;

[JsonPropertyName("tsv_url")]
public string TsvUrl{ get; set; } = string.Empty;
}
}
}
Loading

0 comments on commit 7d0fabd

Please sign in to comment.