|
6 | 6 | using System.IO; |
7 | 7 | using System.Linq; |
8 | 8 | using System.Text; |
| 9 | +using System.Threading.Tasks; |
9 | 10 | using System.Windows; |
10 | 11 | using System.Windows.Controls; |
11 | 12 | using System.Windows.Input; |
|
17 | 18 | using Microsoft.WindowsAPICodePack.Dialogs; |
18 | 19 | using SPCode.Interop; |
19 | 20 | using SPCode.Utils; |
| 21 | +using ValveQuery.GameServer; |
20 | 22 | using static SPCode.Interop.TranslationProvider; |
21 | 23 |
|
22 | 24 | namespace SPCode.UI.Windows |
@@ -503,23 +505,23 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e) |
503 | 505 |
|
504 | 506 | private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs e) |
505 | 507 | { |
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); |
507 | 509 | 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 |
511 | 513 | { |
512 | | - await result?.CloseAsync(); |
| 514 | + await dialog?.CloseAsync(); |
513 | 515 | return; |
514 | 516 | }; |
515 | 517 | if (await ftp.TestConnection()) |
516 | 518 | { |
517 | | - await result?.CloseAsync(); |
| 519 | + await dialog?.CloseAsync(); |
518 | 520 | await this.ShowMessageAsync("Success", "Connection successful!", settings: Program.MainWindow.MetroDialogOptions); |
519 | 521 | } |
520 | 522 | else |
521 | 523 | { |
522 | | - await result?.CloseAsync(); |
| 524 | + await dialog?.CloseAsync(); |
523 | 525 | await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {ftp.ErrorMessage}", settings: Program.MainWindow.MetroDialogOptions); |
524 | 526 | } |
525 | 527 | } |
@@ -560,6 +562,48 @@ private void C_RConPW_TextChanged(object sender, RoutedEventArgs e) |
560 | 562 | Program.Configs[ConfigListBox.SelectedIndex].RConPassword = C_RConPW.Password; |
561 | 563 | } |
562 | 564 |
|
| 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 | + |
563 | 607 | private void C_RConCmds_TextChanged(object sender, RoutedEventArgs e) |
564 | 608 | { |
565 | 609 | if (!AllowChange) |
|
0 commit comments