コード例 #1
0
 private void buttonConnect_Click(object sender, EventArgs e)
 {
     if (this.comboBoxUsers.SelectedIndex != 0)
     {
         Sock.SendToBuddy(userName, true, buddyList[this.comboBoxUsers.Text], this.comboBoxUsers.Text, "Reconnected!", null);
     }
 }
コード例 #2
0
        private bool handleFileIO(byte[] buffer, int length, string filepath, int chunk, string ip, string fullname)
        {
            string fileData = StringCompressor.ToHexString(buffer, length);
            string m        = "<OBJECT>" + "FILE*" + chunk.ToString() + "*" + Path.GetFileName(filepath).Replace("?", "_") + "*" + fileData;
            string chk      = Sock.Checksum(Sock.Checksum(m)); // do it twice, trust me

            _e = null;
            AckDone.Reset();
            Sock.SendToBuddy(userName, false, ip, fullname, m, null);

            // wait for confirmations
            AckDone.WaitOne(5000);

            if (!isExit && (_e == null || !_e.Valid || _e.Checksum != chk))
            {
                // try to repeat once
                _e = null;
                AckDone.Reset();
                Sock.SendToBuddy(userName, false, ip, fullname, m, null);
                // wait for confirmations
                AckDone.WaitOne(5000);

                if (_e == null || !_e.Valid || _e.Checksum != chk)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
        private void processTypedMessage(string message)
        {
            if (String.IsNullOrWhiteSpace(message))
            {
                richTextBoxChatIn.Clear();
                return;
            }

            string m = message.TrimEnd();

            // cmd's
            if (m.StartsWith("<CMD>"))
            {
                m = m.Replace("<CMD>", "").ToLower();

                if (m == "clear")
                {
                    this.richTextBoxChatOut.Clear();
                }
                else if (m == "max")
                {
                    this.WindowState = FormWindowState.Maximized;
                }
                else if (m == "hide")
                {
                    this.WindowState = FormWindowState.Minimized;
                }
                else if (m == "pop")
                {
                    ActivateMe();
                }
                else if (m == "debug")
                {
                    Sock.InDebug = true;
                }
                else if (m == "normal")
                {
                    Sock.InDebug = false;
                }
                else if (m == "exit")
                {
                    this.Close();
                }
                else if (m == "look")
                {
                    this.buttonGoConnection_Click(null, null);
                }
                else if (m == "all")
                {
                    this.comboBoxUsers.SelectedIndex = 0;
                }
                richTextBoxChatIn.Clear();
                return;
            }

            if (this.comboBoxUsers.Items.Count == 1)
            {
                appendText(richTextBoxChatOut, "No friends can be found." + Environment.NewLine, Color.LightGreen);
                // scroll it automatically
                richTextBoxChatIn.Text           = m;
                richTextBoxChatIn.SelectionStart = richTextBoxChatIn.Text.Length;
                richTextBoxChatIn.ScrollToCaret();
                return;
            }

            // handle multi lines nicely
            if (m.Contains('\n'))
            {
                string[] splits = m.Split(new char[] { '\n' }, StringSplitOptions.None);
                m = "";
                foreach (string s in splits)
                {
                    m += s + "\n\t\t";
                }
                m = m.TrimEnd();
            }

            string buddyName = this.comboBoxUsers.Text;

            // ready to send message to a buddy
            if (this.comboBoxUsers.SelectedIndex != 0 && !Sock.SendToBuddy(userName, false, buddyList[buddyName], buddyName, m, null))
            {
                appendText(richTextBoxChatOut, "Me:\t\t", Color.LightGreen);
                appendText(richTextBoxChatOut, m + " <remote ignored>" + Environment.NewLine, Color.LightSalmon);

                // scroll it automatically
                richTextBoxChatIn.Text           = m;
                richTextBoxChatIn.SelectionStart = richTextBoxChatIn.Text.Length;
                richTextBoxChatIn.ScrollToCaret();
                return;
            }
            else
            {
                appendText(richTextBoxChatOut, "Me:\t\t", Color.LightGreen);
                appendText(richTextBoxChatOut, m + Environment.NewLine, Color.LightSalmon);
                //richTextBoxChatOut.SelectionStart = richTextBoxChatOut.Text.Length;
                // scroll it automatically
                richTextBoxChatOut.ScrollToCaret();
            }

            this.richTextBoxChatIn.Text = "";

            // send message to each buddy
            if (this.comboBoxUsers.SelectedIndex == 0)
            {
                foreach (string key in this.buddyList.Keys)
                {
                    Sock.SendToBuddy(userName, false, buddyList[key], key, m, null);
                }
            }
        }