mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 18:11:27 -07:00
Added IP2Location.io API as failover geolocation API
This commit is contained in:
parent
d15e910904
commit
317c5f8074
@ -302,8 +302,25 @@
|
|||||||
var ipInfo = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json");
|
var ipInfo = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json");
|
||||||
|
|
||||||
if (ipInfo is null)
|
if (ipInfo is null)
|
||||||
return $"? ({Resources.Strings.ActivityTracker_LookupFailed})";
|
{
|
||||||
|
var ip2LocationIO = await Http.GetJson<IP2LocationIOResponse>($"https://api.ip2location.io/?ip={ActivityMachineAddress}");
|
||||||
|
|
||||||
|
if (ip2LocationIO is null)
|
||||||
|
{
|
||||||
|
return $"? ({Resources.Strings.ActivityTracker_LookupFailed})";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(ip2LocationIO.Country))
|
||||||
|
location = "?";
|
||||||
|
else if (ip2LocationIO.City == ip2LocationIO.Region)
|
||||||
|
location = $"{ip2LocationIO.Region}, {ip2LocationIO.Country}";
|
||||||
|
else
|
||||||
|
location = $"{ip2LocationIO.City}, {ip2LocationIO.Region}, {ip2LocationIO.Country}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (string.IsNullOrEmpty(ipInfo.Country))
|
if (string.IsNullOrEmpty(ipInfo.Country))
|
||||||
location = "?";
|
location = "?";
|
||||||
else if (ipInfo.City == ipInfo.Region)
|
else if (ipInfo.City == ipInfo.Region)
|
||||||
@ -311,6 +328,8 @@
|
|||||||
else
|
else
|
||||||
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (!ActivityInGame)
|
if (!ActivityInGame)
|
||||||
return $"? ({Resources.Strings.ActivityTracker_LeftGame})";
|
return $"? ({Resources.Strings.ActivityTracker_LeftGame})";
|
||||||
|
|
||||||
|
14
Bloxstrap/Models/IP2LocationIOResponse.cs
Normal file
14
Bloxstrap/Models/IP2LocationIOResponse.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
namespace Bloxstrap.Models
|
||||||
|
{
|
||||||
|
public class IP2LocationIOResponse
|
||||||
|
{
|
||||||
|
[JsonPropertyName("city_name")]
|
||||||
|
public string City { get; set; } = null!;
|
||||||
|
|
||||||
|
[JsonPropertyName("country_code")]
|
||||||
|
public string Country { get; set; } = null!;
|
||||||
|
|
||||||
|
[JsonPropertyName("region_name")]
|
||||||
|
public string Region { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user