From cf6861d86fae2d5bfb61749015997383757d13a0 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Tue, 19 Jan 2016 21:51:19 +0100 Subject: [PATCH] Bugfixes --- YJMPD-UWP/Model/NetworkHandler.cs | 20 ++++++++++++++++---- YJMPD-UWP/ViewModels/MatchVM.cs | 5 ++++- YJMPD-UWP/ViewModels/ScoreVM.cs | 5 ++++- YJMPD-UWP/Views/WaitingView.xaml.cs | 8 +------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/YJMPD-UWP/Model/NetworkHandler.cs b/YJMPD-UWP/Model/NetworkHandler.cs index aceee33..42fb893 100644 --- a/YJMPD-UWP/Model/NetworkHandler.cs +++ b/YJMPD-UWP/Model/NetworkHandler.cs @@ -49,6 +49,9 @@ namespace YJMPD_UWP.Model public async Task Write(string data) { + if (client.InputStream == null || client.OutputStream == null) + return false; + dout.WriteString(data + Environment.NewLine); await dout.StoreAsync(); await dout.FlushAsync(); @@ -86,9 +89,18 @@ namespace YJMPD_UWP.Model while (workItem.Status != AsyncStatus.Canceled) { Debug.WriteLine("Awaiting incoming data..."); - string data = await App.Network.Read(); - App.Network.HandleMessage(data); - await Task.Delay(TimeSpan.FromMilliseconds(50)); + + if(client.InputStream != null && client.OutputStream != null) + { + string data = await Read(); + HandleMessage(data); + await Task.Delay(TimeSpan.FromMilliseconds(50)); + } + else + { + Disconnect(); + workItem.Cancel(); + } } }); @@ -98,7 +110,7 @@ namespace YJMPD_UWP.Model public async Task Disconnect() { if(App.Game.Status != GameHandler.GameStatus.STOPPED) - App.Api.LeaveGame(); + await App.Api.LeaveGame(); UpdateNetworkStatus(NetworkStatus.DISCONNECTED); diff --git a/YJMPD-UWP/ViewModels/MatchVM.cs b/YJMPD-UWP/ViewModels/MatchVM.cs index fc2f31c..2bb399f 100644 --- a/YJMPD-UWP/ViewModels/MatchVM.cs +++ b/YJMPD-UWP/ViewModels/MatchVM.cs @@ -62,7 +62,10 @@ namespace YJMPD_UWP.ViewModels { get { - return "There are currently " + App.Game.Players.Count + " players in the match."; + if (App.Game.Players.Count == 1) + return "There is currently " + App.Game.Players.Count + " player in the match."; + else + return "There are currently " + App.Game.Players.Count + " players in the match."; } } diff --git a/YJMPD-UWP/ViewModels/ScoreVM.cs b/YJMPD-UWP/ViewModels/ScoreVM.cs index a4c8286..57add71 100644 --- a/YJMPD-UWP/ViewModels/ScoreVM.cs +++ b/YJMPD-UWP/ViewModels/ScoreVM.cs @@ -36,7 +36,10 @@ namespace YJMPD_UWP.ViewModels { get { - return "There are currently " + App.Game.Players.Count + " players in the match."; + if (App.Game.Players.Count == 1) + return "There is currently " + App.Game.Players.Count + " player in the match."; + else + return "There are currently " + App.Game.Players.Count + " players in the match."; } } } diff --git a/YJMPD-UWP/Views/WaitingView.xaml.cs b/YJMPD-UWP/Views/WaitingView.xaml.cs index 713e797..0d7e197 100644 --- a/YJMPD-UWP/Views/WaitingView.xaml.cs +++ b/YJMPD-UWP/Views/WaitingView.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading.Tasks; using Windows.UI.Xaml.Controls; @@ -9,13 +10,6 @@ namespace YJMPD_UWP.Views public WaitingView() { this.InitializeComponent(); - StartWait(); - } - - private async void StartWait() - { - await Task.Delay(TimeSpan.FromSeconds(2)); - App.Navigate(typeof(PhotoView)); } } }