Пример #1
0
        private void textBoxChatInput_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (allowInput)
                {
                    if (e.KeyChar == (char)27)
                    {
                        if (alprivMsgs.Contains(tabControlChatTabs.SelectedTab.Text))
                        {
                            for (int i = 0; i < tabControlChatTabs.TabPages.Count; i++)
                            {
                                if (tabControlChatTabs.TabPages[i].Text.ToString().Equals(tabControlChatTabs.SelectedTab.Text))
                                {
                                    removeTabPageDelegate = new RemoveTabPage_Delegate(RemoveTabPage_DelegateFunction);
                                    IAsyncResult r = BeginInvoke(removeTabPageDelegate, new object[] { tabControlChatTabs.TabPages[i] });
                                    EndInvoke(r);
                                }
                            }
                        }
                    }

                    if (e.KeyChar == (char)13)
                    {
                        if (User.extra != null)
                        {
                            this.Text = Application.Name + " [" + User.server + ":" + User.port.ToString() + ", " + irc.Nickname + "] - " + User.extra.ToString();
                        }

                        if (textBoxChatInput.Text.Length > 0)
                        {
                            if (textBoxChatInput.Text.StartsWith("/"))
                            {
                                if (textBoxChatInput.Text.StartsWith("/nick ") ||
                                    textBoxChatInput.Text.StartsWith("/me ") ||
                                    textBoxChatInput.Text.StartsWith("/msg ") ||
                                    textBoxChatInput.Text.StartsWith("/query ") ||
                                    textBoxChatInput.Text.StartsWith("/op ") ||
                                    textBoxChatInput.Text.Equals("/basic") ||
                                    textBoxChatInput.Text.Equals("/help") ||
                                    textBoxChatInput.Text.Equals("/admin") ||
                                    textBoxChatInput.Text.Equals("/config") ||
                                    textBoxChatInput.Text.Equals("/close") ||
                                    textBoxChatInput.Text.Equals("/disconnect") ||
                                    textBoxChatInput.Text.StartsWith("/own ") ||
                                    textBoxChatInput.Text.StartsWith("/halfop ") ||
                                    textBoxChatInput.Text.StartsWith("/protect ") ||
                                    textBoxChatInput.Text.StartsWith("/voice ") ||
                                    textBoxChatInput.Text.StartsWith("/ignore ") ||
                                    textBoxChatInput.Text.Equals("/clear") ||
                                    textBoxChatInput.Text.StartsWith("/deop ") ||
                                    textBoxChatInput.Text.StartsWith("/devoice ") ||
                                    textBoxChatInput.Text.StartsWith("/deown ") ||
                                    textBoxChatInput.Text.StartsWith("/dehalfop ") ||
                                    textBoxChatInput.Text.StartsWith("/unprotect ") ||
                                    textBoxChatInput.Text.StartsWith("/ban ") ||
                                    textBoxChatInput.Text.StartsWith("/unban ") ||
                                    textBoxChatInput.Text.StartsWith("/kick ") ||
                                    textBoxChatInput.Text.StartsWith("/topic ") ||
                                    textBoxChatInput.Text.Equals("/topic") ||
                                    textBoxChatInput.Text.StartsWith("/whois ") ||
                                    textBoxChatInput.Text.Equals("/quit") ||
                                    textBoxChatInput.Text.Equals("/exit") ||
                                    textBoxChatInput.Text.StartsWith("/quit ") ||
                                    textBoxChatInput.Text.StartsWith("/autoscroll ") ||
                                    textBoxChatInput.Text.StartsWith("/autoconnect ") ||
                                    textBoxChatInput.Text.StartsWith("/exit "))
                                {
                                    if (textBoxChatInput.Text.Equals("/config"))
                                    {
                                        ShowConfigHelp();
                                    }

                                    if (textBoxChatInput.Text.Equals("/admin"))
                                    {
                                        ShowAdvancedCommandHelp();
                                    }

                                    if (textBoxChatInput.Text.Equals("/help"))
                                    {
                                        ShowMainHelp();
                                    }

                                    if (textBoxChatInput.Text.Equals("/basic"))
                                    {
                                        ShowBasicCommandHelp();
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/autoconnect "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(13);

                                        if (message.Equals("on"))
                                        {
                                            menuItemAutoConnect.Checked = true;
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Connect has been turned on\n");
                                        }

                                        if (message.Equals("off"))
                                        {
                                            menuItemAutoConnect.Checked = false;
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Connect has been turned off\n");
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/autoscroll "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(12);

                                        if (message.Equals("on"))
                                        {
                                            menuItemAutoScroll.Checked = true;
                                            timerAutoScroll.Enabled = true;

                                            ScrollChatWindow();

                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Scroll has been turned on\n");
                                        }

                                        if (message.Equals("off"))
                                        {
                                            menuItemAutoScroll.Checked = false;
                                            timerAutoScroll.Enabled = false;

                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Scroll has been turned off\n");
                                        }
                                    }

                                    if (textBoxChatInput.Text.Equals("/disconnect"))
                                    {
                                        if (menuItemDisconnect.Enabled)
                                        {
                                            menuItemDisconnect_Click(sender, e);
                                        }
                                    }

                                    if (textBoxChatInput.Text.Equals("/close"))
                                    {
                                        if (alprivMsgs.Contains(tabControlChatTabs.SelectedTab.Text))
                                        {
                                            for (int i = 0; i < tabControlChatTabs.TabPages.Count; i++)
                                            {
                                                if (tabControlChatTabs.TabPages[i].Text.ToString().Equals(tabControlChatTabs.SelectedTab.Text))
                                                {
                                                    removeTabPageDelegate = new RemoveTabPage_Delegate(RemoveTabPage_DelegateFunction);
                                                    IAsyncResult r = BeginInvoke(removeTabPageDelegate, new object[] { tabControlChatTabs.TabPages[i] });
                                                    EndInvoke(r);
                                                }
                                            }
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/quit ") || textBoxChatInput.Text.StartsWith("/exit "))
                                    {
                                        mstrQuitMessage = textBoxChatInput.Text.Substring(6);

                                        Exit();
                                    }

                                    if (textBoxChatInput.Text.Equals("/quit") || textBoxChatInput.Text.Equals("/exit"))
                                    {
                                        Exit();
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/msg ") || textBoxChatInput.Text.StartsWith("/query "))
                                    {
                                        string comment = null;
                                        string message = null;

                                        if (textBoxChatInput.Text.StartsWith("/msg "))
                                        {
                                            message = textBoxChatInput.Text.Substring(5);
                                        }

                                        if (textBoxChatInput.Text.StartsWith("/query "))
                                        {
                                            message = textBoxChatInput.Text.Substring(7);
                                        }

                                        string[] split = message.Split(' ');

                                        for (int i = 1; i < split.Length; i++)
                                        {
                                            comment += split[i].ToString() + " ";
                                        }

                                        if (comment != null)
                                        {
                                            comment = comment.TrimStart(' ');
                                        }

                                        if (!split[0].ToString().Equals(irc.Nickname.ToString()))
                                        {
                                            if (split[0].ToString().Equals("NickServ"))
                                            {
                                                split[0] = split[0].ToLower();
                                            }

                                            if (listBoxUserList.Items.Contains(split[0].ToString()) || split[0].ToString().Equals("nickserv"))
                                            {
                                                textBoxChatWindow = new Khendys.Controls.ExRichTextBox();

                                                textBoxChatWindow.BackColor = User.background;
                                                textBoxChatWindow.ForeColor = User.text;
                                                textBoxChatWindow.ReadOnly = true;
                                                textBoxChatWindow.Font = new Font(User.defaultFontFamily, User.defaultFontSize, User.defaultFontStyle, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

                                                tab = new TabPage(split[0].ToString());

                                                if (!alprivMsgs.Contains(split[0].ToString()))
                                                {
                                                    textBoxChatWindow.Dock = System.Windows.Forms.DockStyle.Fill;

                                                    textBoxChatWindow.Visible = true;

                                                    tab.Controls.Add(textBoxChatWindow);

                                                    alprivMsgs.Add(split[0].ToString());

                                                    alPrivMsgWindows = new ArrayList();
                                                    alPrivMsgWindows.Add(textBoxChatWindow);

                                                    alPrivMsgWindowList.Add(alPrivMsgWindows);

                                                    addTabPageDelegate = new AddTabPage_Delegate(AddTabPage_DelegateFunction);
                                                    IAsyncResult r = BeginInvoke(addTabPageDelegate, new object[] { tab });
                                                    EndInvoke(r);

                                                    tabControlChatTabs.SelectedTab = tab;

                                                    if (comment != null && comment.Length > 0)
                                                    {
                                                        if (split[0].Equals("nickserv"))
                                                        {
                                                            irc.Message(SendType.Message, split[0].ToString(), comment.ToString());
                                                        }
                                                        else
                                                        {
                                                            irc.Message(SendType.Message, split[0].ToString(), comment.ToString());
                                                        }

                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "[");
                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", DateTime.Now.ToShortTimeString().ToString());
                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "] <");
                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", Nickname(irc.Nickname.ToString()));
                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "> ");
                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", comment.ToString());
                                                        AppendText(tabControlChatTabs.SelectedTab.Text, "text", "\n");

                                                        User.Log(tabControlChatTabs.SelectedTab.Text, "[" + DateTime.Now.ToShortTimeString().ToString() + "] <" + Nickname(irc.Nickname.ToString()) + "> " + comment.ToString() + "\n");
                                                    }
                                                }
                                                else
                                                {
                                                    for (int i = 0; i < tabControlChatTabs.TabPages.Count; i++)
                                                    {
                                                        if (tabControlChatTabs.TabPages[i].Text.ToString().Equals(split[0]))
                                                        {
                                                            tab = tabControlChatTabs.TabPages[i];
                                                        }
                                                    }

                                                    for (int i = 0; i < tab.Controls.Count; i++)
                                                    {
                                                        if (tab.Controls[i].GetType().Name == "ExRichTextBox")
                                                        {
                                                            tabControlChatTabs.SelectedTab = tab;

                                                            if (comment != null && comment.Length > 0)
                                                            {
                                                                if (split[0].Equals("nickserv"))
                                                                {
                                                                    irc.Message(SendType.Message, split[0].ToString(), comment.ToString());
                                                                }
                                                                else
                                                                {
                                                                    irc.Message(SendType.Message, split[0].ToString(), comment.ToString());
                                                                }

                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "[");
                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", DateTime.Now.ToShortTimeString().ToString());
                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "] <");
                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", Nickname(irc.Nickname.ToString()));
                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "> ");
                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", comment.ToString());
                                                                AppendText(tabControlChatTabs.SelectedTab.Text, "text", "\n");

                                                                User.Log(tabControlChatTabs.SelectedTab.Text, "[" + DateTime.Now.ToShortTimeString().ToString() + "] <" + Nickname(irc.Nickname.ToString()) + "> " + comment.ToString() + "\n");
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/whois "))
                                    {
                                        string nickname = textBoxChatInput.Text.Substring(7);

                                        if (listBoxUserList.Items.Contains(Nickname(nickname)))
                                        {
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                            AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- " + nickname + " is " +
                                                irc.GetChannelUser(User.channel, nickname).Ident.ToString() + "@" +
                                                irc.GetChannelUser(User.channel, nickname).Host.ToString() + " (" +
                                                irc.GetChannelUser(User.channel, nickname).Realname.ToString() + ")\n");

                                            User.Log(tabControlChatTabs.SelectedTab.Text, "[" + DateTime.Now.ToShortTimeString().ToString() + "] " + " -!- " + nickname + " is " + irc.GetChannelUser(User.channel, nickname).Ident.ToString() + "@" + irc.GetChannelUser(User.channel, nickname).Host.ToString() + " (" + irc.GetChannelUser(User.channel, nickname).Realname.ToString() + ")\n");
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/me "))
                                    {
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "action", "* " + irc.Nickname.ToString() + " ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "action", textBoxChatInput.Text.Substring(4));
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "action", "\n");

                                        irc.Message(SendType.Action, tabControlChatTabs.SelectedTab.Text, textBoxChatInput.Text.Substring(4));

                                        User.Log(tabControlChatTabs.SelectedTab.Text, "[" + DateTime.Now.ToShortTimeString().ToString() + "] * " + irc.Nickname.ToString() + " " + textBoxChatInput.Text.Substring(4) + "\n");
                                    }

                                    if (textBoxChatInput.Text.Equals("/topic"))
                                    {
                                        AppendText(User.channel, "notice", " -!- Topic: " + irc.GetChannel(User.channel).Topic.ToString() + "\n");
                                        User.Log(User.channel, " -!- Topic: " + irc.GetChannel(User.channel).Topic.ToString() + "\n");
                                    }

                                    if (textBoxChatInput.Text.Equals("/clear"))
                                    {
                                        ClearText();
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/topic "))
                                    {
                                        if (irc.GetChannelUser(User.channel, irc.Nickname).IsOp ||
                                            irc.GetChannelUser(User.channel, irc.Nickname).IsOwner)
                                        {
                                            string message = textBoxChatInput.Text.Substring(7);
                                            string[] split = message.Split(' ');

                                            if (split.Length > 0)
                                            {
                                                message = message.TrimEnd(' ');
                                                AppendText(User.channel, "notice", " -!- " + irc.Nickname.ToString() + " changed the topic to: " + message + "\n");

                                                irc.Topic(User.channel, message);

                                                User.Log(User.channel, " -!- " + irc.Nickname.ToString() + " changed the topic to: " + message + "\n");
                                                this.Text = Application.Name + " [" + User.server + ":" + User.port.ToString() + ", " + irc.Nickname + "] - " + message.ToString();
                                            }
                                        }
                                        else
                                        {
                                            AppendText(User.channel, "notice", " -!- " + "You need to have operator status or higher in order to set the topic. This is a restriction imposed by " + Application.Name + " in order to protect the topic from being set by non-operators.\n");
                                            User.Log(User.channel, " -!- " + "You need to have operator status or higher in order to set the topic. This is a restriction imposed by " + Application.Name + " in order to protect the topic from being set by non-operators.\n");
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/protect "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(4);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsVoice)
                                            {
                                                irc.Devoice(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOwner)
                                            {
                                                irc.DeOwner(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsHalfOp)
                                            {
                                                irc.DeHalfOp(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOp)
                                            {
                                                irc.Deop(User.channel, split[0].ToString());
                                            }

                                            irc.Protect(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/halfop "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(4);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsVoice)
                                            {
                                                irc.Devoice(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOwner)
                                            {
                                                irc.DeOwner(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOp)
                                            {
                                                irc.Deop(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsProtected)
                                            {
                                                irc.DeProtect(User.channel, split[0].ToString());
                                            }

                                            irc.HalfOp(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/own "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(4);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsVoice)
                                            {
                                                irc.Devoice(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOp)
                                            {
                                                irc.Deop(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsHalfOp)
                                            {
                                                irc.DeHalfOp(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsProtected)
                                            {
                                                irc.DeProtect(User.channel, split[0].ToString());
                                            }

                                            irc.Owner(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/op "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(4);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsVoice)
                                            {
                                                irc.Devoice(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOwner)
                                            {
                                                irc.DeOwner(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsHalfOp)
                                            {
                                                irc.DeHalfOp(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsProtected)
                                            {
                                                irc.DeProtect(User.channel, split[0].ToString());
                                            }

                                            irc.Op(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/deown "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(6);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.DeOwner(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/dehalfop "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(6);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.DeHalfOp(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/unprotect "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(6);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.DeProtect(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/deop "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(6);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.Deop(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/ignore "))
                                    {
                                        string user = textBoxChatInput.Text.Substring(8);

                                        if (user != User.username)
                                        {
                                            alIgnoredHosts.Add(irc.GetChannelUser(User.channel, user).Host.ToString());

                                            using (StreamWriter sw = new StreamWriter("ignore", true))
                                            {
                                                sw.WriteLine(irc.GetChannelUser(User.channel, user).Host.ToString());
                                            }
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/voice "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(7);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.Voice(User.channel, split[0].ToString());

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOp)
                                            {
                                                irc.Deop(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsOwner)
                                            {
                                                irc.DeOwner(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsProtected)
                                            {
                                                irc.DeProtect(User.channel, split[0].ToString());
                                            }

                                            if (irc.GetChannelUser(User.channel, split[0].ToString()).IsHalfOp)
                                            {
                                                irc.DeHalfOp(User.channel, split[0].ToString());
                                            }
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/devoice "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(9);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.Devoice(User.channel, split[0].ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/ban "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(5);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            if (!irc.GetChannelUser(User.channel, split[0]).IsOwner &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsOp &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsHalfOp &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsProtected)
                                            {
                                                irc.Ban(User.channel, irc.GetChannelUser(User.channel, split[0].ToString()).Host.ToString());
                                            }
                                            else
                                            {
                                                AppendText(User.channel, "tag", "[");
                                                AppendText(User.channel, "time", DateTime.Now.ToShortTimeString().ToString());
                                                AppendText(User.channel, "tag", "] ");
                                                AppendText(User.channel, "notice", " -!- Ban failed. " + split[0] + " is a protected user\n");
                                            }
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/unban "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(7);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            irc.Unban(User.channel, irc.GetChannelUser(User.channel, split[0].ToString()).Host.ToString());
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/kick "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(6);
                                        string[] split = message.Split(' ');

                                        if (split.Length == 1)
                                        {
                                            if (!irc.GetChannelUser(User.channel, split[0]).IsOwner &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsOp &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsHalfOp &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsProtected)
                                            {
                                                irc.Kick(User.channel, split[0]);
                                            }
                                            else
                                            {
                                                AppendText(User.channel, "tag", "[");
                                                AppendText(User.channel, "time", DateTime.Now.ToShortTimeString().ToString());
                                                AppendText(User.channel, "tag", "] ");
                                                AppendText(User.channel, "notice", " -!- Kick failed. " + split[0] + " is a protected user\n");
                                            }
                                        }

                                        if (split.Length >= 2)
                                        {
                                            string reason = null;

                                            for (int j = 0; j < split.Length; j++)
                                            {
                                                reason += split[j].ToString() + " ";
                                            }

                                            reason = reason.TrimEnd(' ');

                                            if (!irc.GetChannelUser(User.channel, split[0]).IsOwner &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsOp &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsHalfOp &&
                                                !irc.GetChannelUser(User.channel, split[0]).IsProtected)
                                            {
                                                irc.Kick(User.channel, split[0].ToString(), reason.ToString());
                                            }
                                            else
                                            {
                                                AppendText(User.channel, "tag", "[");
                                                AppendText(User.channel, "time", DateTime.Now.ToShortTimeString().ToString());
                                                AppendText(User.channel, "tag", "] ");
                                                AppendText(User.channel, "notice", " -!- Kick failed. " + split[0] + " is a protected user\n");
                                            }
                                        }
                                    }

                                    if (textBoxChatInput.Text.StartsWith("/nick "))
                                    {
                                        string message = textBoxChatInput.Text.Substring(6);
                                        string[] split = message.Split(' ');
                                        User.username = split[0];
                                        irc.Nick(split[0].ToString());
                                        this.Text = Application.Name + " [" + User.server + ":" + User.port.ToString() + ", " + split[0].ToString() + "] - " + irc.GetChannel(User.channel).Topic.ToString();
                                    }
                                }
                            }
                            else
                            {
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "[");
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", DateTime.Now.ToShortTimeString().ToString());
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "] <");
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", Nickname(irc.Nickname.ToString()));
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "> ");
                                AppendText(tabControlChatTabs.SelectedTab.Text, "text", textBoxChatInput.Text + "\n");

                                irc.Message(SendType.Message, tabControlChatTabs.SelectedTab.Text, textBoxChatInput.Text);
                                User.Log(tabControlChatTabs.SelectedTab.Text, "[" + DateTime.Now.ToShortTimeString().ToString() + "] <" + Nickname(irc.Nickname.ToString()) + "> " + textBoxChatInput.Text + "\n");
                            }
                        }
                        textBoxChatInput.Clear();
                    }
                }
                else
                {
                    if (e.KeyChar == (char)13)
                    {
                        if (textBoxChatInput.Text != "")
                        {
                            if (textBoxChatInput.Text.StartsWith("/"))
                            {
                                if (textBoxChatInput.Text.StartsWith("/server "))
                                {
                                    string message = textBoxChatInput.Text.Substring(8);
                                    User.server = message;

                                    Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser;
                                    key = key.CreateSubKey("SOFTWARE\\" + Application.Name);
                                    key.SetValue("server", User.server.ToString());

                                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Server address has been set to " + message + "\n");
                                }

                                if (textBoxChatInput.Text.StartsWith("/port "))
                                {
                                    string message = textBoxChatInput.Text.Substring(6);

                                    try
                                    {
                                        User.port = Convert.ToInt32(message);
                                        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser;
                                        key = key.CreateSubKey("SOFTWARE\\" + Application.Name);
                                        key.SetValue("port", User.port);

                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Server port has been set to " + message + "\n");
                                    }
                                    catch (System.FormatException)
                                    {
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Server port must be a number\n");
                                    }
                                }

                                if (textBoxChatInput.Text.StartsWith("/channel "))
                                {
                                    string message = textBoxChatInput.Text.Substring(9);

                                    User.channel = message;
                                    Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser;
                                    key = key.CreateSubKey("SOFTWARE\\" + Application.Name);
                                    key.SetValue("channel", User.channel.ToString());

                                    tabControlChatTabs.TabPages[0].Text = User.channel;

                                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Channel name has been set to " + message + "\n");
                                }

                                if (textBoxChatInput.Text.Equals("/config"))
                                {
                                    ShowConfigHelp();
                                }

                                if (textBoxChatInput.Text.Equals("/admin"))
                                {
                                    ShowAdvancedCommandHelp();
                                }

                                if (textBoxChatInput.Text.Equals("/help"))
                                {
                                    ShowMainHelp();
                                }

                                if (textBoxChatInput.Text.Equals("/basic"))
                                {
                                    ShowBasicCommandHelp();
                                }

                                if (textBoxChatInput.Text.StartsWith("/autoconnect "))
                                {
                                    string message = textBoxChatInput.Text.Substring(13);

                                    if (message.Equals("on"))
                                    {
                                        menuItemAutoConnect.Checked = true;
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Connect has been turned on\n");
                                    }

                                    if (message.Equals("off"))
                                    {
                                        menuItemAutoConnect.Checked = false;
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Connect has been turned off\n");
                                    }
                                }

                                if (textBoxChatInput.Text.StartsWith("/autoscroll "))
                                {
                                    string message = textBoxChatInput.Text.Substring(12);

                                    if (message.Equals("on"))
                                    {
                                        menuItemAutoScroll.Checked = true;
                                        timerAutoScroll.Enabled = true;
                                        ScrollChatWindow();
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Scroll has been turned on\n");
                                    }

                                    if (message.Equals("off"))
                                    {
                                        menuItemAutoScroll.Checked = false;
                                        timerAutoScroll.Enabled = false;
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Auto Scroll has been turned off\n");
                                    }
                                }

                                if (textBoxChatInput.Text.StartsWith("/nick "))
                                {
                                    string message = textBoxChatInput.Text.Substring(6);
                                    string[] split = message.Split(' ');

                                    AppendText(User.channel, "tag", "[");
                                    AppendText(User.channel, "time", DateTime.Now.ToShortTimeString().ToString());
                                    AppendText(User.channel, "tag", "] ");
                                    AppendText(User.channel, "notice", " -!- " + User.username.ToString() + " is now known as " + split[0].ToString() + "\n");

                                    User.username = split[0];
                                    this.Text = Application.Name + " [" + User.server + ":" + User.port.ToString() + ", " + User.username + "]";
                                }

                                if (textBoxChatInput.Text.StartsWith("/me "))
                                {
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "action", "* " + User.username.ToString() + " ");
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "action", textBoxChatInput.Text.Substring(4));
                                    AppendText(tabControlChatTabs.SelectedTab.Text, "action", "\n");
                                }

                                if (textBoxChatInput.Text.Equals("/connect"))
                                {
                                    if (menuItemConnect.Enabled)
                                    {
                                        menuItemConnect_Click(sender, e);
                                    }
                                }

                                if (textBoxChatInput.Text.Equals("/disconnect"))
                                {
                                    if (menuItemDisconnect.Enabled)
                                    {
                                        menuItemDisconnect_Click(sender, e);
                                    }
                                }

                                if (textBoxChatInput.Text.Equals("/clear"))
                                {
                                    ClearText();
                                }

                                if (textBoxChatInput.Text.Equals("/quit") || textBoxChatInput.Text.Equals("/exit"))
                                {
                                    Exit();
                                }
                            }
                            else
                            {
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "[");
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", DateTime.Now.ToShortTimeString().ToString());
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "] (offline) <");
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", User.username.ToString());
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", "> ");
                                AppendText(tabControlChatTabs.SelectedTab.Text, "yourself", textBoxChatInput.Text);
                                AppendText(tabControlChatTabs.SelectedTab.Text, "text", "\n");
                            }
                        }

                        textBoxChatInput.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                User.ErrorLog(ex.ToString());
            }
        }
Пример #2
0
        private void irc_OnQuit(string str1, string str2, Data ircdata)
        {
            try
            {
                if (str2 != null)
                {
                    AppendText(User.channel, "tag", "[");
                    AppendText(User.channel, "time", DateTime.Now.ToShortTimeString().ToString());
                    AppendText(User.channel, "tag", "] ");
                    AppendText(User.channel, "notice", " -!- " + ircdata.Nick.ToString() + " [" + ircdata.Ident + "@" + ircdata.Host + "] has quit" + " (" + str2.ToString() + ")" + "\n");
                    User.Log(User.channel, "[" + DateTime.Now.ToShortTimeString().ToString() + "] " + " -!- " + ircdata.Nick.ToString() + " [" + ircdata.Ident + "@" + ircdata.Host + "] has quit" + " (" + str2.ToString() + ")" + "\n");
                }
                else
                {
                    AppendText(User.channel, "tag", "[");
                    AppendText(User.channel, "time", DateTime.Now.ToShortTimeString().ToString());
                    AppendText(User.channel, "tag", "] ");
                    AppendText(User.channel, "notice", " -!- " + ircdata.Nick.ToString() + " [" + ircdata.Ident + "@" + ircdata.Host + "] has quit\n");
                    User.Log(User.channel, "[" + DateTime.Now.ToShortTimeString().ToString() + "] " + " -!- " + ircdata.Nick.ToString() + " [" + ircdata.Ident + "@" + ircdata.Host + "] has quit\n");
                }

                if (alprivMsgs.Contains(ircdata.Nick.ToString()))
                {
                    for (int i = 0; i < tabControlChatTabs.TabPages.Count; i++)
                    {
                        if (tabControlChatTabs.TabPages[i].Text.ToString().Equals(ircdata.Nick.ToString()))
                        {
                            removeTabPageDelegate = new RemoveTabPage_Delegate(RemoveTabPage_DelegateFunction);
                            IAsyncResult r = BeginInvoke(removeTabPageDelegate, new object[] { tabControlChatTabs.TabPages[i] });
                            EndInvoke(r);
                        }
                    }
                }

                RemoveUserFromUserList(ircdata.Nick.ToString());
            }
            catch (Exception ex)
            {
                User.ErrorLog(ex.ToString());
            }
        }