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

Commit

Permalink
finish RCON test button
Browse files Browse the repository at this point in the history
  • Loading branch information
maxijabase committed Mar 20, 2022
1 parent 6ca6b7f commit 599acae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
4 changes: 1 addition & 3 deletions UI/Components/EditorElement/EditorElement.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
{
// ignored
}

Thread.Sleep(
100); //dont include System.Threading in the using directives, cause its onlyused once and the Timer class will double
Thread.Sleep(100);
}
});
}
Expand Down
52 changes: 36 additions & 16 deletions UI/Windows/ConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private void C_FTPDir_TextChanged(object sender, TextChangedEventArgs e)

private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs e)
{
var dialog = await this.ShowProgressAsync("Testing the FTP connection with the provided details...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
ProgressDialogController? dialog = await this.ShowProgressAsync(Translate("TestingFTPConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
var ftp = new FTP(C_FTPHost.Text, C_FTPUser.Text, C_FTPPW.Password);
dialog.SetIndeterminate();
dialog.SetCancelable(true);
Expand All @@ -514,15 +514,20 @@ private async void FTPTestConnectionButton_Click(object sender, RoutedEventArgs
await dialog?.CloseAsync();
return;
};
if (await ftp.TestConnection())
var result = await ftp.TestConnection();
if ((bool)dialog?.IsCanceled)
{
return;
}
if (result)
{
await dialog?.CloseAsync();
await this.ShowMessageAsync("Success", "Connection successful!", settings: Program.MainWindow.MetroDialogOptions);
await this.ShowMessageAsync(Translate("Success"), string.Empty, settings: Program.MainWindow.MetroDialogOptions);
}
else
{
await dialog?.CloseAsync();
await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {ftp.ErrorMessage}", settings: Program.MainWindow.MetroDialogOptions);
await this.ShowMessageAsync(Translate("Error"), ftp.ErrorMessage, settings: Program.MainWindow.MetroDialogOptions);
}
}

Expand Down Expand Up @@ -564,43 +569,58 @@ private void C_RConPW_TextChanged(object sender, RoutedEventArgs e)

private async void RCONTestConnectionButton_Click(object sender, RoutedEventArgs e)
{
var dialog = await this.ShowProgressAsync("Testing RCON connection...", "Please wait...", settings: Program.MainWindow.MetroDialogOptions);
ProgressDialogController? dialog = await this.ShowProgressAsync(Translate("TestingRCONConn"), Translate("PleaseWait"), settings: Program.MainWindow.MetroDialogOptions);
dialog.SetIndeterminate();
dialog.SetCancelable(true);
dialog.Canceled += async delegate
{
await dialog?.CloseAsync();
return;
};

var success = true;
var errorMsg = "";

try
{
await Dispatcher.InvokeAsync(() =>
var server = ServerQuery.GetServerInstance(C_RConIP.Text, ushort.Parse(C_RConPort.Text));
var sInfo = new ServerInfo();
// See if the provided details at least point to a valid server
await Task.Run(() => { sInfo = server.GetInfo(); });
if (sInfo == null)
{
var server = ServerQuery.GetServerInstance(C_RConIP.Text, ushort.Parse(C_RConPort.Text));
server.GetInfo();
if (!server.GetControl(C_RConPW.Password, false))
{
success = false;
errorMsg = "Invalid credentials!";
}
});
success = false;
errorMsg = Translate("RCONFailureMessage");
goto End;
}
bool done = false;
await Task.Run(() => { done = server.GetControl(C_RConPW.Password, false); });
if (!done)
{
success = false;
errorMsg = Translate("InvalidCredentials");
}
}
catch (Exception ex)
{
success = false;
errorMsg = ex.Message;
}

End:

if ((bool)dialog?.IsCanceled)
{
return;
}
await dialog?.CloseAsync();
if (success)
{
await this.ShowMessageAsync("Success", "The connection was successful!", settings: Program.MainWindow.MetroDialogOptions);
await this.ShowMessageAsync(Translate("Success"), string.Empty, settings: Program.MainWindow.MetroDialogOptions);
}
else
{
await this.ShowMessageAsync("Error", $"The connection could not be made! Message: {errorMsg}", settings: Program.MainWindow.MetroDialogOptions);
await this.ShowMessageAsync(Translate("Error"), errorMsg, settings: Program.MainWindow.MetroDialogOptions);
}
}

Expand Down

0 comments on commit 599acae

Please sign in to comment.