mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Activity tracker, more efficient, fix city not IP
This commit is contained in:
parent
38edb68574
commit
cda660cc3e
@ -280,18 +280,27 @@
|
|||||||
if (GeolocationCache.ContainsKey(ActivityMachineAddress))
|
if (GeolocationCache.ContainsKey(ActivityMachineAddress))
|
||||||
return GeolocationCache[ActivityMachineAddress];
|
return GeolocationCache[ActivityMachineAddress];
|
||||||
|
|
||||||
string location = "", locationCity = "", locationRegion = "", locationCountry = "";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var locationInformation = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json");
|
string location = "";
|
||||||
|
var ipInfo = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{ActivityMachineAddress}/json");
|
||||||
|
|
||||||
if (locationInformation is not null)
|
if (ipInfo is null)
|
||||||
{
|
return $"N/A ({Resources.Strings.ActivityTracker_LookupFailed})";
|
||||||
locationCity = locationInformation.IP;
|
|
||||||
locationRegion = locationInformation.Region;
|
if (string.IsNullOrEmpty(ipInfo.Country))
|
||||||
locationCountry = locationInformation.Country;
|
location = "N/A";
|
||||||
}
|
else if (ipInfo.City == ipInfo.Region)
|
||||||
|
location = $"{ipInfo.Region}, {ipInfo.Country}";
|
||||||
|
else
|
||||||
|
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
||||||
|
|
||||||
|
if (!ActivityInGame)
|
||||||
|
return $"N/A ({Resources.Strings.ActivityTracker_LeftGame})";
|
||||||
|
|
||||||
|
GeolocationCache[ActivityMachineAddress] = location;
|
||||||
|
|
||||||
|
return location;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -300,24 +309,6 @@
|
|||||||
|
|
||||||
return $"N/A ({Resources.Strings.ActivityTracker_LookupFailed})";
|
return $"N/A ({Resources.Strings.ActivityTracker_LookupFailed})";
|
||||||
}
|
}
|
||||||
|
|
||||||
locationCity = locationCity.ReplaceLineEndings("");
|
|
||||||
locationRegion = locationRegion.ReplaceLineEndings("");
|
|
||||||
locationCountry = locationCountry.ReplaceLineEndings("");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(locationCountry))
|
|
||||||
location = "N/A";
|
|
||||||
else if (locationCity == locationRegion)
|
|
||||||
location = $"{locationRegion}, {locationCountry}";
|
|
||||||
else
|
|
||||||
location = $"{locationCity}, {locationRegion}, {locationCountry}";
|
|
||||||
|
|
||||||
if (!ActivityInGame)
|
|
||||||
return $"N/A ({Resources.Strings.ActivityTracker_LeftGame})";
|
|
||||||
|
|
||||||
GeolocationCache[ActivityMachineAddress] = location;
|
|
||||||
|
|
||||||
return location;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -2,8 +2,8 @@ namespace Bloxstrap.Models
|
|||||||
{
|
{
|
||||||
public class IPInfoResponse
|
public class IPInfoResponse
|
||||||
{
|
{
|
||||||
[JsonPropertyName("ip")]
|
[JsonPropertyName("city")]
|
||||||
public string IP { get; set; } = null!;
|
public string City { get; set; } = null!;
|
||||||
|
|
||||||
[JsonPropertyName("country")]
|
[JsonPropertyName("country")]
|
||||||
public string Country { get; set; } = null!;
|
public string Country { get; set; } = null!;
|
||||||
|
Loading…
Reference in New Issue
Block a user