2015-08-25 04:38:35 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
|
|
|
|
Copyright (c) 2007-2015 ShareX Team
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using ShareX.HelpersLib;
|
2015-09-04 01:34:13 +12:00
|
|
|
|
using ShareX.IRCLib.Properties;
|
2015-08-25 04:38:35 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.IRCLib
|
|
|
|
|
{
|
2015-09-01 06:36:50 +12:00
|
|
|
|
public partial class IRCClientForm : BaseForm
|
2015-08-25 04:38:35 +12:00
|
|
|
|
{
|
|
|
|
|
public IRCInfo Info { get; private set; }
|
|
|
|
|
public IRC IRC { get; private set; }
|
|
|
|
|
|
2015-08-31 22:57:51 +12:00
|
|
|
|
private TabManager tabManager;
|
2015-08-25 04:38:35 +12:00
|
|
|
|
private string lastCommand, lastMessage;
|
|
|
|
|
|
|
|
|
|
public IRCClientForm() : this(new IRCInfo())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IRCClientForm(IRCInfo info)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-09-10 04:21:31 +12:00
|
|
|
|
rtbOutput.AddContextMenu();
|
2015-09-24 06:23:25 +12:00
|
|
|
|
tsmiColors.HideImageMargin();
|
2015-08-25 04:38:35 +12:00
|
|
|
|
|
2015-08-31 22:57:51 +12:00
|
|
|
|
tabManager = new TabManager(tcMessages);
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
Info = info;
|
|
|
|
|
pgSettings.SelectedObject = Info;
|
|
|
|
|
|
|
|
|
|
IRC = new IRC(Info);
|
|
|
|
|
IRC.Disconnected += IRC_Disconnected;
|
|
|
|
|
IRC.Output += IRC_Output;
|
2015-09-10 04:21:31 +12:00
|
|
|
|
IRC.ErrorOutput += IRC_ErrorOutput;
|
2015-08-25 04:38:35 +12:00
|
|
|
|
IRC.Message += IRC_Message;
|
2015-08-25 09:40:57 +12:00
|
|
|
|
IRC.UserJoined += IRC_UserJoined;
|
2015-08-25 04:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 00:40:39 +12:00
|
|
|
|
protected override void Dispose(bool disposing)
|
2015-08-25 04:38:35 +12:00
|
|
|
|
{
|
2015-09-01 00:40:39 +12:00
|
|
|
|
if (disposing)
|
2015-08-25 04:38:35 +12:00
|
|
|
|
{
|
2015-09-01 00:40:39 +12:00
|
|
|
|
if (components != null)
|
|
|
|
|
{
|
|
|
|
|
components.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IRC != null)
|
|
|
|
|
{
|
|
|
|
|
IRC.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.Dispose(disposing);
|
2015-08-25 04:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 04:21:31 +12:00
|
|
|
|
private void AppendOutput(string output, Color color)
|
|
|
|
|
{
|
|
|
|
|
this.InvokeSafe(() =>
|
|
|
|
|
{
|
|
|
|
|
rtbOutput.Select(rtbOutput.TextLength, 0);
|
|
|
|
|
rtbOutput.SelectionColor = color;
|
|
|
|
|
rtbOutput.AppendText($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {output}\r\n");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
private void AppendMessage(string message)
|
|
|
|
|
{
|
|
|
|
|
txtMessage.AppendTextToSelection(message);
|
|
|
|
|
txtMessage.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendCommand()
|
|
|
|
|
{
|
|
|
|
|
string command = txtCommand.Text;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(command))
|
|
|
|
|
{
|
|
|
|
|
lastCommand = command;
|
|
|
|
|
|
2015-09-04 01:08:40 +12:00
|
|
|
|
if (IRC.IsWorking)
|
2015-08-25 04:38:35 +12:00
|
|
|
|
{
|
|
|
|
|
SendCommand(command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txtCommand.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendCommand(string command)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(command))
|
|
|
|
|
{
|
|
|
|
|
if (command.StartsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
command = command.Substring(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRC.SendRawMessage(command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendMessage()
|
|
|
|
|
{
|
|
|
|
|
string message = txtMessage.Text;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(message))
|
|
|
|
|
{
|
|
|
|
|
lastMessage = message;
|
|
|
|
|
|
2015-09-04 01:08:40 +12:00
|
|
|
|
if (IRC.IsWorking)
|
2015-08-25 04:38:35 +12:00
|
|
|
|
{
|
|
|
|
|
SendMessage(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txtMessage.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendMessage(string message)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(message))
|
|
|
|
|
{
|
|
|
|
|
if (message.StartsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
IRC.SendRawMessage(message.Substring(1));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IRC.SendMessage(message, txtChannel.Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Connect()
|
|
|
|
|
{
|
2015-08-25 06:05:35 +12:00
|
|
|
|
if (CheckInfo())
|
|
|
|
|
{
|
2015-09-04 01:34:13 +12:00
|
|
|
|
btnConnect.Text = Resources.IRCClientForm_Connect_Disconnect;
|
2015-08-25 06:05:35 +12:00
|
|
|
|
btnCommandSend.Enabled = btnMessageSend.Enabled = true;
|
|
|
|
|
tcMain.SelectedTab = tpOutput;
|
|
|
|
|
IRC.Connect();
|
|
|
|
|
}
|
2015-08-25 04:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Disconnect()
|
|
|
|
|
{
|
2015-09-04 01:34:13 +12:00
|
|
|
|
btnConnect.Text = Resources.IRCClientForm_Disconnect_Connect;
|
2015-08-25 04:38:35 +12:00
|
|
|
|
btnCommandSend.Enabled = btnMessageSend.Enabled = false;
|
|
|
|
|
IRC.Disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 06:05:35 +12:00
|
|
|
|
private bool CheckInfo()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Info.Server))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Server field cannot be empty.", "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Info.Nickname))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Nickname field cannot be empty.", "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Info.Username))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Username field cannot be empty.", "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(Info.Realname))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Realname field cannot be empty.", "ShareX - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
#region Form events
|
|
|
|
|
|
2015-09-04 01:24:25 +12:00
|
|
|
|
private void tcMain_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (tcMain.SelectedTab == tpOutput)
|
|
|
|
|
{
|
|
|
|
|
txtCommand.Focus();
|
|
|
|
|
}
|
|
|
|
|
else if (tcMain.SelectedTab == tpMessages)
|
|
|
|
|
{
|
|
|
|
|
txtMessage.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
private void btnConnect_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-09-04 01:08:40 +12:00
|
|
|
|
if (!IRC.IsWorking)
|
2015-08-25 04:38:35 +12:00
|
|
|
|
{
|
|
|
|
|
Connect();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 08:36:20 +12:00
|
|
|
|
private void rtbOutput_LinkClicked(object sender, LinkClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
URLHelpers.OpenURL(e.LinkText);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
private void txtCommand_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
SendCommand();
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.Up && !string.IsNullOrEmpty(lastCommand))
|
|
|
|
|
{
|
|
|
|
|
txtCommand.Text = lastCommand;
|
|
|
|
|
txtCommand.SelectionStart = txtCommand.TextLength;
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCommandSend_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SendCommand();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 23:36:57 +12:00
|
|
|
|
private void tcMessages_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TabInfo tabInfo = tabManager.ActiveTab;
|
|
|
|
|
|
|
|
|
|
if (tabInfo != null)
|
|
|
|
|
{
|
|
|
|
|
txtChannel.Text = tabInfo.Name;
|
|
|
|
|
}
|
2015-09-04 01:24:25 +12:00
|
|
|
|
|
|
|
|
|
txtMessage.Focus();
|
2015-08-31 23:36:57 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
private void txtMessage_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
{
|
|
|
|
|
SendMessage();
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.Up && !string.IsNullOrEmpty(lastMessage))
|
|
|
|
|
{
|
|
|
|
|
txtMessage.Text = lastMessage;
|
|
|
|
|
txtMessage.SelectionStart = txtMessage.TextLength;
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnMessagesMenu_MouseClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
cmsMessage.Show(btnMessagesMenu, new Point(0, btnMessagesMenu.Height + 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Message menu
|
|
|
|
|
|
|
|
|
|
private void tsmiMessageBold_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Bold);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiMessageItalic_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Italic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiMessageUnderline_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Underline);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiMessageNormal_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Reset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorWhite_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.White));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorBlack_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Black));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorBlue_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Blue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorGreen_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Green));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorLightRed_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.LightRed));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorBrown_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Brown));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorPurple_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Purple));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorOrange_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Orange));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorYellow_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Yellow));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorLightGreen_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.LightGreen));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorCyan_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Cyan));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorLightCyan_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.LightCyan));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorLightBlue_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.LightBlue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorPink_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Pink));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorGrey_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.Grey));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiColorLightGrey_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AppendMessage(IRCText.Color(IRCColors.LightGrey));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Message menu
|
|
|
|
|
|
|
|
|
|
private void btnMessageSend_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SendMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Form events
|
|
|
|
|
|
|
|
|
|
#region IRC events
|
|
|
|
|
|
|
|
|
|
private void IRC_Disconnected()
|
|
|
|
|
{
|
|
|
|
|
if (!Info.AutoReconnect)
|
|
|
|
|
{
|
|
|
|
|
Disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IRC_Output(MessageInfo messageInfo)
|
|
|
|
|
{
|
2015-09-10 04:21:31 +12:00
|
|
|
|
AppendOutput(messageInfo.Content, Color.Black);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IRC_ErrorOutput(Exception e)
|
|
|
|
|
{
|
|
|
|
|
AppendOutput(e.ToString(), Color.Red);
|
2015-08-25 04:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void IRC_Message(UserInfo user, string channel, string message)
|
|
|
|
|
{
|
2015-08-31 22:57:51 +12:00
|
|
|
|
this.InvokeSafe(() =>
|
|
|
|
|
{
|
2015-09-09 07:54:49 +12:00
|
|
|
|
if (channel[0] != '#' && user.UserType == IRCUserType.User)
|
|
|
|
|
{
|
|
|
|
|
channel = user.Nickname;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 04:21:31 +12:00
|
|
|
|
tabManager.AddMessage(channel, $"{user.Nickname}: {message}");
|
2015-08-31 22:57:51 +12:00
|
|
|
|
});
|
2015-08-25 04:38:35 +12:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 09:40:57 +12:00
|
|
|
|
private void IRC_UserJoined(UserInfo user, string channel)
|
|
|
|
|
{
|
2015-09-04 00:28:34 +12:00
|
|
|
|
if (user.Nickname == IRC.CurrentNickname && user.Username == Info.Username)
|
2015-08-25 09:40:57 +12:00
|
|
|
|
{
|
|
|
|
|
this.InvokeSafe(() =>
|
|
|
|
|
{
|
2015-08-31 23:25:40 +12:00
|
|
|
|
tabManager.AddChannel(channel);
|
2015-08-31 23:36:57 +12:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(txtChannel.Text))
|
|
|
|
|
{
|
|
|
|
|
txtChannel.Text = channel;
|
|
|
|
|
}
|
2015-08-25 09:40:57 +12:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 04:38:35 +12:00
|
|
|
|
#endregion IRC events
|
|
|
|
|
}
|
|
|
|
|
}
|