Skip to content

Commit

Permalink
Add detection for reserved/private server types
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Jul 20, 2023
1 parent 5205287 commit 890f7a1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 31 deletions.
9 changes: 9 additions & 0 deletions Bloxstrap/Enums/ServerType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Bloxstrap.Enums
{
public enum ServerType
{
Public,
Private,
Reserved
}
}
64 changes: 43 additions & 21 deletions Bloxstrap/RobloxActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class RobloxActivity : IDisposable
// i'm thinking the functionality for parsing roblox logs could be broadened for more features than just rich presence,
// like checking the ping and region of the current connected server. maybe that's something to add?
private const string GameJoiningEntry = "[FLog::Output] ! Joining game";
private const string GameJoiningPrivateServerEntry = "[FLog::GameJoinUtil] GameJoinUtil::joinGamePostPrivateServer";
private const string GameJoiningReservedServerEntry = "[FLog::GameJoinUtil] GameJoinUtil::initiateTeleportToReservedServer";
private const string GameJoiningUDMUXEntry = "[FLog::Network] UDMUX Address = ";
private const string GameJoinedEntry = "[FLog::Network] serverId:";
private const string GameDisconnectedEntry = "[FLog::Network] Time to disconnect replication data:";
Expand All @@ -17,6 +19,7 @@ public class RobloxActivity : IDisposable

private int _logEntriesRead = 0;
private bool _teleportMarker = false;
private bool _reservedTeleportMarker = false;

public event EventHandler<string>? OnLogEntry;
public event EventHandler? OnGameJoin;
Expand All @@ -28,12 +31,14 @@ public class RobloxActivity : IDisposable
public string LogFilename = null!;

// these are values to use assuming the player isn't currently in a game
// hmm... do i move this to a model?
public bool ActivityInGame = false;
public long ActivityPlaceId = 0;
public string ActivityJobId = "";
public string ActivityMachineAddress = "";
public bool ActivityMachineUDMUX = false;
public bool ActivityIsTeleport = false;
public ServerType ActivityServerType = ServerType.Public;

public bool IsDisposed = false;

Expand Down Expand Up @@ -113,33 +118,43 @@ private void ExamineLogEntry(string entry)
else if (_logEntriesRead % 100 == 0)
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Read {_logEntriesRead} log entries");

if (!ActivityInGame && ActivityPlaceId == 0 && entry.Contains(GameJoiningEntry))
if (!ActivityInGame && ActivityPlaceId == 0)
{
Match match = Regex.Match(entry, GameJoiningEntryPattern);

if (match.Groups.Count != 4)
if (entry.Contains(GameJoiningPrivateServerEntry))
{
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Failed to assert format for game join entry");
App.Logger.WriteLine(entry);
return;
// we only expect to be joining a private server if we're not already in a game
ActivityServerType = ServerType.Private;
}
else if (entry.Contains(GameJoiningEntry))
{
Match match = Regex.Match(entry, GameJoiningEntryPattern);

ActivityInGame = false;
ActivityPlaceId = long.Parse(match.Groups[2].Value);
ActivityJobId = match.Groups[1].Value;
ActivityMachineAddress = match.Groups[3].Value;
if (match.Groups.Count != 4)
{
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Failed to assert format for game join entry");
App.Logger.WriteLine(entry);
return;
}

if (_teleportMarker)
{
ActivityIsTeleport = true;
_teleportMarker = false;
}
else
{
ActivityIsTeleport = false;
}
ActivityInGame = false;
ActivityPlaceId = long.Parse(match.Groups[2].Value);
ActivityJobId = match.Groups[1].Value;
ActivityMachineAddress = match.Groups[3].Value;

if (_teleportMarker)
{
ActivityIsTeleport = true;
_teleportMarker = false;
}

App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Joining Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
if (_reservedTeleportMarker)
{
ActivityServerType = ServerType.Reserved;
_reservedTeleportMarker = false;
}

App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Joining Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
}
}
else if (!ActivityInGame && ActivityPlaceId != 0)
{
Expand Down Expand Up @@ -187,6 +202,8 @@ private void ExamineLogEntry(string entry)
ActivityJobId = "";
ActivityMachineAddress = "";
ActivityMachineUDMUX = false;
ActivityIsTeleport = false;
ActivityServerType = ServerType.Public;

OnGameLeave?.Invoke(this, new EventArgs());
}
Expand All @@ -195,6 +212,11 @@ private void ExamineLogEntry(string entry)
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Initiating teleport to server ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
_teleportMarker = true;
}
else if (_teleportMarker && entry.Contains(GameJoiningReservedServerEntry))
{
// we only expect to be joining a reserved server if we're teleporting to one from a game
_reservedTeleportMarker = true;
}
else if (entry.Contains(GameMessageEntry))
{
string messagePlain = entry.Substring(entry.IndexOf(GameMessageEntry) + GameMessageEntry.Length + 1);
Expand Down
31 changes: 22 additions & 9 deletions Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
MinWidth="0"
MinHeight="0"
Width="400"
Height="230"
SizeToContent="Height"
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
Expand All @@ -26,17 +26,30 @@

<ui:TitleBar Grid.Row="0" Grid.ColumnSpan="2" Padding="8" x:Name="RootTitleBar" Title="Server information" ShowMinimize="False" ShowMaximize="False" CanMaximize="False" KeyboardNavigation.TabNavigation="None" Icon="pack://application:,,,/Bloxstrap.ico" />

<StackPanel Grid.Row="1" Margin="12">
<TextBlock Text="Instance ID" FontSize="16" FontWeight="Medium" />
<TextBlock Text="{Binding InstanceId, Mode=OneWay}" />
<Grid Grid.Row="1" Margin="16,8,16,16">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<TextBlock Margin="0,16,0,0" Text="Server location" FontSize="16" FontWeight="Medium" />
<TextBlock Text="{Binding ServerLocation, Mode=OneWay}" />
</StackPanel>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,16,8" VerticalAlignment="Center" Text="Type" />
<TextBlock Grid.Row="0" Grid.Column="1" Foreground="{DynamicResource TextFillColorTertiaryBrush}" Text="{Binding ServerType, Mode=OneWay}" />

<Border Grid.Row="2" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,16,8" VerticalAlignment="Center" Text="Instance ID" />
<TextBlock Grid.Row="1" Grid.Column="1" Foreground="{DynamicResource TextFillColorTertiaryBrush}" Text="{Binding InstanceId, Mode=OneWay}" />

<TextBlock Grid.Row="2" Grid.Column="0" Margin="0,0,16,0" VerticalAlignment="Center" Text="Location" />
<TextBlock Grid.Row="2" Grid.Column="1" Foreground="{DynamicResource TextFillColorTertiaryBrush}" Text="{Binding ServerLocation, Mode=OneWay}" />
</Grid>

<Border Grid.Row="2" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
<Button MinWidth="100" Content="Copy instance ID" Command="{Binding CopyInstanceIdCommand, Mode=OneTime}" />
<Button MinWidth="100" Content="Copy Instance ID" Command="{Binding CopyInstanceIdCommand, Mode=OneTime}" />
<Button Margin="12,0,0,0" MinWidth="100" Content="Close" Command="{Binding CloseWindowCommand, Mode=OneTime}" />
</StackPanel>
</Border>
Expand Down
8 changes: 7 additions & 1 deletion Bloxstrap/UI/NotifyIconWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEve
public async void OnGameJoin()
{
string serverLocation = await _activityWatcher!.GetServerLocation();
ShowAlert("Connnected to server", $"Location: {serverLocation}\nClick for more information", 10, (_, _) => _menuContainer?.ShowServerInformationWindow());

ShowAlert(
$"Connnected to {_activityWatcher.ActivityServerType.ToString().ToLower()} server",
$"Located at {serverLocation}\nClick for more information",
10,
(_, _) => _menuContainer?.ShowServerInformationWindow()
);
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class ServerInformationViewModel : NotifyPropertyChangedViewModel
private readonly RobloxActivity _activityWatcher;

public string InstanceId => _activityWatcher.ActivityJobId;
public string ServerType => $"{_activityWatcher.ActivityServerType} server";
public string ServerLocation { get; private set; } = "Loading, please wait...";

public ICommand CopyInstanceIdCommand => new RelayCommand(CopyInstanceId);
Expand Down

0 comments on commit 890f7a1

Please sign in to comment.