Add detection for reserved/private server types

This commit is contained in:
pizzaboxer 2023-07-20 23:15:30 +01:00
parent 5205287f36
commit 890f7a14df
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
5 changed files with 83 additions and 32 deletions

View File

@ -0,0 +1,9 @@
namespace Bloxstrap.Enums
{
public enum ServerType
{
Public,
Private,
Reserved
}
}

View File

@ -5,6 +5,8 @@
// 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:";
@ -17,6 +19,7 @@
private int _logEntriesRead = 0;
private bool _teleportMarker = false;
private bool _reservedTeleportMarker = false;
public event EventHandler<string>? OnLogEntry;
public event EventHandler? OnGameJoin;
@ -28,12 +31,14 @@
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;
@ -113,33 +118,43 @@
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;
}
ActivityInGame = false;
ActivityPlaceId = long.Parse(match.Groups[2].Value);
ActivityJobId = match.Groups[1].Value;
ActivityMachineAddress = match.Groups[3].Value;
if (_teleportMarker)
else if (entry.Contains(GameJoiningEntry))
{
ActivityIsTeleport = true;
_teleportMarker = false;
}
else
{
ActivityIsTeleport = false;
}
Match match = Regex.Match(entry, GameJoiningEntryPattern);
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Joining Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
if (match.Groups.Count != 4)
{
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Failed to assert format for game join entry");
App.Logger.WriteLine(entry);
return;
}
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;
}
if (_reservedTeleportMarker)
{
ActivityServerType = ServerType.Reserved;
_reservedTeleportMarker = false;
}
App.Logger.WriteLine($"[RobloxActivity::ExamineLogEntry] Joining Game ({ActivityPlaceId}/{ActivityJobId}/{ActivityMachineAddress})");
}
}
else if (!ActivityInGame && ActivityPlaceId != 0)
{
@ -187,6 +202,8 @@
ActivityJobId = "";
ActivityMachineAddress = "";
ActivityMachineUDMUX = false;
ActivityIsTeleport = false;
ActivityServerType = ServerType.Public;
OnGameLeave?.Invoke(this, new EventArgs());
}
@ -195,6 +212,11 @@
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);

View File

@ -12,7 +12,7 @@
MinWidth="0"
MinHeight="0"
Width="400"
Height="230"
SizeToContent="Height"
ResizeMode="NoResize"
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
@ -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>

View File

@ -78,7 +78,13 @@ namespace Bloxstrap.UI
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

View File

@ -11,6 +11,7 @@ namespace Bloxstrap.UI.ViewModels.ContextMenu
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);