From a5f74344c6857a68e8ad5d96af241ce5607945c1 Mon Sep 17 00:00:00 2001 From: Plenyx Date: Tue, 4 Jun 2019 10:30:25 +0200 Subject: [PATCH] Build n. 39 --- Forms/FormCustomName.cs | 5 ++++- Forms/FormLogSession.Designer.cs | 16 ++++++++++++++- Forms/FormLogSession.cs | 25 ++++++++++++++++++++++- Forms/FormMain.cs | 32 +++++++++++++++++++++--------- TwitchIRCClient/IrcStates.cs | 1 + TwitchIRCClient/TwitchIrcClient.cs | 12 ++++++++++- VERSION | 2 +- 7 files changed, 79 insertions(+), 14 deletions(-) diff --git a/Forms/FormCustomName.cs b/Forms/FormCustomName.cs index ed4f101..d3dcfdb 100644 --- a/Forms/FormCustomName.cs +++ b/Forms/FormCustomName.cs @@ -24,7 +24,10 @@ private void FormCustomName_FormClosing(object sender, FormClosingEventArgs e) Hide(); Properties.Settings.Default.CustomTwitchName = textBoxCustomName.Text.ToLower(); Properties.Settings.Default.CustomTwitchOAuthPassword = textBoxCustomOAuth.Text; - mainLink.ReconnectTwitchBot(); + if (!mainLink.IsConnectionNull()) + { + mainLink.ReconnectTwitchBot(); + } } private void checkBoxCustomNameEnable_CheckedChanged(object sender, EventArgs e) diff --git a/Forms/FormLogSession.Designer.cs b/Forms/FormLogSession.Designer.cs index 9b8af08..c0e6576 100644 --- a/Forms/FormLogSession.Designer.cs +++ b/Forms/FormLogSession.Designer.cs @@ -31,13 +31,14 @@ private void InitializeComponent() this.buttonSessionStarter = new System.Windows.Forms.Button(); this.checkBoxSupressWebhooks = new System.Windows.Forms.CheckBox(); this.checkBoxOnlySuccess = new System.Windows.Forms.CheckBox(); + this.buttonUnPauseSession = new System.Windows.Forms.Button(); this.SuspendLayout(); // // buttonSessionStarter // this.buttonSessionStarter.Location = new System.Drawing.Point(12, 12); this.buttonSessionStarter.Name = "buttonSessionStarter"; - this.buttonSessionStarter.Size = new System.Drawing.Size(271, 23); + this.buttonSessionStarter.Size = new System.Drawing.Size(163, 23); this.buttonSessionStarter.TabIndex = 0; this.buttonSessionStarter.Text = "Start a log session"; this.buttonSessionStarter.UseVisualStyleBackColor = true; @@ -67,11 +68,23 @@ private void InitializeComponent() this.checkBoxOnlySuccess.Text = "only successful attempts"; this.checkBoxOnlySuccess.UseVisualStyleBackColor = true; // + // buttonUnPauseSession + // + this.buttonUnPauseSession.Enabled = false; + this.buttonUnPauseSession.Location = new System.Drawing.Point(181, 12); + this.buttonUnPauseSession.Name = "buttonUnPauseSession"; + this.buttonUnPauseSession.Size = new System.Drawing.Size(102, 23); + this.buttonUnPauseSession.TabIndex = 3; + this.buttonUnPauseSession.Text = "Pause session"; + this.buttonUnPauseSession.UseVisualStyleBackColor = true; + this.buttonUnPauseSession.Click += new System.EventHandler(this.ButtonUnPauseSession_Click); + // // FormLogSession // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(295, 91); + this.Controls.Add(this.buttonUnPauseSession); this.Controls.Add(this.checkBoxOnlySuccess); this.Controls.Add(this.checkBoxSupressWebhooks); this.Controls.Add(this.buttonSessionStarter); @@ -92,5 +105,6 @@ private void InitializeComponent() private System.Windows.Forms.Button buttonSessionStarter; public System.Windows.Forms.CheckBox checkBoxSupressWebhooks; public System.Windows.Forms.CheckBox checkBoxOnlySuccess; + private System.Windows.Forms.Button buttonUnPauseSession; } } \ No newline at end of file diff --git a/Forms/FormLogSession.cs b/Forms/FormLogSession.cs index c20af2d..e608e1a 100644 --- a/Forms/FormLogSession.cs +++ b/Forms/FormLogSession.cs @@ -11,6 +11,7 @@ public partial class FormLogSession : Form // fields private FormMain mainLink; + private bool sessionPaused = false; #endregion public FormLogSession(FormMain mainLink) @@ -28,17 +29,39 @@ private void FormLogSession_FormClosing(object sender, FormClosingEventArgs e) private async void ButtonSessionStarter_Click(object sender, EventArgs e) { - if (SessionRunning) + if (SessionRunning || sessionPaused) { buttonSessionStarter.Text = "Start a log session"; + buttonUnPauseSession.Text = "Pause session"; + buttonUnPauseSession.Enabled = false; SessionRunning = false; + sessionPaused = false; await mainLink.ExecuteSessionLogWebhooksAsync(); mainLink.SessionLogs.Clear(); } else { buttonSessionStarter.Text = "Stop the log session"; + buttonUnPauseSession.Text = "Pause session"; + buttonUnPauseSession.Enabled = true; SessionRunning = true; + sessionPaused = false; + } + } + + private void ButtonUnPauseSession_Click(object sender, EventArgs e) + { + if (!sessionPaused) + { + SessionRunning = false; + sessionPaused = true; + buttonUnPauseSession.Text = "Unpause session"; + } + else + { + SessionRunning = true; + sessionPaused = false; + buttonUnPauseSession.Text = "Pause session"; } } } diff --git a/Forms/FormMain.cs b/Forms/FormMain.cs index f65e869..726fa45 100644 --- a/Forms/FormMain.cs +++ b/Forms/FormMain.cs @@ -47,7 +47,7 @@ public partial class FormMain : Form // constants private const int minFileSize = 12288; - private const int uploaderBuild = 38; + private const int uploaderBuild = 39; #endregion #region constructor @@ -59,6 +59,7 @@ public FormMain() toolTip.SetToolTip(checkBoxWepSkill1, "If checked dps.report renders all autoattacks."); toolTip.SetToolTip(checkBoxFileSizeIgnore, "If checked logs with less than 12 kB filesize will not be uploaded."); #endregion + Properties.Settings.Default.PropertyChanged += delegate { Properties.Settings.Default.Save(); }; Icon = Properties.Resources.AppIcon; notifyIconTray.Icon = Properties.Resources.AppIcon; Text = $"{Text} b{uploaderBuild}"; @@ -197,10 +198,8 @@ public FormMain() { buttonDisConnectTwitch.Text = "Connect to Twitch"; buttonChangeTwitchChannel.Enabled = false; - toolStripMenuItemOpenCustomName.Enabled = false; toolStripMenuItemPostToTwitch.Enabled = false; toolStripMenuItemOpenTwitchCommands.Enabled = false; - buttonCustomName.Enabled = false; buttonReconnectBot.Enabled = false; buttonTwitchCommands.Enabled = false; checkBoxPostToTwitch.Enabled = false; @@ -217,7 +216,7 @@ public FormMain() checkBoxStartWhenWindowsStarts.Checked = true; } } - /* Subscribe to field changes events, otherwise they would trigger with load */ + /* Subscribe to field changes events, otherwise they would trigger on load */ checkBoxPostToTwitch.CheckedChanged += new EventHandler(checkBoxPostToTwitch_CheckedChanged); checkBoxWepSkill1.CheckedChanged += new EventHandler(checkBoxWepSkill1_CheckedChanged); checkBoxUploadLogs.CheckedChanged += new EventHandler(checkBoxUploadAll_CheckedChanged); @@ -700,13 +699,16 @@ public async void HttpUploadLogAsync(string file, Dictionary pos public void ConnectTwitchBot() { + if (InvokeRequired) + { + Invoke((Action)delegate { ConnectTwitchBot(); }); + return; + } buttonDisConnectTwitch.Text = "Disconnect from Twitch"; buttonChangeTwitchChannel.Enabled = true; - toolStripMenuItemOpenCustomName.Enabled = true; toolStripMenuItemPostToTwitch.Enabled = true; toolStripMenuItemOpenTwitchCommands.Enabled = true; buttonCustomName.Enabled = true; - buttonReconnectBot.Enabled = true; buttonTwitchCommands.Enabled = true; checkBoxPostToTwitch.Enabled = true; if (Properties.Settings.Default.CustomTwitchNameEnabled) @@ -725,6 +727,11 @@ public void ConnectTwitchBot() public void DisconnectTwitchBot() { + if (InvokeRequired) + { + Invoke((Action)delegate { DisconnectTwitchBot(); }); + return; + } chatConnect.ReceiveMessage -= ReadMessagesAsync; chatConnect.StateChange -= OnIrcStateChanged; chatConnect.Dispose(); @@ -732,10 +739,8 @@ public void DisconnectTwitchBot() AddToText("<-?-> CONNECTION CLOSED"); buttonDisConnectTwitch.Text = "Connect to Twitch"; buttonChangeTwitchChannel.Enabled = false; - toolStripMenuItemOpenCustomName.Enabled = false; toolStripMenuItemPostToTwitch.Enabled = false; toolStripMenuItemOpenTwitchCommands.Enabled = false; - buttonCustomName.Enabled = false; buttonReconnectBot.Enabled = false; buttonTwitchCommands.Enabled = false; checkBoxPostToTwitch.Enabled = false; @@ -744,6 +749,11 @@ public void DisconnectTwitchBot() public void ReconnectTwitchBot() { + if (InvokeRequired) + { + Invoke((Action)delegate { ReconnectTwitchBot(); }); + return; + } chatConnect.ReceiveMessage -= ReadMessagesAsync; chatConnect.StateChange -= OnIrcStateChanged; chatConnect.Dispose(); @@ -808,6 +818,10 @@ protected async void OnIrcStateChanged(object sender, IrcChangedEventArgs e) case IrcStates.ChannelLeaving: AddToText($"<-?-> LEAVING CHANNEL {e.Channel.ToUpper()}"); break; + case IrcStates.FailedConnection: + AddToText("<-?-> FAILED TO CONNECT TO TWITCH"); + DisconnectTwitchBot(); + break; default: AddToText("<-?-> UNRECOGNISED IRC STATE RECEIVED"); break; @@ -816,7 +830,7 @@ protected async void OnIrcStateChanged(object sender, IrcChangedEventArgs e) protected async void ReadMessagesAsync(object sender, IrcMessageEventArgs e) { - if (e == null) + if ((e == null) || (e.Message == null)) { return; } diff --git a/TwitchIRCClient/IrcStates.cs b/TwitchIRCClient/IrcStates.cs index cb5d736..9784990 100644 --- a/TwitchIRCClient/IrcStates.cs +++ b/TwitchIRCClient/IrcStates.cs @@ -2,6 +2,7 @@ { public enum IrcStates { + FailedConnection, Disconnected, Connecting, Connected, diff --git a/TwitchIRCClient/TwitchIrcClient.cs b/TwitchIRCClient/TwitchIrcClient.cs index 930572c..d302490 100644 --- a/TwitchIRCClient/TwitchIrcClient.cs +++ b/TwitchIRCClient/TwitchIrcClient.cs @@ -204,8 +204,18 @@ private async void ReadMessagesAsync() protected async void OnMessageReceived(object sender, IrcMessageEventArgs e) { - if (e == null) + if ((e == null) || (e.Message == null)) { + if (Connecting && !Connected) + { + StateChange?.Invoke(this, new IrcChangedEventArgs(IrcStates.FailedConnection)); + } + else + { + StateChange?.Invoke(this, new IrcChangedEventArgs(IrcStates.Disconnected)); + } + Connecting = false; + Connected = false; return; } if (!Connected && e.Message.Equals($":tmi.twitch.tv 001 {userName} :Welcome, GLHF!")) diff --git a/VERSION b/VERSION index c24b6ae..72f523f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -38 \ No newline at end of file +39 \ No newline at end of file