Skip to content

Commit

Permalink
Make activity tracking an independent option
Browse files Browse the repository at this point in the history
also moved server location info logic to the activity handler itself as i plan to also use it in an informational window accessible from the context menu
  • Loading branch information
pizzaboxer committed Jul 19, 2023
1 parent 5f9f63d commit ce1c2bc
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Bloxstrap/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions Bloxstrap/RobloxActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class RobloxActivity : IDisposable
public event EventHandler? OnGameLeave;
public event EventHandler<GameMessage>? OnGameMessage;

private Dictionary<string, string> 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
Expand Down Expand Up @@ -213,9 +215,37 @@ private void ExamineLogEntry(string entry)
}
}

public async Task<string> 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);
}
}
}
40 changes: 26 additions & 14 deletions Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,33 @@
<StackPanel Margin="0,0,14,14">
<TextBlock Text="Configure quick and easy ways to improve the Roblox gameplay experience." FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />

<TextBlock Text="Discord Rich Presence" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<TextBlock Text="Roblox activity tracking" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<ui:CardControl Margin="0,8,0,0">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Enable activity tracking" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Allows for Bloxstrap to detect what Roblox game you're playing. Certain features may require this." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch x:Name="ActivityTrackingEnabledToggle" IsChecked="{Binding ActivityTrackingEnabled, Mode=TwoWay}" />
</ui:CardControl>
<ui:CardControl Margin="0,8,0,0" IsEnabled="{Binding IsChecked, ElementName=ActivityTrackingEnabledToggle, Mode=OneWay}">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Know where your server's located" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="When you join a game, you'll be notified of the server's location. Won't show in fullscreen." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch IsChecked="{Binding ShowServerDetailsEnabled, Mode=TwoWay}" />
</ui:CardControl>

<TextBlock Text="Discord Rich Presence" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<TextBlock Margin="0,4,0,0" Text="This feature requires activity tracking to be enabled." TextWrapping="Wrap" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<ui:CardControl Margin="0,8,0,0" IsEnabled="{Binding IsChecked, ElementName=ActivityTrackingEnabledToggle, Mode=OneWay}">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Show game activity" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="The game you're playing on Roblox will show on your Discord activity." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="When playing a Roblox game, the game you're playing will show on your Discord profile activity." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch x:Name="DiscordActivityEnabledToggle" IsChecked="{Binding DiscordActivityEnabled, Mode=TwoWay}" />
Expand All @@ -26,7 +47,7 @@
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Allow activity joining" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="When enabled, anyone can join your game through your Discord activity." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Allows for anybody to join the game you're currently in through your Discord profile." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch IsChecked="{Binding DiscordActivityJoinEnabled, Mode=TwoWay}" />
Expand All @@ -36,17 +57,8 @@
<ui:CardControl Margin="0,8,0,0">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Be notified of server details on game join" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Lets you see location and Job ID of current server. These will not show when in fullscreen." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch IsChecked="{Binding ShowServerDetailsEnabled, Mode=TwoWay}" />
</ui:CardControl>
<ui:CardControl Margin="0,8,0,0">
<ui:CardControl.Header>
<StackPanel>
<TextBlock FontSize="14" Text="Allow multi-game instance launching" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Roblox will allow having more than one game instance open simultaneously." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
<TextBlock FontSize="14" Text="Allow multi-instance launching" />
<TextBlock Margin="0,2,0,0" FontSize="12" Text="Allows for having more than one Roblox game client instance open simultaneously." Foreground="{DynamicResource TextFillColorTertiaryBrush}" />
</StackPanel>
</ui:CardControl.Header>
<ui:ToggleSwitch IsChecked="{Binding MultiInstanceLaunchingEnabled, Mode=TwoWay}" />
Expand Down
31 changes: 4 additions & 27 deletions Bloxstrap/UI/NotifyIconWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 26 additions & 6 deletions Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ce1c2bc

Please sign in to comment.