Skip to content

Commit

Permalink
Check channel by comparing against LIVE
Browse files Browse the repository at this point in the history
also change how version comparisons work
  • Loading branch information
pizzaboxer committed Jul 17, 2023
1 parent 0b8b9ea commit 607075c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 33 deletions.
5 changes: 2 additions & 3 deletions Bloxstrap/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,10 @@ private async Task CheckForUpdates()
return;
}

int numCurrentVersion = Utilities.VersionToNumber(App.Version);
int numLatestVersion = Utilities.VersionToNumber(releaseInfo.TagName);
int versionComparison = Utilities.CompareVersions(App.Version, releaseInfo.TagName);

// check if we aren't using a deployed build, so we can update to one if a new version comes out
if (numCurrentVersion == numLatestVersion && App.BuildMetadata.CommitRef.StartsWith("tag") || numCurrentVersion > numLatestVersion)
if (versionComparison == 0 && App.BuildMetadata.CommitRef.StartsWith("tag") || versionComparison == -1)
{
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found");
return;
Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/Models/ClientVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class ClientVersion
public string BootstrapperVersion { get; set; } = null!;

public DateTime? Timestamp { get; set; }

public bool IsBehindDefaultChannel { get; set; }
}
}
66 changes: 45 additions & 21 deletions Bloxstrap/RobloxDeployment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public static class RobloxDeployment
#region Properties
public const string DefaultChannel = "LIVE";

private static Dictionary<string, ClientVersion> ClientVersionCache = new();

// a list of roblox delpoyment locations that we check for, in case one of them don't work
private static List<string> BaseUrls = new()
{
Expand Down Expand Up @@ -77,36 +79,47 @@ public static string GetLocation(string resource, string? channel = null)
return location;
}

public static async Task<ClientVersion> GetInfo(string channel, bool timestamp = false)
public static async Task<ClientVersion> GetInfo(string channel, bool extraInformation = false)
{
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Getting deploy info for channel {channel} (timestamp={timestamp})");

HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}");
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Getting deploy info for channel {channel} (extraInformation={extraInformation})");

string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync();
ClientVersion clientVersion;

if (!deployInfoResponse.IsSuccessStatusCode)
if (ClientVersionCache.ContainsKey(channel))
{
// 400 = Invalid binaryType.
// 404 = Could not find version details for binaryType.
// 500 = Error while fetching version information.
// either way, we throw

App.Logger.WriteLine(
"[RobloxDeployment::GetInfo] Failed to fetch deploy info!\r\n" +
$"\tStatus code: {deployInfoResponse.StatusCode}\r\n" +
$"\tResponse: {rawResponse}"
);

throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})");
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] Deploy information is cached");
clientVersion = ClientVersionCache[channel];
}
else
{
HttpResponseMessage deployInfoResponse = await App.HttpClient.GetAsync($"https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/{channel}");

ClientVersion clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!;
string rawResponse = await deployInfoResponse.Content.ReadAsStringAsync();

if (!deployInfoResponse.IsSuccessStatusCode)
{
// 400 = Invalid binaryType.
// 404 = Could not find version details for binaryType.
// 500 = Error while fetching version information.
// either way, we throw

App.Logger.WriteLine(
"[RobloxDeployment::GetInfo] Failed to fetch deploy info!\r\n" +
$"\tStatus code: {deployInfoResponse.StatusCode}\r\n" +
$"\tResponse: {rawResponse}"
);

throw new Exception($"Could not get latest deploy for channel {channel}! (HTTP {deployInfoResponse.StatusCode})");
}

clientVersion = JsonSerializer.Deserialize<ClientVersion>(rawResponse)!;
}


// for preferences
if (timestamp)
if (extraInformation && clientVersion.Timestamp is null)
{
App.Logger.WriteLine("[RobloxDeployment::GetInfo] Getting timestamp...");
App.Logger.WriteLine("[RobloxDeployment::GetInfo] Getting extra information...");

string manifestUrl = GetLocation($"/{clientVersion.VersionGuid}-rbxPkgManifest.txt", channel);

Expand All @@ -119,8 +132,19 @@ public static async Task<ClientVersion> GetInfo(string channel, bool timestamp =
App.Logger.WriteLine($"[RobloxDeployment::GetInfo] {manifestUrl} - Last-Modified: {lastModified}");
clientVersion.Timestamp = DateTime.Parse(lastModified).ToLocalTime();
}

// check if channel is behind LIVE
if (channel != DefaultChannel)
{
var defaultClientVersion = await GetInfo(DefaultChannel);

if (Utilities.CompareVersions(clientVersion.Version, defaultClientVersion.Version) == -1)
clientVersion.IsBehindDefaultChannel = true;
}
}

ClientVersionCache[channel] = clientVersion;

return clientVersion;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Elements/Menu/Pages/BehaviourPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

<StackPanel Grid.Row="3" Grid.ColumnSpan="2" Margin="0,16,0,0" Orientation="Horizontal" Visibility="{Binding ChannelWarningVisibility, Mode=OneWay}">
<Image Grid.Column="0" Width="24" Height="24" RenderOptions.BitmapScalingMode="HighQuality" Source="pack://application:,,,/Resources/MessageBox/Warning.png" />
<TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Text="This channel may be out of date, as it was last deployed to over a month ago." />
<TextBlock Margin="8,0,0,0" VerticalAlignment="Center" Text="This channel is out of date, and is likely no longer being updated. Please use another channel." />
</StackPanel>
</Grid>
<Grid Column="0">
Expand Down
5 changes: 1 addition & 4 deletions Bloxstrap/UI/ViewModels/Menu/BehaviourViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ private async Task LoadChannelDeployInfo(string channel)
{
ClientVersion info = await RobloxDeployment.GetInfo(channel, true);

if (info.Timestamp?.AddMonths(1) < DateTime.Now)
ChannelWarningVisibility = Visibility.Visible;
else
ChannelWarningVisibility = Visibility.Collapsed;
ChannelWarningVisibility = info.IsBehindDefaultChannel ? Visibility.Visible : Visibility.Collapsed;

ChannelDeployInfo = new DeployInfo
{
Expand Down
20 changes: 16 additions & 4 deletions Bloxstrap/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ public static long GetFreeDiskSpace(string path)

public static void ShellExecute(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true });

public static int VersionToNumber(string version)
/// <summary>
///
/// </summary>
/// <param name="versionStr1"></param>
/// <param name="versionStr2"></param>
/// <returns>
/// Result of System.Version.CompareTo <br />
/// -1: version1 &lt; version2 <br />
/// 0: version1 == version2 <br />
/// 1: version1 &gt; version2
/// </returns>
public static int CompareVersions(string versionStr1, string versionStr2)
{
// yes this is kinda stupid lol
version = version.Replace("v", "").Replace(".", "");
return Int32.Parse(version);
var version1 = new Version(versionStr1.Replace("v", ""));
var version2 = new Version(versionStr2.Replace("v", ""));

return version1.CompareTo(version2);
}
}
}

0 comments on commit 607075c

Please sign in to comment.