mirror of
https://github.com/Ace-73/RC2Launcher-Git.git
synced 2025-04-01 17:40:59 +00:00
Added 'online builder count' display and made player count checks async to prevent launcher from freezing
This commit is contained in:
parent
a99b0c6e71
commit
39a1b42029
4 changed files with 103 additions and 50 deletions
Bobocraft 2 Launcher v11 actually fixed countdown/GameLauncher
|
@ -16,6 +16,7 @@
|
|||
<None Remove="LauncherBackground.png" />
|
||||
<None Remove="shape_square.png" />
|
||||
<None Remove="user-1808597_1280.png" />
|
||||
<None Remove="user-orange.png" />
|
||||
<None Remove="vector_dizzy.png" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -32,6 +33,7 @@
|
|||
<Resource Include="LauncherBackground.png" />
|
||||
<Resource Include="shape_square.png" />
|
||||
<Resource Include="user-1808597_1280.png" />
|
||||
<Resource Include="user-orange.png" />
|
||||
<Resource Include="vector_dizzy.png" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@
|
|||
<Image Name="OnlineUserpfp" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="62,57,0,0" Height="40" Width="40" Source="/user-1808597_1280.png"/>
|
||||
<TextBlock x:Name="CraftersOnlineText" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" Background="#7F000000" Foreground="LightGreen" Margin="15,105,0,0" Text="Crafters Online Now!"/>
|
||||
<TextBlock x:Name="CraftersOnlineNumber" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="30" Background="#7F000000" Foreground="LightGreen" Margin="21,57,0,0" Text="0"/>
|
||||
|
||||
<Image Name="BuildingUserpfp" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="62,123,0,0" Height="40" Width="40" Source="/user-orange.png"/>
|
||||
<TextBlock x:Name="CraftersBuildingText" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" Background="#7F000000" Foreground="Orange" Margin="15,168,0,0" Text="Crafters Building Now!"/>
|
||||
<TextBlock x:Name="CraftersBuildingNumber" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="30" Background="#7F000000" Foreground="Orange" Margin="21,123,0,0" Text="0"/>
|
||||
|
||||
<Button Name ="DiscordButtonLFP" BorderThickness="0" Click ="DiscordButton_ClickLFP" Background="#00000000" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,102,316,0" Height="20" Width="23" RenderTransformOrigin="-1.39,1.253">
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Width="20" Height="20">
|
||||
<Image Source="/discord-mark-blue.png" HorizontalAlignment="Left" VerticalAlignment="Center" Width="20" Height="20" />
|
||||
|
|
|
@ -16,6 +16,7 @@ using System.Text.Json;
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Windows.Media;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameLauncher
|
||||
{
|
||||
|
@ -66,9 +67,14 @@ namespace GameLauncher
|
|||
private string NextSessionFile;
|
||||
private string NextSessionFileLink;
|
||||
private string NorbiServerInfoLink;
|
||||
private string NorbiGameInfoLink;
|
||||
private string ServerInfoJson;
|
||||
private string ServerInfoString;
|
||||
private string GameInfoJson;
|
||||
private string GameInfoString;
|
||||
private int PlayerCount;
|
||||
private int BuilderCount;
|
||||
private bool ErrorCheckingPlayerCounts;
|
||||
|
||||
|
||||
private LauncherStatus _status;
|
||||
|
@ -149,9 +155,14 @@ namespace GameLauncher
|
|||
CSCZipLink = "https://cloud.norbipeti.eu/s/6dTzZyAbyXRwHc9/download/Connection%20Health%20Calculator.zip";
|
||||
NextSessionFileLink = "https://drive.google.com/uc?export=download&id=1lMctvUExhyjw8FRrpiCKmfVnqNQMI7U7";
|
||||
NorbiServerInfoLink = "https://norbipeti.eu/rc2matchmaking/servers";
|
||||
NorbiGameInfoLink = "https://norbipeti.eu/rc2matchmaking/custom-apps/info";
|
||||
PlayerCount = 0;
|
||||
SetupTimer();
|
||||
BuilderCount = 0;
|
||||
ErrorCheckingPlayerCounts = false;
|
||||
|
||||
CheckPlayerCount();
|
||||
CheckBuilderCount();
|
||||
SetupTimer();
|
||||
}
|
||||
|
||||
private void SetupTimer()
|
||||
|
@ -174,9 +185,92 @@ namespace GameLauncher
|
|||
CountdownLabel.Content = "ROBOCRAFT SESSION TODAY!";
|
||||
}
|
||||
else { CountdownLabel.Content = $"{timeLeft.Days} days {timeLeft.Hours} hours {timeLeft.Minutes} minutes {timeLeft.Seconds} seconds"; }
|
||||
CheckPlayerCount();
|
||||
if (ErrorCheckingPlayerCounts == false && Status == LauncherStatus.ready) { CheckPlayerCount(); CheckBuilderCount(); }
|
||||
//CheckPlayerCount();
|
||||
});
|
||||
}
|
||||
|
||||
private async Task CheckPlayerCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Headers.Add("Authorization", "TlBDQVRSQzI=");
|
||||
ServerInfoJson = await webClient.DownloadStringTaskAsync(NorbiServerInfoLink);
|
||||
JArray _ServerArray = new JArray();
|
||||
_ServerArray = JArray.Parse(ServerInfoJson);
|
||||
PlayerCount = 0;
|
||||
for (int i = 0; i < _ServerArray.Count; i++)
|
||||
{
|
||||
var server = _ServerArray[i];
|
||||
var onlinePlayers = server["onlinePlayers"];
|
||||
int PlayersInt = 0;
|
||||
int.TryParse(onlinePlayers.ToString(), out PlayersInt);
|
||||
PlayerCount += PlayersInt;
|
||||
}
|
||||
|
||||
if (PlayerCount > 0)
|
||||
{
|
||||
CraftersOnlineNumber.Text = PlayerCount.ToString();
|
||||
CraftersOnlineNumber.Visibility = Visibility.Visible;
|
||||
CraftersOnlineText.Visibility = Visibility.Visible;
|
||||
OnlineUserpfp.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
CraftersOnlineNumber.Visibility = Visibility.Hidden;
|
||||
CraftersOnlineText.Visibility = Visibility.Hidden;
|
||||
OnlineUserpfp.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = LauncherStatus.failed;
|
||||
ErrorCheckingPlayerCounts = true;
|
||||
MessageBox.Show($"Error checking for server info: {ex}");
|
||||
}
|
||||
}
|
||||
private async Task CheckBuilderCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Headers.Add("Authorization", "TlBDQVRSQzI=");
|
||||
GameInfoJson = await webClient.DownloadStringTaskAsync(NorbiGameInfoLink);
|
||||
JObject jsonObject = JObject.Parse(GameInfoJson);
|
||||
int BuildersInt = (int)jsonObject["onlinePlayerCount"];
|
||||
BuilderCount = 0;
|
||||
BuilderCount += BuildersInt;
|
||||
BuilderCount -= PlayerCount;
|
||||
|
||||
if (BuilderCount > 0)
|
||||
{
|
||||
CraftersBuildingNumber.Text = BuilderCount.ToString();
|
||||
CraftersBuildingNumber.Visibility = Visibility.Visible;
|
||||
CraftersBuildingText.Visibility = Visibility.Visible;
|
||||
BuildingUserpfp.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
CraftersBuildingNumber.Visibility = Visibility.Hidden;
|
||||
CraftersBuildingText.Visibility = Visibility.Hidden;
|
||||
BuildingUserpfp.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = LauncherStatus.failed;
|
||||
ErrorCheckingPlayerCounts = true;
|
||||
MessageBox.Show($"Error checking for server info: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void PullSessionTimeFromLink()
|
||||
{
|
||||
var Localtimezone = TimeZoneInfo.Local;
|
||||
|
@ -319,54 +413,6 @@ namespace GameLauncher
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void CheckPlayerCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Headers.Add("Authorization", "TlBDQVRSQzI=");
|
||||
ServerInfoJson = webClient.DownloadString(NorbiServerInfoLink);
|
||||
JArray _ServerArray = new JArray();
|
||||
_ServerArray = JArray.Parse(ServerInfoJson);
|
||||
PlayerCount = 0;
|
||||
for(int i = 0; i < _ServerArray.Count; i++)
|
||||
{
|
||||
var server = _ServerArray[i];
|
||||
var onlinePlayers = server["onlinePlayers"];
|
||||
int PlayersInt = 0;
|
||||
int.TryParse(onlinePlayers.ToString(), out PlayersInt);
|
||||
PlayerCount += PlayersInt;
|
||||
}
|
||||
if (PlayerCount > 0)
|
||||
{
|
||||
CraftersOnlineNumber.Text = PlayerCount.ToString();
|
||||
//CraftersOnlineNumber.Foreground = new SolidColorBrush(Colors.LightGreen);
|
||||
CraftersOnlineNumber.Visibility = Visibility.Visible;
|
||||
CraftersOnlineText.Visibility = Visibility.Visible;
|
||||
OnlineUserpfp.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
CraftersOnlineNumber.Visibility = Visibility.Hidden;
|
||||
CraftersOnlineText.Visibility = Visibility.Hidden;
|
||||
OnlineUserpfp.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = LauncherStatus.failed;
|
||||
MessageBox.Show($"Error checking for server info: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void CheckForCRFManagerUpdates()
|
||||
{
|
||||
if (File.Exists(CRF2ManagerVersionFile))
|
||||
|
|
Binary file not shown.
After ![]() (image error) Size: 75 KiB |
Loading…
Add table
Reference in a new issue