Build error fix and added back ip property

This commit is contained in:
BuildTools 2024-04-15 00:43:44 +01:00
parent 868ee2a4ff
commit 38edb68574
2 changed files with 12 additions and 11 deletions

View File

@ -280,18 +280,19 @@
if (GeolocationCache.ContainsKey(ActivityMachineAddress)) if (GeolocationCache.ContainsKey(ActivityMachineAddress))
return GeolocationCache[ActivityMachineAddress]; return GeolocationCache[ActivityMachineAddress];
string location, locationCity, locationRegion, locationCountry = ""; string location = "", locationCity = "", locationRegion = "", locationCountry = "";
IPInfoResponse locationInformation;
try try
{ {
IPInfoResponse locationInformation = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json"); var locationInformation = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json");
if (locationInformation is not null)
{
locationCity = locationInformation.IP; locationCity = locationInformation.IP;
locationRegion = locationInformation.Region; locationRegion = locationInformation.Region;
locationCountry = locationInformation.Country; locationCountry = locationInformation.Country;
} }
}
catch (Exception ex) catch (Exception ex)
{ {
App.Logger.WriteLine(LOG_IDENT, $"Failed to get server location for {ActivityMachineAddress}"); App.Logger.WriteLine(LOG_IDENT, $"Failed to get server location for {ActivityMachineAddress}");

View File

@ -2,13 +2,13 @@ namespace Bloxstrap.Models
{ {
public class IPInfoResponse public class IPInfoResponse
{ {
[JsonPropertyName("city")] [JsonPropertyName("ip")]
public string? City { get; set; } public string IP { get; set; } = null!;
[JsonPropertyName("country")] [JsonPropertyName("country")]
public string? Country { get; set; } public string Country { get; set; } = null!;
[JsonPropertyName("region")] [JsonPropertyName("region")]
public string? Region { get; set; } public string Region { get; set; } = null!;
} }
} }