mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Improve server location querying and general connectivity handling
This commit is contained in:
parent
3f0ab22393
commit
717b57ea2a
@ -118,10 +118,6 @@ namespace Bloxstrap
|
|||||||
|
|
||||||
App.Logger.WriteLine(LOG_IDENT, "Running bootstrapper");
|
App.Logger.WriteLine(LOG_IDENT, "Running bootstrapper");
|
||||||
|
|
||||||
// connectivity check
|
|
||||||
|
|
||||||
App.Logger.WriteLine(LOG_IDENT, "Performing connectivity check...");
|
|
||||||
|
|
||||||
SetStatus(Strings.Bootstrapper_Status_Connecting);
|
SetStatus(Strings.Bootstrapper_Status_Connecting);
|
||||||
|
|
||||||
var connectionResult = await RobloxDeployment.InitializeConnectivity();
|
var connectionResult = await RobloxDeployment.InitializeConnectivity();
|
||||||
@ -129,9 +125,7 @@ namespace Bloxstrap
|
|||||||
App.Logger.WriteLine(LOG_IDENT, "Connectivity check finished");
|
App.Logger.WriteLine(LOG_IDENT, "Connectivity check finished");
|
||||||
|
|
||||||
if (connectionResult is not null)
|
if (connectionResult is not null)
|
||||||
{
|
|
||||||
HandleConnectionError(connectionResult);
|
HandleConnectionError(connectionResult);
|
||||||
}
|
|
||||||
|
|
||||||
#if !DEBUG || DEBUG_UPDATER
|
#if !DEBUG || DEBUG_UPDATER
|
||||||
if (App.Settings.Prop.CheckForUpdates && !App.LaunchSettings.UpgradeFlag.Active)
|
if (App.Settings.Prop.CheckForUpdates && !App.LaunchSettings.UpgradeFlag.Active)
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
{
|
{
|
||||||
public static class GlobalCache
|
public static class GlobalCache
|
||||||
{
|
{
|
||||||
public static readonly Dictionary<string, Task> PendingTasks = new();
|
public static readonly Dictionary<string, string?> ServerLocation = new();
|
||||||
|
|
||||||
public static readonly Dictionary<string, string> ServerLocation = new();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,8 @@ namespace Bloxstrap.Models
|
|||||||
|
|
||||||
public ICommand RejoinServerCommand => new RelayCommand(RejoinServer);
|
public ICommand RejoinServerCommand => new RelayCommand(RejoinServer);
|
||||||
|
|
||||||
|
private SemaphoreSlim serverQuerySemaphore = new(1, 1);
|
||||||
|
|
||||||
public string GetInviteDeeplink(bool launchData = true)
|
public string GetInviteDeeplink(bool launchData = true)
|
||||||
{
|
{
|
||||||
string deeplink = $"roblox://experiences/start?placeId={PlaceId}";
|
string deeplink = $"roblox://experiences/start?placeId={PlaceId}";
|
||||||
@ -86,29 +88,24 @@ namespace Bloxstrap.Models
|
|||||||
return deeplink;
|
return deeplink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> QueryServerLocation()
|
public async Task<string?> QueryServerLocation()
|
||||||
{
|
{
|
||||||
const string LOG_IDENT = "ActivityData::QueryServerLocation";
|
const string LOG_IDENT = "ActivityData::QueryServerLocation";
|
||||||
|
|
||||||
if (!MachineAddressValid)
|
if (!MachineAddressValid)
|
||||||
throw new InvalidOperationException($"Machine address is invalid ({MachineAddress})");
|
throw new InvalidOperationException($"Machine address is invalid ({MachineAddress})");
|
||||||
|
|
||||||
if (GlobalCache.PendingTasks.TryGetValue(MachineAddress, out Task? task))
|
await serverQuerySemaphore.WaitAsync();
|
||||||
await task;
|
|
||||||
|
|
||||||
if (GlobalCache.ServerLocation.TryGetValue(MachineAddress, out string? location))
|
if (GlobalCache.ServerLocation.TryGetValue(MachineAddress, out string? location))
|
||||||
|
{
|
||||||
|
serverQuerySemaphore.Release();
|
||||||
return location;
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
location = "";
|
var ipInfo = await Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{MachineAddress}/json");
|
||||||
var ipInfoTask = Http.GetJson<IPInfoResponse>($"https://ipinfo.io/{MachineAddress}/json");
|
|
||||||
|
|
||||||
GlobalCache.PendingTasks.Add(MachineAddress, ipInfoTask);
|
|
||||||
|
|
||||||
var ipInfo = await ipInfoTask;
|
|
||||||
|
|
||||||
GlobalCache.PendingTasks.Remove(MachineAddress);
|
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(ipInfo.City))
|
if (String.IsNullOrEmpty(ipInfo.City))
|
||||||
throw new InvalidHTTPResponseException("Reported city was blank");
|
throw new InvalidHTTPResponseException("Reported city was blank");
|
||||||
@ -119,18 +116,25 @@ namespace Bloxstrap.Models
|
|||||||
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
location = $"{ipInfo.City}, {ipInfo.Region}, {ipInfo.Country}";
|
||||||
|
|
||||||
GlobalCache.ServerLocation[MachineAddress] = location;
|
GlobalCache.ServerLocation[MachineAddress] = location;
|
||||||
|
serverQuerySemaphore.Release();
|
||||||
return location;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
App.Logger.WriteLine(LOG_IDENT, $"Failed to get server location for {MachineAddress}");
|
App.Logger.WriteLine(LOG_IDENT, $"Failed to get server location for {MachineAddress}");
|
||||||
App.Logger.WriteException(LOG_IDENT, ex);
|
App.Logger.WriteException(LOG_IDENT, ex);
|
||||||
|
|
||||||
Frontend.ShowMessageBox($"{Strings.ActivityWatcher_LocationQueryFailed}\n\n{ex.Message}", MessageBoxImage.Warning);
|
GlobalCache.ServerLocation[MachineAddress] = location;
|
||||||
|
serverQuerySemaphore.Release();
|
||||||
|
|
||||||
return "?";
|
Frontend.ShowConnectivityDialog(
|
||||||
|
String.Format(Strings.Dialog_Connectivity_UnableToConnect, "ipinfo.io"),
|
||||||
|
Strings.ActivityWatcher_LocationQueryFailed,
|
||||||
|
MessageBoxImage.Warning,
|
||||||
|
ex
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"{PlaceId}/{JobId}";
|
public override string ToString() => $"{PlaceId}/{JobId}";
|
||||||
|
@ -52,9 +52,12 @@ namespace Bloxstrap.Models.SettingTasks
|
|||||||
{
|
{
|
||||||
App.Logger.WriteException(LOG_IDENT, ex);
|
App.Logger.WriteException(LOG_IDENT, ex);
|
||||||
|
|
||||||
Frontend.ShowMessageBox(
|
Frontend.ShowConnectivityDialog(
|
||||||
String.Format(Strings.Menu_Mods_Presets_EmojiType_Error, ex.Message),
|
String.Format(Strings.Dialog_Connectivity_UnableToConnect, "GitHub"),
|
||||||
MessageBoxImage.Warning);
|
$"{Strings.Menu_Mods_Presets_EmojiType_Error}\n\n{Strings.Dialog_Connectivity_TryAgainLater}",
|
||||||
|
MessageBoxImage.Warning,
|
||||||
|
ex
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (query is not null && query.Any())
|
else if (query is not null && query.Any())
|
||||||
|
15
Bloxstrap/Resources/Strings.Designer.cs
generated
15
Bloxstrap/Resources/Strings.Designer.cs
generated
@ -106,7 +106,7 @@ namespace Bloxstrap.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Failed to query server location..
|
/// Looks up a localized string similar to The server location could not be queried. You may be joining games too quickly..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ActivityWatcher_LocationQueryFailed {
|
public static string ActivityWatcher_LocationQueryFailed {
|
||||||
get {
|
get {
|
||||||
@ -512,6 +512,15 @@ namespace Bloxstrap.Resources {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Not available.
|
||||||
|
/// </summary>
|
||||||
|
public static string Common_NotAvailable {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Common.NotAvailable", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to OK.
|
/// Looks up a localized string similar to OK.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -2891,9 +2900,7 @@ namespace Bloxstrap.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to The emoji mod could not be applied because of a network error during download.
|
/// Looks up a localized string similar to The emoji mod can not be applied at this time..
|
||||||
///
|
|
||||||
///{0}.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Menu_Mods_Presets_EmojiType_Error {
|
public static string Menu_Mods_Presets_EmojiType_Error {
|
||||||
get {
|
get {
|
||||||
|
@ -1096,9 +1096,7 @@ If not, then please report this exception to the maintainers of this fork. Do NO
|
|||||||
<value>Connected to reserved server</value>
|
<value>Connected to reserved server</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Menu.Mods.Presets.EmojiType.Error" xml:space="preserve">
|
<data name="Menu.Mods.Presets.EmojiType.Error" xml:space="preserve">
|
||||||
<value>The emoji mod could not be applied because of a network error during download.
|
<value>The emoji mod can not be applied at this time.</value>
|
||||||
|
|
||||||
{0}</value>
|
|
||||||
</data>
|
</data>
|
||||||
<data name="Dialog.AlreadyRunning.Installer" xml:space="preserve">
|
<data name="Dialog.AlreadyRunning.Installer" xml:space="preserve">
|
||||||
<value>Please wait for installation to finish.</value>
|
<value>Please wait for installation to finish.</value>
|
||||||
@ -1163,7 +1161,7 @@ Are you sure you want to continue?</value>
|
|||||||
<value>Game history is only recorded for your current Roblox session. Games will appear here as you leave them or teleport within them.</value>
|
<value>Game history is only recorded for your current Roblox session. Games will appear here as you leave them or teleport within them.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ActivityWatcher.LocationQueryFailed" xml:space="preserve">
|
<data name="ActivityWatcher.LocationQueryFailed" xml:space="preserve">
|
||||||
<value>Failed to query server location.</value>
|
<value>The server location could not be queried. You may be joining games too quickly.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Dialog.Connectivity.ServiceDown" xml:space="preserve">
|
<data name="Dialog.Connectivity.ServiceDown" xml:space="preserve">
|
||||||
<value>{0} may be down right now.</value>
|
<value>{0} may be down right now.</value>
|
||||||
@ -1182,4 +1180,7 @@ Are you sure you want to continue?</value>
|
|||||||
|
|
||||||
Please manually delete Bloxstrap.exe from the install location or try restarting your system, and then retry installation afterwards.</value>
|
Please manually delete Bloxstrap.exe from the install location or try restarting your system, and then retry installation afterwards.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Common.NotAvailable" xml:space="preserve">
|
||||||
|
<value>Not available</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -59,7 +59,7 @@ namespace Bloxstrap.UI
|
|||||||
if (_activityWatcher is null)
|
if (_activityWatcher is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string serverLocation = await _activityWatcher.Data.QueryServerLocation();
|
string? serverLocation = await _activityWatcher.Data.QueryServerLocation();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(serverLocation))
|
if (string.IsNullOrEmpty(serverLocation))
|
||||||
return;
|
return;
|
||||||
|
@ -29,7 +29,13 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
|
|||||||
|
|
||||||
public async void QueryServerLocation()
|
public async void QueryServerLocation()
|
||||||
{
|
{
|
||||||
ServerLocation = await _activityWatcher.Data.QueryServerLocation();
|
string? location = await _activityWatcher.Data.QueryServerLocation();
|
||||||
|
|
||||||
|
if (String.IsNullOrEmpty(location))
|
||||||
|
ServerLocation = Strings.Common_NotAvailable;
|
||||||
|
else
|
||||||
|
ServerLocation = location;
|
||||||
|
|
||||||
OnPropertyChanged(nameof(ServerLocation));
|
OnPropertyChanged(nameof(ServerLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user