From 51d1319c5022b57f9e42df474794ace459f8a6c7 Mon Sep 17 00:00:00 2001 From: php Date: Sun, 17 Nov 2024 02:34:05 -0600 Subject: [PATCH] Ensure we try to reconnect a system after a disconnect --- .../AudioSettingsWindow.xaml.cs | 22 +++++++- WhackerLinkConsoleV2/MainWindow.xaml.cs | 51 ++++++++++++------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/WhackerLinkConsoleV2/AudioSettingsWindow.xaml.cs b/WhackerLinkConsoleV2/AudioSettingsWindow.xaml.cs index 2f8cfe2..7964b12 100644 --- a/WhackerLinkConsoleV2/AudioSettingsWindow.xaml.cs +++ b/WhackerLinkConsoleV2/AudioSettingsWindow.xaml.cs @@ -1,4 +1,24 @@ -using System.Windows; +/* +* WhackerLink - WhackerLinkConsoleV2 +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Copyright (C) 2024 Caleb, K4PHP +* +*/ + +using System.Windows; using System.Collections.Generic; using NAudio.Wave; diff --git a/WhackerLinkConsoleV2/MainWindow.xaml.cs b/WhackerLinkConsoleV2/MainWindow.xaml.cs index e039433..199b1b0 100644 --- a/WhackerLinkConsoleV2/MainWindow.xaml.cs +++ b/WhackerLinkConsoleV2/MainWindow.xaml.cs @@ -173,26 +173,43 @@ namespace WhackerLinkConsoleV2 handler.OnVoiceChannelRelease += HandleVoiceRelease; handler.OnAudioData += HandleReceivedAudio; - Task.Factory.StartNew(() => + handler.OnUnitRegistrationResponse += (response) => { - handler.Connect(system.Address, system.Port); - - handler.OnUnitRegistrationResponse += (response) => + Dispatcher.Invoke(() => { - Dispatcher.Invoke(() => + if (response.Status == (int)ResponseType.GRANT) { - if (response.Status == (int)ResponseType.GRANT) - { - systemStatusBox.Background = new SolidColorBrush(Colors.Green); - systemStatusBox.ConnectionState = "Connected"; - } - else - { - systemStatusBox.Background = new SolidColorBrush(Colors.Red); - systemStatusBox.ConnectionState = "Disconnected"; - } - }); - }; + systemStatusBox.Background = new SolidColorBrush(Colors.Green); + systemStatusBox.ConnectionState = "Connected"; + } + else + { + systemStatusBox.Background = new SolidColorBrush(Colors.Red); + systemStatusBox.ConnectionState = "Disconnected"; + } + }); + }; + + handler.OnClose += () => + { + Dispatcher.Invoke(() => + { + systemStatusBox.Background = new SolidColorBrush(Colors.Red); + systemStatusBox.ConnectionState = "Disconnected"; + }); + + Thread.Sleep(1000); + + Task.Factory.StartNew(() => + { + handler.Connect(system.Address, system.Port); + handler.SendMessage(PacketFactory.CreateUnitRegistrationRequest(system.Rid, system.Site)); + }); + }; + + Task.Factory.StartNew(() => + { + handler.Connect(system.Address, system.Port); handler.OnGroupAffiliationResponse += (response) => { /* TODO */ };