/trunk/WingMan/WingManForm.cs |
@@ -11,6 +11,7 @@ |
using WingMan.Lobby; |
using WingMan.MouseKey; |
using WingMan.Properties; |
using WingMan.Utilities; |
|
namespace WingMan |
{ |
@@ -24,6 +25,8 @@ |
FormCancellationTokenSource = new CancellationTokenSource(); |
|
MQTTCommunication = new MQTTCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); |
MQTTCommunication.OnClientAuthenticationFailed += OnMQTTClientAuthenticationFailed; |
MQTTCommunication.OnServerAuthenticationFailed += OnMQTTServerAuthenticationFailed; |
|
MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); |
|
@@ -81,6 +84,18 @@ |
|
public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; } |
|
private void OnMQTTServerAuthenticationFailed(object sender, EventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Failed_to_authenticate_client}{Environment.NewLine}"); |
} |
|
private void OnMQTTClientAuthenticationFailed(object sender, EventArgs e) |
{ |
ActivityTextBox.AppendText( |
$"{Strings.Server_authentication_failed}{Environment.NewLine}"); |
} |
|
/// <summary> |
/// Clean up any resources being used. |
/// </summary> |
@@ -181,11 +196,12 @@ |
return; |
} |
|
if (!ValidateAddressPort(out var ipAddress, out var port, out var nick)) |
if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
return; |
|
// Start the MQTT server. |
await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick).ConfigureAwait(false); |
await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick, password) |
.ConfigureAwait(false); |
toolStripStatusLabel.Text = Strings.Server_started; |
HostButton.BackColor = Color.Aquamarine; |
|
@@ -196,19 +212,22 @@ |
Nick.Enabled = false; |
} |
|
private bool ValidateAddressPort(out IPAddress address, out int port, out string nick) |
private bool ValidateAddressPort(out IPAddress address, out int port, out string nick, out string password) |
{ |
address = IPAddress.Any; |
port = 0; |
nick = string.Empty; |
password = string.Empty; |
|
if (string.IsNullOrEmpty(Address.Text) && |
string.IsNullOrEmpty(Port.Text) && |
string.IsNullOrEmpty(Nick.Text)) |
string.IsNullOrEmpty(Nick.Text) && |
string.IsNullOrEmpty(Password.Text)) |
{ |
Address.BackColor = Color.LightPink; |
Port.BackColor = Color.LightPink; |
Nick.BackColor = Color.LightPink; |
Password.BackColor = Color.LightPink; |
return false; |
} |
|
@@ -234,9 +253,18 @@ |
|
nick = Nick.Text; |
|
if (string.IsNullOrEmpty(Password.Text)) |
{ |
Password.BackColor = Color.LightPink; |
return false; |
} |
|
password = AES.LinearFeedbackShiftPassword(Password.Text); |
|
Address.BackColor = Color.Empty; |
Port.BackColor = Color.Empty; |
Nick.BackColor = Color.Empty; |
Password.BackColor = Color.Empty; |
|
return true; |
} |
@@ -256,10 +284,11 @@ |
return; |
} |
|
if (!ValidateAddressPort(out var ipAddress, out var port, out var nick)) |
if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
return; |
|
await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick).ConfigureAwait(false); |
await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick, password) |
.ConfigureAwait(false); |
|
toolStripStatusLabel.Text = Strings.Client_started; |
ConnectButton.Text = Strings.Disconnect; |
@@ -289,7 +318,7 @@ |
return; |
} |
|
HelmAddButton.Enabled = false; |
ShowOverlayPanel(); |
|
MouseKeyCombo = new List<string>(); |
|
@@ -300,6 +329,13 @@ |
MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp; |
} |
|
private void ShowOverlayPanel() |
{ |
OverlayPanel.BringToFront(); |
OverlayPanel.Visible = true; |
OverlayPanel.Invalidate(); |
} |
|
private void MouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
{ |
MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); |
@@ -314,9 +350,16 @@ |
MouseKeyApplicationHook.Dispose(); |
|
HelmNameTextBox.Text = string.Empty; |
HelmAddButton.Enabled = true; |
HideOverlayPanel(); |
} |
|
private void HideOverlayPanel() |
{ |
OverlayPanel.SendToBack(); |
OverlayPanel.Visible = false; |
OverlayPanel.Invalidate(); |
} |
|
private void MouseKeyHookOnMouseUp(object sender, MouseEventArgs e) |
{ |
MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); |
@@ -331,7 +374,7 @@ |
MouseKeyApplicationHook.Dispose(); |
|
HelmNameTextBox.Text = string.Empty; |
HelmAddButton.Enabled = true; |
HideOverlayPanel(); |
} |
|
|
@@ -373,5 +416,9 @@ |
{ |
UpdateWingListBoxItems(); |
} |
|
private void WingBindingsBindButtonClicked(object sender, EventArgs e) |
{ |
} |
} |
} |