WingMan – Diff between revs 7 and 8

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 7 Rev 8
Line 9... Line 9...
9 using Gma.System.MouseKeyHook; 9 using Gma.System.MouseKeyHook;
10 using WingMan.Communication; 10 using WingMan.Communication;
11 using WingMan.Lobby; 11 using WingMan.Lobby;
12 using WingMan.MouseKey; 12 using WingMan.MouseKey;
13 using WingMan.Properties; 13 using WingMan.Properties;
-   14 using WingMan.Utilities;
Line 14... Line 15...
14   15  
15 namespace WingMan 16 namespace WingMan
16 { 17 {
17 public partial class WingManForm : Form 18 public partial class WingManForm : Form
Line 22... Line 23...
22   23  
23 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); 24 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Line 24... Line 25...
24 FormCancellationTokenSource = new CancellationTokenSource(); 25 FormCancellationTokenSource = new CancellationTokenSource();
-   26  
-   27 MQTTCommunication = new MQTTCommunication(FormTaskScheduler, FormCancellationTokenSource.Token);
Line 25... Line 28...
25   28 MQTTCommunication.OnClientAuthenticationFailed += OnMQTTClientAuthenticationFailed;
Line 26... Line 29...
26 MQTTCommunication = new MQTTCommunication(FormTaskScheduler, FormCancellationTokenSource.Token); 29 MQTTCommunication.OnServerAuthenticationFailed += OnMQTTServerAuthenticationFailed;
27   30  
Line 79... Line 82...
79   82  
Line 80... Line 83...
80 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; } 83 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; }
Line -... Line 84...
-   84  
-   85 public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; }
-   86  
-   87 private void OnMQTTServerAuthenticationFailed(object sender, EventArgs e)
-   88 {
-   89 ActivityTextBox.AppendText(
-   90 $"{Strings.Failed_to_authenticate_client}{Environment.NewLine}");
-   91 }
-   92  
-   93 private void OnMQTTClientAuthenticationFailed(object sender, EventArgs e)
-   94 {
-   95 ActivityTextBox.AppendText(
81   96 $"{Strings.Server_authentication_failed}{Environment.NewLine}");
82 public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; } 97 }
83   98  
84 /// <summary> 99 /// <summary>
85 /// Clean up any resources being used. 100 /// Clean up any resources being used.
Line 179... Line 194...
179 Nick.Enabled = true; 194 Nick.Enabled = true;
Line 180... Line 195...
180   195  
181 return; 196 return;
Line 182... Line 197...
182 } 197 }
183   198  
Line 184... Line 199...
184 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick)) 199 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password))
185 return; 200 return;
-   201  
186   202 // Start the MQTT server.
187 // Start the MQTT server. 203 await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick, password)
Line 188... Line 204...
188 await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick).ConfigureAwait(false); 204 .ConfigureAwait(false);
189 toolStripStatusLabel.Text = Strings.Server_started; 205 toolStripStatusLabel.Text = Strings.Server_started;
190 HostButton.BackColor = Color.Aquamarine; 206 HostButton.BackColor = Color.Aquamarine;
191   207  
192 // Disable controls 208 // Disable controls
193 ConnectButton.Enabled = false; 209 ConnectButton.Enabled = false;
Line 194... Line 210...
194 Address.Enabled = false; 210 Address.Enabled = false;
195 Port.Enabled = false; 211 Port.Enabled = false;
196 Nick.Enabled = false; 212 Nick.Enabled = false;
197 } 213 }
198   214  
-   215 private bool ValidateAddressPort(out IPAddress address, out int port, out string nick, out string password)
Line 199... Line 216...
199 private bool ValidateAddressPort(out IPAddress address, out int port, out string nick) 216 {
200 { 217 address = IPAddress.Any;
201 address = IPAddress.Any; 218 port = 0;
-   219 nick = string.Empty;
202 port = 0; 220 password = string.Empty;
203 nick = string.Empty; 221  
204   222 if (string.IsNullOrEmpty(Address.Text) &&
205 if (string.IsNullOrEmpty(Address.Text) && 223 string.IsNullOrEmpty(Port.Text) &&
-   224 string.IsNullOrEmpty(Nick.Text) &&
206 string.IsNullOrEmpty(Port.Text) && 225 string.IsNullOrEmpty(Password.Text))
207 string.IsNullOrEmpty(Nick.Text)) 226 {
Line 208... Line 227...
208 { 227 Address.BackColor = Color.LightPink;
209 Address.BackColor = Color.LightPink; 228 Port.BackColor = Color.LightPink;
Line 232... Line 251...
232 return false; 251 return false;
233 } 252 }
Line 234... Line 253...
234   253  
Line -... Line 254...
-   254 nick = Nick.Text;
-   255  
-   256 if (string.IsNullOrEmpty(Password.Text))
-   257 {
-   258 Password.BackColor = Color.LightPink;
-   259 return false;
-   260 }
-   261  
235 nick = Nick.Text; 262 password = AES.LinearFeedbackShiftPassword(Password.Text);
236   263  
237 Address.BackColor = Color.Empty; 264 Address.BackColor = Color.Empty;
-   265 Port.BackColor = Color.Empty;
Line 238... Line 266...
238 Port.BackColor = Color.Empty; 266 Nick.BackColor = Color.Empty;
239 Nick.BackColor = Color.Empty; 267 Password.BackColor = Color.Empty;
Line 240... Line 268...
240   268  
Line 254... Line 282...
254 Nick.Enabled = true; 282 Nick.Enabled = true;
255 HostButton.Enabled = true; 283 HostButton.Enabled = true;
256 return; 284 return;
257 } 285 }
Line 258... Line 286...
258   286  
259 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick)) 287 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password))
Line 260... Line 288...
260 return; 288 return;
-   289  
Line 261... Line 290...
261   290 await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick, password)
262 await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick).ConfigureAwait(false); 291 .ConfigureAwait(false);
263   292  
Line 287... Line 316...
287 { 316 {
288 HelmNameTextBox.BackColor = Color.LightPink; 317 HelmNameTextBox.BackColor = Color.LightPink;
289 return; 318 return;
290 } 319 }
Line 291... Line 320...
291   320  
Line 292... Line 321...
292 HelmAddButton.Enabled = false; 321 ShowOverlayPanel();
Line 293... Line 322...
293   322  
294 MouseKeyCombo = new List<string>(); 323 MouseKeyCombo = new List<string>();
295   324  
296 MouseKeyApplicationHook = Hook.AppEvents(); 325 MouseKeyApplicationHook = Hook.AppEvents();
297 MouseKeyApplicationHook.MouseDown += MouseKeyHookOnMouseDown; 326 MouseKeyApplicationHook.MouseDown += MouseKeyHookOnMouseDown;
298 MouseKeyApplicationHook.KeyUp += MouseKeyHookOnKeyUp; 327 MouseKeyApplicationHook.KeyUp += MouseKeyHookOnKeyUp;
Line -... Line 328...
-   328 MouseKeyApplicationHook.KeyDown += MouseKeyHookOnKeyDown;
-   329 MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp;
-   330 }
-   331  
-   332 private void ShowOverlayPanel()
-   333 {
-   334 OverlayPanel.BringToFront();
299 MouseKeyApplicationHook.KeyDown += MouseKeyHookOnKeyDown; 335 OverlayPanel.Visible = true;
300 MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp; 336 OverlayPanel.Invalidate();
301 } 337 }
Line 302... Line 338...
302   338  
Line 312... Line 348...
312 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 348 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp;
Line 313... Line 349...
313   349  
Line 314... Line 350...
314 MouseKeyApplicationHook.Dispose(); 350 MouseKeyApplicationHook.Dispose();
-   351  
-   352 HelmNameTextBox.Text = string.Empty;
-   353 HideOverlayPanel();
-   354 }
-   355  
-   356 private void HideOverlayPanel()
315   357 {
-   358 OverlayPanel.SendToBack();
316 HelmNameTextBox.Text = string.Empty; 359 OverlayPanel.Visible = false;
Line 317... Line 360...
317 HelmAddButton.Enabled = true; 360 OverlayPanel.Invalidate();
318 } 361 }
319   362  
Line 329... Line 372...
329 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 372 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp;
Line 330... Line 373...
330   373  
Line 331... Line 374...
331 MouseKeyApplicationHook.Dispose(); 374 MouseKeyApplicationHook.Dispose();
332   375  
333 HelmNameTextBox.Text = string.Empty; 376 HelmNameTextBox.Text = string.Empty;
Line 334... Line 377...
334 HelmAddButton.Enabled = true; 377 HideOverlayPanel();
335 } 378 }
Line 371... Line 414...
371   414  
372 private void WingBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) 415 private void WingBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e)
373 { 416 {
374 UpdateWingListBoxItems(); 417 UpdateWingListBoxItems();
-   418 }
-   419  
-   420 private void WingBindingsBindButtonClicked(object sender, EventArgs e)
-   421 {
375 } 422 }
376 } 423 }