Beispiel #1
0
        public void Send(object sender, MouseButtonEventArgs e)
        {
            long   time = Time.Now();
            string url  = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg" +
                          "?sid=" + Data.wxsid +
                          "&skey=" + Data.skey +
                          "&pass_ticket=" + Data.pass_ticket +
                          "&r=" + time;
            WebRequest request = WebRequest.Create(url);

            request.Method = "POST";

            JObject jsonObj = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest));
            SendMsg msg = new SendMsg();

            msg.FromUserName = Data.me.UserName;
            msg.ToUserName   = user.UserName;
            msg.Type         = 1;
            msg.Content      = SendBox.Text.Replace("\r", "");
            msg.ClientMsgId  = time;
            msg.LocalID      = time;
            SendBox.Clear();
            jsonObj.Add("Msg", JObject.FromObject(msg));

            byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", ""));
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader reader    = new StreamReader(dataStream);
            string       ret       = reader.ReadToEnd();
            webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject <webwxsendmsg>(ret);

            reader.Close();
            dataStream.Close();
            response.Close();
            Msg recvmsg = new Msg();

            recvmsg.MsgId        = wxsendmsg.MsgID;
            recvmsg.FromUserName = msg.FromUserName;
            recvmsg.ToUserName   = msg.ToUserName;
            recvmsg.MsgType      = msg.Type;
            recvmsg.Content      = msg.Content;
            recvmsg.CreateTime   = msg.LocalID;

            Trace.WriteLine("发送消息");
            Trace.WriteLine(recvmsg.Content);

            Data.main.记录消息(recvmsg);
        }
Beispiel #2
0
 /// <summary>
 /// Handles sending the current text in the text box to the game log
 /// </summary>
 ///
 /// <param name="sender">The object sending the event</param>
 /// <param name="args">The arguments sent</param>
 private void SendBox_KeyPress(object sender, KeyPressEventArgs args)
 {
     // Only send if there is something to send and the user pressed enter
     if (args.KeyChar == (char)Keys.Enter && SendBox.Text.Length > 0)
     {
         LogMaster.Log($"{Game.CurrentPlayer.Name}: {SendBox.Text}");
         SendBox.Clear();
     }
 }
Beispiel #3
0
 /// <summary>
 /// Handles sending the current text in the text box to the game log
 /// </summary>
 ///
 /// <param name="sender">The object sending the event</param>
 /// <param name="args">The arguments sent</param>
 private void SendButton_Click(object sender, EventArgs args)
 {
     // Only send something if there is something to send
     if (SendBox.Text.Length > 0)
     {
         LogMaster.Log($"{Game.CurrentPlayer.Name}: {SendBox.Text}");
         SendBox.Clear();
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     if (SendBox.Text != "\n")
     {
         SendMessage();
     }
     else
     {
         SendBox.Clear();
     }
 }
 private void SendMessage()
 {
     ReciveBox.AppendText(m_MyNick + ": " + SendBox.Text + "\n");
     m_ParentMsg.SendMsg(m_PrivateNick, SendBox.Text);
     SendBox.Clear();
     // Auto scroll
     ReciveBox.SelectionStart = ReciveBox.TextLength;
     ReciveBox.Focus();
     ReciveBox.ScrollToCaret();
     SendBox.Focus();
 }
Beispiel #6
0
        void AssembleSendString(MessageHeaders type, string toSend = "")
        {
            if (m_CurrentClientType == ClientType.MultiCast)
            {
                switch (type)
                {
                case MessageHeaders.REGULAR:
                    if (toSend != null && toSend.Length > 0)
                    {
                        m_Multicast.m_SendQueue.Add((int)MessageHeaders.REGULAR + m_UserName + ": " + toSend);
                    }
                    SendBox.Clear();
                    break;

                case MessageHeaders.CONNECT:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.CONNECT + m_UserName);
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.REGULAR + m_UserName + toSend);
                    break;

                case MessageHeaders.DISCONNECT:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.DISCONNECT + m_UserName);
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.REGULAR + m_UserName + toSend);
                    break;

                case MessageHeaders.USERSNAMES:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.USERSNAMES + m_UserName);
                    break;

                case MessageHeaders.SYSTEM:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.SYSTEM + toSend);
                    SendBox.Clear();
                    break;

                case MessageHeaders.PULSE:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.PULSE + m_UserName + " Pulse");
                    break;

                case MessageHeaders.COORD:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.COORD + toSend);
                    break;

                case MessageHeaders.STFU:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.STFU + m_UserName);
                    break;

                case MessageHeaders.ALLCLEAR:
                    m_Multicast.m_SendQueue.Add((int)MessageHeaders.ALLCLEAR + m_UserName);
                    break;
                }
            }
        }
Beispiel #7
0
        private void SendBtn_Click(object sender, EventArgs e)
        {
            string message = this.SendBox.Text;

            SendBox.AppendText("work");
            SendBox.Clear();

            Label labmsg = new Label();

            labmsg.AutoSize = true;
            labmsg.Text     = user + ": " + message;
            MessageBox.Show(labmsg.Text);
            DisplayPanel.Controls.Add(labmsg);
            DisplayPanel.ScrollControlIntoView(labmsg);
        }
 private void SendBox_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (SendBox.Text != "\n")
     {
         if (e.KeyChar == '\r')
         {
             SendBox.Text = SendBox.Text.TrimEnd('\n');
             SendMessage();
         }
     }
     else
     {
         SendBox.Clear();
     }
 }
Beispiel #9
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                ASCIIEncoding enc = new ASCIIEncoding();
                byte[]        msg = new byte[4096];
                msg = enc.GetBytes(SendBox.Text);

                sck.Send(msg);
                if (SendBox.Text != "")
                {
                    listMessage.Items.Add("Me:" + SendBox.Text);
                }
                SendBox.Clear();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }
 private void SendBtn_Click(object sender, RoutedEventArgs e)
 {
     SendBtn.IsEnabled   = false;
     CancelBtn.IsEnabled = true;
     SendBox.Text       += "\r\n";
     SendBox.IsReadOnly  = true;
     stringBuilder       = new StringBuilder(SendBox.Text);
     int.TryParse(IntervalBox.Text, out int interval);
     if (sendingThread != null)
     {
         sendingThread.Abort();
     }
     sendingThread = new Thread(delegate()
     {
         while (true)
         {
             int lineBreakIndex = stringBuilder.ToString().IndexOf('\n');
             if (lineBreakIndex == -1)
             {
                 Dispatcher.Invoke(new Action(() =>
                 {
                     SendBtn.IsEnabled   = true;
                     CancelBtn.IsEnabled = false;
                     SendBox.IsReadOnly  = false;
                     SendBox.Clear();
                 }));
                 break;
             }
             string firstLine = stringBuilder.ToString().Substring(0, lineBreakIndex).Trim();
             stringBuilder.Remove(0, lineBreakIndex + 1);
             if (firstLine != string.Empty)
             {
                 MessageSent?.Invoke(firstLine);
             }
             Thread.Sleep(interval);
         }
     });
     sendingThread.Start();
 }
Beispiel #11
0
        private void Send()
        {
            string sendData = SendBox.Text;

            byte[] sendBuffer = null;
            if (hex.IsChecked != true)
            {
                try
                {
                    _serialPort.Write(sendData + "\r\n");
                    SendBox.Clear();
                    //_serialPort.Write(sendCharArray, 0, sendCharArray.Length);
                    //_serialPort.Write(sendByteArray, 0, sendByteArray.Length);
                }
                catch (Exception ex)
                {
                    notifier.ShowError(ex.Message);
                    return;
                }
            }
            else
            {
                try
                {
                    sendData = sendData.Replace(" ", "");
                    sendData = sendData.Replace("\r", "");
                    sendData = sendData.Replace("\n", "");
                    if (sendData.Length == 1)
                    {
                        sendData = "0" + sendData;
                    }
                    else if (sendData.Length % 2 != 0)
                    {
                        sendData = sendData.Remove(sendData.Length - 1, 1);
                    }

                    List <string> sendData16 = new List <string>();
                    for (int i = 0; i < sendData.Length; i += 2)
                    {
                        sendData16.Add(sendData.Substring(i, 2));
                    }
                    sendBuffer = new byte[sendData16.Count];
                    for (int i = 0; i < sendData16.Count; i++)
                    {
                        sendBuffer[i] = (byte)(Convert.ToInt32(sendData16[i], 16));
                    }
                }
                catch
                {
                    notifier.ShowWarning("HEX Message Only");
                    return;
                }
                try
                {
                    _serialPort.Write(sendBuffer, 0, sendBuffer.Length);
                    SendBox.Clear();
                }
                catch (Exception ex)
                {
                    notifier.ShowError(ex.Message);
                    return;
                }
            }
        }