Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 6ca6b7f

Browse files
committed
first steps in RCON test button in configs
1 parent d5768b7 commit 6ca6b7f

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

UI/MainWindow/MainWindowServerQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private void Server_Query()
2929

3030
try
3131
{
32-
using var server = ServerQuery.GetServerInstance(c.RConIP, c.RConPort, false, 500, 500, 2, true);
32+
using var server = ServerQuery.GetServerInstance(c.RConIP, c.RConPort, false, 1000, 1000, 2, true);
3333
var serverInfo = server.GetInfo();
3434

3535
if (serverInfo == null)

UI/Windows/ConfigWindow.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
<PasswordBox x:Name="C_FTPPW" PasswordChanged="C_FTPPW_TextChanged" />
192192
<TextBlock x:Name="FTPDirBlock" IsHitTestVisible="False" />
193193
<TextBox x:Name="C_FTPDir" TextChanged="C_FTPDir_TextChanged" />
194-
<Button x:Name="FTPTestConnectionButton" Content="Test Connection" Click="FTPTestConnectionButton_Click" HorizontalAlignment="Left" Margin="0,20,0,-10"/>
194+
<Button x:Name="FTPTestConnectionButton" Content="Test Connection" Click="FTPTestConnectionButton_Click" HorizontalAlignment="Left" Margin="0,15,0,-10"/>
195195
</StackPanel>
196196
</Grid>
197197
<Grid Grid.Column="1" Margin="5,0,0,0">
@@ -245,6 +245,11 @@
245245
<TextBox Name="C_RConPort" TextChanged="C_RConPort_TextChanged" />
246246
<TextBlock Name="RConPWBlock" IsHitTestVisible="False" />
247247
<PasswordBox Name="C_RConPW" PasswordChanged="C_RConPW_TextChanged" />
248+
<Button x:Name="RCONTestConnectionButton"
249+
Margin="0,15,0,0"
250+
HorizontalAlignment="Left"
251+
Content="Test connection"
252+
Click="RCONTestConnectionButton_Click"/>
248253
</StackPanel>
249254
</Grid>
250255
<Grid Grid.Column="1">

UI/Windows/ConfigWindow.xaml.cs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Text;
9+
using System.Threading.Tasks;
910
using System.Windows;
1011
using System.Windows.Controls;
1112
using System.Windows.Input;
@@ -17,6 +18,7 @@
1718
using Microsoft.WindowsAPICodePack.Dialogs;
1819
using SPCode.Interop;
1920
using SPCode.Utils;
21+
using ValveQuery.GameServer;
2022
using static SPCode.Interop.TranslationProvider;
2123

2224
namespace SPCode.UI.Windows
@@ -503,23 +505,23 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e)
503505

504506
private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs e)
505507
{
506-
var result = await this.ShowProgressAsync("Testing the FTP connection with the provided details...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
508+
var dialog = await this.ShowProgressAsync("Testing the FTP connection with the provided details...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
507509
var ftp = new FTP(C_FTPHost.Text, C_FTPUser.Text, C_FTPPW.Password);
508-
result.SetIndeterminate();
509-
result.SetCancelable(true);
510-
result.Canceled += async delegate
510+
dialog.SetIndeterminate();
511+
dialog.SetCancelable(true);
512+
dialog.Canceled += async delegate
511513
{
512-
await result?.CloseAsync();
514+
await dialog?.CloseAsync();
513515
return;
514516
};
515517
if (await ftp.TestConnection())
516518
{
517-
await result?.CloseAsync();
519+
await dialog?.CloseAsync();
518520
await this.ShowMessageAsync("Success", "Connection successful!", settings: Program.MainWindow.MetroDialogOptions);
519521
}
520522
else
521523
{
522-
await result?.CloseAsync();
524+
await dialog?.CloseAsync();
523525
await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {ftp.ErrorMessage}", settings: Program.MainWindow.MetroDialogOptions);
524526
}
525527
}
@@ -560,6 +562,48 @@ private void C_RConPW_TextChanged(object sender, RoutedEventArgs e)
560562
Program.Configs[ConfigListBox.SelectedIndex].RConPassword = C_RConPW.Password;
561563
}
562564

565+
private async void RCONTestConnectionButton_Click(object sender, RoutedEventArgs e)
566+
{
567+
var dialog = await this.ShowProgressAsync("Testing RCON connection...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
568+
dialog.SetIndeterminate();
569+
dialog.SetCancelable(true);
570+
dialog.Canceled += async delegate
571+
{
572+
await dialog?.CloseAsync();
573+
return;
574+
};
575+
var success = true;
576+
var errorMsg = "";
577+
try
578+
{
579+
await Dispatcher.InvokeAsync(() =>
580+
{
581+
var server = ServerQuery.GetServerInstance(C_RConIP.Text, ushort.Parse(C_RConPort.Text));
582+
server.GetInfo();
583+
if (!server.GetControl(C_RConPW.Password, false))
584+
{
585+
success = false;
586+
errorMsg = "Invalid credentials!";
587+
}
588+
});
589+
}
590+
catch (Exception ex)
591+
{
592+
success = false;
593+
errorMsg = ex.Message;
594+
}
595+
596+
await dialog?.CloseAsync();
597+
if (success)
598+
{
599+
await this.ShowMessageAsync("Success", "The connection was successful!", settings: Program.MainWindow.MetroDialogOptions);
600+
}
601+
else
602+
{
603+
await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {errorMsg}", settings: Program.MainWindow.MetroDialogOptions);
604+
}
605+
}
606+
563607
private void C_RConCmds_TextChanged(object sender, RoutedEventArgs e)
564608
{
565609
if (!AllowChange)

0 commit comments

Comments
 (0)