-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chaniru Rajapakse
committed
May 31, 2022
1 parent
1d0d406
commit a9c49c8
Showing
26 changed files
with
396 additions
and
203 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml.Media.Imaging; | ||
using SDLauncher_UWP.Helpers; | ||
|
||
namespace SDLauncher_UWP.DataTemplates | ||
{ | ||
public class ServerTemplate : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged = delegate { }; | ||
//server | ||
private string server; | ||
public string Server { get => server; private set { server = value; OnPropertyChanged(); UpdateStatus(); } } | ||
//Vers | ||
private string ver; | ||
public string Versions { get => ver; set { ver = value; OnPropertyChanged(); } } | ||
//port | ||
private int port; | ||
public int Port { get => port; private set { port = value; OnPropertyChanged(); UpdateStatus(); } } | ||
//max players | ||
private int maxPlayers; | ||
public int MaxPlayers { get => maxPlayers; private set { maxPlayers = value; OnPropertyChanged(); } } | ||
//online players | ||
private int minPlayers; | ||
public int OnlinePlayers { get => minPlayers; private set { minPlayers = value; OnPropertyChanged(); } } | ||
//favicon | ||
private string favicon; | ||
public string Favicon { get => favicon; private set { favicon = value; OnPropertyChanged(); } } | ||
|
||
public ServerTemplate(string server, int port) | ||
{ | ||
Server = server; | ||
Port = port; | ||
UpdateStatus(); | ||
} | ||
|
||
public async void UpdateStatus() | ||
{ | ||
try | ||
{ | ||
var status = ServerStatusJSONConverter.Convert(await Util.DownloadText("https://api.mcstatus.io/status/java/" + Server.Trim() + ":" + Port.ToString())); | ||
if (status.online) | ||
{ | ||
server = status.host; | ||
port = status.port; | ||
MaxPlayers = status.response.players.max; | ||
Versions = status.response.version.name; | ||
OnlinePlayers = status.response.players.online; | ||
OnPropertyChanged(); | ||
Favicon = status.response.favicon; | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
|
||
} | ||
} | ||
private void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<ContentDialog | ||
x:Class="SDLauncher_UWP.Dialogs.ServerChooserDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:SDLauncher_UWP.Dialogs" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Title="Choose or add a server" | ||
Background="{ThemeResource AcrylicInAppFillColorDefaultBrush}" | ||
PrimaryButtonText="Button1" | ||
CloseButtonStyle="{ThemeResource ButtonRevealStyle}" | ||
PrimaryButtonStyle="{ThemeResource ButtonRevealStyle}" | ||
SecondaryButtonStyle="{ThemeResource ButtonRevealStyle}" | ||
SecondaryButtonText="Button2" | ||
CornerRadius="10" | ||
PrimaryButtonClick="ContentDialog_PrimaryButtonClick" | ||
SecondaryButtonClick="ContentDialog_SecondaryButtonClick" | ||
xmlns:data="using:SDLauncher_UWP.DataTemplates"> | ||
|
||
<Grid> | ||
<FlipView BorderBrush="Black" BorderThickness="1" x:Name="view"> | ||
<FlipView.ItemTemplate> | ||
<DataTemplate x:DataType="data:ServerTemplate"> | ||
<Button Padding="15,45" Style="{ThemeResource ChooseButtonSyle}"> | ||
<Grid> | ||
<StackPanel> | ||
<WebView DefaultBackgroundColor="Transparent" Source="{x:Bind Favicon,Mode=OneWay}" HorizontalAlignment="Center"/> | ||
<TextBlock HorizontalAlignment="Center" Style="{ThemeResource SubtitleTextBlockStyle}" Text="{x:Bind Server,Mode=OneWay}"/> | ||
<WebView DefaultBackgroundColor="Transparent" HorizontalAlignment="Center"/> | ||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> | ||
<TextBlock> | ||
<Run Text="{x:Bind Server,Mode=OneWay}"/> : <Run Text="{x:Bind Port.ToString(),Mode=OneWay}"/> | ||
</TextBlock> | ||
</StackPanel> | ||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> | ||
<FontIcon Glyph="" VerticalAlignment="Center"/> | ||
<TextBlock Margin="5,0,0,0" > | ||
<Run Text="{x:Bind OnlinePlayers.ToString(),Mode=OneWay}"/>/ | ||
<Run Text="{x:Bind MaxPlayers.ToString(),Mode=OneWay}"/> playing | ||
</TextBlock> | ||
</StackPanel> | ||
<TextBlock HorizontalAlignment="Center" Text="{x:Bind Versions,Mode=OneWay}"/> | ||
</StackPanel> | ||
</Grid> | ||
</Button> | ||
</DataTemplate> | ||
</FlipView.ItemTemplate> | ||
</FlipView> | ||
</Grid> | ||
</ContentDialog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using SDLauncher_UWP.DataTemplates; | ||
using System.Collections.ObjectModel; | ||
// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace SDLauncher_UWP.Dialogs | ||
{ | ||
public sealed partial class ServerChooserDialog : ContentDialog | ||
{ | ||
public ObservableCollection<ServerTemplate> servers = new ObservableCollection<ServerTemplate>(); | ||
public ServerChooserDialog() | ||
{ | ||
this.InitializeComponent(); | ||
servers.Add(new ServerTemplate("mc.hypixel.net", 25565)); | ||
view.ItemsSource = servers; | ||
} | ||
|
||
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) | ||
{ | ||
} | ||
|
||
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SDLauncher_UWP.Helpers | ||
{ | ||
public static class ServerStatusJSONConverter | ||
{ | ||
public static ServerStatusInfo.Root Convert(string json) | ||
{ | ||
return JsonConvert.DeserializeObject<ServerStatusInfo.Root>(json); | ||
} | ||
} | ||
public class ServerStatusInfo | ||
{ | ||
|
||
public class Root | ||
{ | ||
public bool online { get; set; } | ||
public string host { get; set; } | ||
public int port { get; set; } | ||
public Response response { get; set; } | ||
} | ||
|
||
public class Response | ||
{ | ||
public Version version { get; set; } | ||
public Players players { get; set; } | ||
public Motd motd { get; set; } | ||
public string favicon { get; set; } | ||
public Srv_Record srv_record { get; set; } | ||
} | ||
|
||
public class Version | ||
{ | ||
public string name { get; set; } | ||
public int protocol { get; set; } | ||
} | ||
|
||
public class Players | ||
{ | ||
public int online { get; set; } | ||
public int max { get; set; } | ||
public object[] sample { get; set; } | ||
} | ||
|
||
public class Motd | ||
{ | ||
public string raw { get; set; } | ||
public string clean { get; set; } | ||
public string html { get; set; } | ||
} | ||
|
||
public class Srv_Record | ||
{ | ||
public string host { get; set; } | ||
public int port { get; set; } | ||
} | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.