From 356c3bebc7908ba2607a6aea49dd66a8d0c46551 Mon Sep 17 00:00:00 2001 From: Stenlan Date: Sun, 11 Oct 2020 02:50:59 +0200 Subject: [PATCH] Added rough exception handling for socket connection --- .vs/slnx.sqlite | Bin 90112 -> 90112 bytes AmongUsCapture/ClientSocket.cs | 11 +++++++++++ AmongUsCapture/Program.cs | 1 - .../PublishProfiles/FolderProfile.pubxml | 2 +- AmongUsCapture/UserForm.cs | 1 - 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 9f0e9e69f94a679dd7c64724494b921b5028a06d..c9a66e8c70db7426c86c513d96defb2067c0b766 100644 GIT binary patch delta 44 zcmZoTz}j$tb%Hb_^F$eEM&^wP74rOshWbVZMg|H7MpmW%)=RtC+_<+neVXOwgR02@vW AZ~y=R diff --git a/AmongUsCapture/ClientSocket.cs b/AmongUsCapture/ClientSocket.cs index b6458fa0..3f3cd3df 100644 --- a/AmongUsCapture/ClientSocket.cs +++ b/AmongUsCapture/ClientSocket.cs @@ -57,6 +57,12 @@ public void OnTokenHandler(object sender, StartToken token) } } + private void OnConnectionFailure(AggregateException? e) + { + string message = e != null ? e.Message : "A generic connection error occured."; + Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan, $"{Color.Red.ToTextColor()}{message}"); + } + private void Connect(string url, string connectCode) { try @@ -64,6 +70,11 @@ private void Connect(string url, string connectCode) socket.ServerUri = new Uri(url); socket.ConnectAsync().ContinueWith(t => { + if (!t.IsCompletedSuccessfully) + { + OnConnectionFailure(t.Exception); + return; + } OnConnected?.Invoke(this, EventArgs.Empty); SendConnectCode(connectCode); }); diff --git a/AmongUsCapture/Program.cs b/AmongUsCapture/Program.cs index a9f926b5..fafce39f 100644 --- a/AmongUsCapture/Program.cs +++ b/AmongUsCapture/Program.cs @@ -13,7 +13,6 @@ using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Win32; -using System.Threading.Tasks; namespace AmongUsCapture { diff --git a/AmongUsCapture/Properties/PublishProfiles/FolderProfile.pubxml b/AmongUsCapture/Properties/PublishProfiles/FolderProfile.pubxml index 91103a93..9f525d9e 100644 --- a/AmongUsCapture/Properties/PublishProfiles/FolderProfile.pubxml +++ b/AmongUsCapture/Properties/PublishProfiles/FolderProfile.pubxml @@ -9,7 +9,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. bin\publish\32Bit\ FileSystem netcoreapp3.1 - win-x86 + win-x64 false True True diff --git a/AmongUsCapture/UserForm.cs b/AmongUsCapture/UserForm.cs index 9388ebae..6a7ffbce 100644 --- a/AmongUsCapture/UserForm.cs +++ b/AmongUsCapture/UserForm.cs @@ -240,7 +240,6 @@ private void doConnect(string url) { clientSocket.OnConnected += (sender, e) => { - Settings.PersistentSettings.host = url; };