mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Added IP2Location.io API as failover geolocation API
This commit is contained in:
parent
d15e910904
commit
317c5f8074
@ -302,16 +302,35 @@
|
||||
var ipInfo = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json");
|
||||
|
||||
if (ipInfo is null)
|
||||
return $"? ({Resources.Strings.ActivityTracker_LookupFailed})";
|
||||
{
|
||||
var ip2LocationIO = await Http.GetJson<IP2LocationIOResponse>($"https://api.ip2location.io/?ip={ActivityMachineAddress}");
|
||||
|
||||
if (string.IsNullOrEmpty(ipInfo.Country))
|
||||
location = "?";
|
||||
else if (ipInfo.City == ipInfo.Region)
|
||||
location = $"{ipInfo.Region}, {ipInfo.Country}";
|
||||
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
|
||||
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
||||
{
|
||||
if (string.IsNullOrEmpty(ipInfo.Country))
|
||||
location = "?";
|
||||
else if (ipInfo.City == ipInfo.Region)
|
||||
location = $"{ipInfo.Region}, {ipInfo.Country}";
|
||||
else
|
||||
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
||||
|
||||
if (!ActivityInGame)
|
||||
}
|
||||
|
||||
if (!ActivityInGame)
|
||||
return $"? ({Resources.Strings.ActivityTracker_LeftGame})";
|
||||
|
||||
GeolocationCache[ActivityMachineAddress] = location;
|
||||
|
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