diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index f9ae13f6..52a1da03 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -247,7 +247,7 @@ private async Task StartRoblox() return; } - if (App.Settings.Prop.UseDiscordRichPresence || App.Settings.Prop.ShowServerDetails) + if (App.Settings.Prop.EnableActivityTracking) { activityWatcher = new(); shouldWait = true; diff --git a/Bloxstrap/Models/Settings.cs b/Bloxstrap/Models/Settings.cs index 4ba664a1..638052be 100644 --- a/Bloxstrap/Models/Settings.cs +++ b/Bloxstrap/Models/Settings.cs @@ -20,6 +20,7 @@ public class Settings public ChannelChangeMode ChannelChangeMode { get; set; } = ChannelChangeMode.Automatic; // integration configuration + public bool EnableActivityTracking { get; set; } = true; public bool UseDiscordRichPresence { get; set; } = true; public bool HideRPCButtons { get; set; } = true; public bool ShowServerDetails { get; set; } = false; diff --git a/Bloxstrap/RobloxActivity.cs b/Bloxstrap/RobloxActivity.cs index a0e89e27..1966ac1f 100644 --- a/Bloxstrap/RobloxActivity.cs +++ b/Bloxstrap/RobloxActivity.cs @@ -21,6 +21,8 @@ public class RobloxActivity : IDisposable public event EventHandler? OnGameLeave; public event EventHandler? OnGameMessage; + private Dictionary GeolcationCache = new(); + // these are values to use assuming the player isn't currently in a game // keep in mind ActivityIsTeleport is only reset by DiscordRichPresence when it's done accessing it // because of the weird chronology of where the teleporting entry is outputted, there's no way to reset it in here @@ -213,9 +215,37 @@ private void ExamineLogEntry(string entry) } } + public async Task GetServerLocation() + { + if (GeolcationCache.ContainsKey(ActivityMachineAddress)) + return GeolcationCache[ActivityMachineAddress]; + + string location = ""; + + string locationCity = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/city"); + string locationRegion = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/region"); + string locationCountry = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/country"); + + 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}"; + + GeolcationCache[ActivityMachineAddress] = location; + + return location; + } + public void Dispose() { IsDisposed = true; + GC.SuppressFinalize(this); } } } diff --git a/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml index 9f6589d1..4e89f64a 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml @@ -12,12 +12,33 @@ - + + + + + + + + + + + + + + + + + + + + + + - + @@ -26,7 +47,7 @@ - + @@ -36,17 +57,8 @@ - - - - - - - - - - - + + diff --git a/Bloxstrap/UI/NotifyIconWrapper.cs b/Bloxstrap/UI/NotifyIconWrapper.cs index 9194417d..f98722e2 100644 --- a/Bloxstrap/UI/NotifyIconWrapper.cs +++ b/Bloxstrap/UI/NotifyIconWrapper.cs @@ -46,35 +46,12 @@ public void SetActivityWatcher(RobloxActivity activityWatcher) public async void OnGameJoin() { - if (!App.Settings.Prop.ShowServerDetails) - return; - - App.Logger.WriteLine($"[NotifyIconWrapper::OnActivityGameJoin] Getting game/server information"); - - string machineAddress = _activityWatcher!.ActivityMachineAddress; - string machineLocation = ""; - - // basically nobody has a free public access geolocation api that's accurate, - // the ones that do require an api key which isn't suitable for a client-side application like this - // so, hopefully this is reliable enough? - string locationCity = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{machineAddress}/city"); - string locationRegion = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{machineAddress}/region"); - string locationCountry = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{machineAddress}/country"); - - locationCity = locationCity.ReplaceLineEndings(""); - locationRegion = locationRegion.ReplaceLineEndings(""); - locationCountry = locationCountry.ReplaceLineEndings(""); - - if (String.IsNullOrEmpty(locationCountry)) - machineLocation = "N/A"; - else if (locationCity == locationRegion) - machineLocation = $"{locationRegion}, {locationCountry}"; - else - machineLocation = $"{locationCity}, {locationRegion}, {locationCountry}"; - + string serverLocation = await _activityWatcher!.GetServerLocation(); + _menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Visible); - ShowAlert("Connnected to server", $"Location: {machineLocation}\nClick to copy Instance ID", 10, (_, _) => System.Windows.Clipboard.SetText(_activityWatcher.ActivityJobId)); + if (App.Settings.Prop.ShowServerDetails) + ShowAlert("Connnected to server", $"Location: {serverLocation}", 10, (_, _) => Clipboard.SetText(_activityWatcher.ActivityJobId)); } public void OnGameLeave(object? sender, EventArgs e) diff --git a/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs index 640b8b84..2776c880 100644 --- a/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs @@ -39,6 +39,32 @@ private void DeleteIntegration() OnPropertyChanged(nameof(IsCustomIntegrationSelected)); } + public bool ActivityTrackingEnabled + { + get => App.Settings.Prop.EnableActivityTracking; + set + { + App.Settings.Prop.EnableActivityTracking = value; + + if (!value) + { + ShowServerDetailsEnabled = value; + DiscordActivityEnabled = value; + DiscordActivityJoinEnabled = value; + + OnPropertyChanged(nameof(ShowServerDetailsEnabled)); + OnPropertyChanged(nameof(DiscordActivityEnabled)); + OnPropertyChanged(nameof(DiscordActivityJoinEnabled)); + } + } + } + + public bool ShowServerDetailsEnabled + { + get => App.Settings.Prop.ShowServerDetails; + set => App.Settings.Prop.ShowServerDetails = value; + } + public bool DiscordActivityEnabled { get => App.Settings.Prop.UseDiscordRichPresence; @@ -60,12 +86,6 @@ public bool DiscordActivityJoinEnabled set => App.Settings.Prop.HideRPCButtons = !value; } - public bool ShowServerDetailsEnabled - { - get => App.Settings.Prop.ShowServerDetails; - set => App.Settings.Prop.ShowServerDetails = value; - } - public bool MultiInstanceLaunchingEnabled { get => App.Settings.Prop.MultiInstanceLaunching;