Skip to content

Commit

Permalink
Build n. 39
Browse files Browse the repository at this point in the history
  • Loading branch information
Plenyx committed Jun 4, 2019
1 parent e2a62fc commit a5f7434
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Forms/FormCustomName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion Forms/FormLogSession.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion Forms/FormLogSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public partial class FormLogSession : Form

// fields
private FormMain mainLink;
private bool sessionPaused = false;
#endregion

public FormLogSession(FormMain mainLink)
Expand All @@ -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";
}
}
}
Expand Down
32 changes: 23 additions & 9 deletions Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}";
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -700,13 +699,16 @@ public async void HttpUploadLogAsync(string file, Dictionary<string, string> 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)
Expand All @@ -725,17 +727,20 @@ public void ConnectTwitchBot()

public void DisconnectTwitchBot()
{
if (InvokeRequired)
{
Invoke((Action)delegate { DisconnectTwitchBot(); });
return;
}
chatConnect.ReceiveMessage -= ReadMessagesAsync;
chatConnect.StateChange -= OnIrcStateChanged;
chatConnect.Dispose();
chatConnect = null;
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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions TwitchIRCClient/IrcStates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum IrcStates
{
FailedConnection,
Disconnected,
Connecting,
Connected,
Expand Down
12 changes: 11 additions & 1 deletion TwitchIRCClient/TwitchIrcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!"))
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38
39

0 comments on commit a5f7434

Please sign in to comment.