Ejemplo n.º 1
0
        public ChatContentDto AddChatContent(ChatContentDto Dto)
        {
            ChatContent entity = chatContentDtoMapper.Map(Dto);

            chatContentRepository.Add(entity);
            return(Dto);
        }
Ejemplo n.º 2
0
 private void ShowMessage()
 {
     stackInput.Clear();
     while (true)
     {
         if (stackInput.Count < 1)
         {
             readData.Suspend();
         }
         else
         {
             ChatContent temp = stackInput.Pop();
             if (temp.Receiver == "" || temp.Receiver == null)
             {
                 ShowChat(temp);
             }
             else
             {
                 if (!temp.Save())
                 {
                     //throw new Exception("Save error");
                     MessageBox.Show("");
                 }
             }
             SendChatContent(temp);
         }
     }
 }
        nfloat CalculateHeightFor(ChatContent item, UITableView tableView)
        {
            if (item is ChatPerson)
            {
                return(BaseChatCell.ImageGap * 2 + BaseChatCell.ImageDisplaySize);
            }
            else if (item is TextMessage)
            {
                var tm = item as TextMessage;
                return(BaseChatCell.ImageGap +
                       BaseChatCell.HeightForFont(BaseChatCell.textFont,
                                                  tm.Text, tableView.Bounds.Width - BaseChatCell.ImageGap * 3f - BaseChatCell.ImageDisplaySize));
            }
            else if (item is ImageMessage)
            {
                return(BaseChatCell.ImageGap + ChatImageCell.ImageCellHeight);
            }
            else if (item is LinkMessage)
            {
                var lm = item as LinkMessage;
                return(BaseChatCell.ImageGap + 20f +
                       BaseChatCell.HeightForFont(BaseChatCell.textFont,
                                                  lm.ExtractedContent, tableView.Bounds.Width - BaseChatCell.ImageGap * 3f
                                                  - BaseChatCell.ImageDisplaySize - ChatLinkCell.quoteBlockSize - ChatLinkCell.quoteBlockGap));
            }

            throw new Exception("The Chat Type is not supported");
        }
Ejemplo n.º 4
0
        public void ShowChatContent(ChatContent data)
        {
            string s = "";

            if (data.Sender == "" && data.Receiver == "")
            {
                s += "Server to " + ClientSite.Instance.User.UserName + ": " + data.Content;
            }
            else
            {
                if (data.Sender == "")
                {
                    s += "Server to " + data.Receiver + ": " + data.Content;
                }
                else if (data.Receiver == "")
                {
                    s += data.Sender + " to Server: " + data.Content;
                }
                else
                {
                    s = data.ToString();
                }
            }
            rtxbAllContent.Text += s + System.Environment.NewLine;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="destUserId"></param>
        public void Send(string content, int destUserId)
        {
            #region
            TcpClientEx tcpclient = ChatClient.ConnectServer();

            ChatContent contentobj = new ChatContent()
            {
                _FromUID = int.Parse(Logon._User.uid),
                _Text    = content,
                _ToUId   = destUserId
            };

            SendChatContent sendchatcontent = new SendChatContent()
            {
                _Content = contentobj
            };

            byte[] command = sendchatcontent.GetProtocolCommand();

            tcpclient.SendToEndDevice(command);

            //可接收是否发送成功

            /*
             * tcpclient.Receive();
             *
             * RecvUserCheckResult usercheckresult = new RecvUserCheckResult();
             *
             * tcpclient.Dispatcher(usercheckresult);
             */
            tcpclient.Close();

            #endregion
        }
Ejemplo n.º 6
0
        private void sendBtn_Click(object sender, EventArgs e)
        {
            string str = sendRichBox.Text;

            if (string.IsNullOrEmpty(str.Trim('\n').Trim('\t').Trim(' ')))
            {
                sendRichBox.Text = "";
                sendRichBox.Focus();
                MessageBox.Show("发送内容不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            DateTime    dt      = DateTime.Now;
            string      style   = null;
            string      content = ChatContent.GetStringByContent(str, fontDialog.Font, colorDialog.Color, dt, ref style);
            MessageType mt      = new MessageType(GlobalClass.CurrentUser.Id, DestUser.Id, content, 1);

            TCPUtil.socketSend.Send(mt.ToJsonBytes());
            recRichBox.AppendText(dt.ToString("yyyy-MM-dd HH:mm:ss") + " " + GlobalClass.CurrentUser.Name + "(" + GlobalClass.CurrentUser.Account + ")" + "\n");
            recRichBox.SelectionFont  = fontDialog.Font;
            recRichBox.SelectionColor = colorDialog.Color;
            recRichBox.AppendText(str + "\n");
            FormatChatText();
            sendRichBox.Text = "";
            UserChatRecord ur = new UserChatRecord()
            {
                MyId    = GlobalClass.CurrentUser.Id,
                UserId  = DestUser.Id,
                Time    = dt,
                Content = str,
                Style   = style,
                Role    = 0
            };

            UserChatRecordManager.AddRecord(ur);
        }
Ejemplo n.º 7
0
        protected override void OnRequest()
        {
            base.OnRequest();

            ChatContent chatContent = getModel <ChatContent>();

            try
            {
                if (chatContent != null)
                {
                    UserinfoModel userModel = null;
                    using (Controller.Account controllerAccount = new Controller.Account())
                    {
                        userModel = controllerAccount.GetUserinfo(aid);
                        if (userModel == null)
                        {
                            throw new UnfulfilException(0, "未找到指定用户");
                        }
                    }

                    String sendUserName = userModel.userNickname;
                    new Controller.Message().AddMessage(chatContent.userid, chatContent.content, this.aid, Controller.Message.MESSAGE_STATUS.UNREACH, Controller.Message.MESSAGE_STYLE.INFORMATION, sendUserName, Controller.Message.MESSAGE_TYPE.CHAT);
                    WriteSuccess <string>("发送成功");
                }
                else
                {
                    WriteUnfulfil("");
                }
            }
            catch (Exception ex)
            {
                WriteException(ex);
            }
        }
Ejemplo n.º 8
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            ChatContent cc = new ChatContent();

            cc.ChatType  = 1;
            cc.SendIP    = this.MyIP;
            cc.Content   = txtSend.Text.Trim();
            cc.FontColor = this.MyColor.ToArgb().ToString();;
            JavaScriptSerializer js = new JavaScriptSerializer();
            string strCc            = js.Serialize(cc);

            List <byte> list = new List <byte>();
            byte        b    = 2;

            list.Add(b);
            byte[] bCc = Encoding.UTF8.GetBytes(strCc);
            list.AddRange(bCc);
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //s.Connect(FriendIP);

            IPEndPoint sendIP = new IPEndPoint(IPAddress.Parse(this.FriendIP), this.comPort);

            s.SendTo(list.ToArray(), sendIP);
            s.Close();
            FontSet(txtShow, txtSend.Text.Trim());
            txtShow.AppendText("我:" + txtSend.Text.Trim() + "\r\n");

            txtSend.Text = string.Empty;
        }
Ejemplo n.º 9
0
 public void Handle(string sourceUserID, int contractaID, byte[] info)
 {
     if (contractaID == 1)
     {
         ChatContent chat = ChatContent.Parser.ParseFrom(info);
         Program.serverEngine.BasicController.SendAll(1, chat);
     }
 }
Ejemplo n.º 10
0
 void Awake()
 {
     inst    = this;
     ChatLog = new List <SentMessage>();
     FindObjectOfType <Parser.Parser>().eventOnReceived += MessagesSent;
     FindObjectOfType <Parser.Parser>().eventOnRead     += MessagesSeen;
     FindObjectOfType <Parser.Parser>().eventOnTyping   += TypeForSeconds;
     // myGameObj.Prnt("Chat content is awake");
 }
Ejemplo n.º 11
0
        public override bool Analysis()
        {
            List <string> analysisinfor = base.Split(2);

            if (analysisinfor != null)
            {
                this._Content          = new ChatContent();
                this._Content._FromUID = int.Parse(analysisinfor[0]);
                this._Content._Text    = analysisinfor[1];
            }

            return(true);
        }
Ejemplo n.º 12
0
        public ChatPostEphemeralMessageRequest(string channelId, string userId, string text)
            : base(HttpMethod.Post, "api/chat.postEphemeral")
        {
            var content = new ChatContent
            {
                ChannelId    = channelId,
                UserId       = userId,
                Text         = text,
                Attachements = new MessageAttachments {
                    Pretext = "", Text = text
                }
            };

            SetJsonContent(content);
        }
Ejemplo n.º 13
0
 private void PushInStack(ChatContent obj)
 {
     try
     {
         stackInput.Push(obj);
     }
     catch (Exception)
     {
         string error = "Error function PushInStack in Class " + ToString();
         Logger.Write(error);
     }
     if (readData.ThreadState == System.Threading.ThreadState.Suspended)
     {
         readData.Resume();
     }
 }
        internal void SendChatContent(ChatContent data)
        {
            Thread tempThread = new Thread(() =>
            {
                foreach (ClientConnecting item in listClients)
                {
                    //Check user
                    if (data.Receiver == "" || data.Sender == "" || data.Sender == item.User.UserName || data.Receiver == item.User.UserName)
                    {
                        item.SendChatContent(data);
                    }
                }
            });

            tempThread.Start();
        }
Ejemplo n.º 15
0
        public Task SendMessage(string message)
        {
            var         httpContext = Context.GetHttpContext();
            var         group       = httpContext.Request.Query["group"].ToString();
            string      name        = Context.User.Identity.Name;
            var         chat        = chatService.Get(group);
            ChatContent chatContent = new ChatContent()
            {
                DateTime = DateTime.Now,
                Message  = htmlEncoder.Encode(message),
                CreateTo = Context.User.Claims.ToList()[1].Value
            };

            chat.Content.Add(chatContent);
            chatService.Update(chat.Id, chat);
            return(Clients.Group(group).SendAsync("ReceiveMessage", name, htmlEncoder.Encode(message), chatContent.Id));
        }
Ejemplo n.º 16
0
 public void ProcessObject(Server.MyObject obj)
 {
     //if(obj is Server.Database.ChatContent)
     if (obj is Server.ChatContent)
     {
         ChatContent temp = obj as ChatContent;
         fChat       item = ListFormShow[0] as fChat;
         if ("" == temp.Receiver && temp.Sender == "")
         {
             temp.Receiver = User.UserName;
         }
         item.ShowChatContent(temp);
     }
     else if (obj is UserAccount)
     {
         RemoveOrAddUserOnline(obj as UserAccount);
     }
 }
Ejemplo n.º 17
0
        private void button1_Click(object sender, EventArgs e)
        {
            string msg = RtbSend.Text.Trim();

            if (string.IsNullOrEmpty(msg))
            {
                return;
            }
            ChatContent chat = new ChatContent()
            {
                Content = msg
            };

            clientEngine.BasicOutter.Send <ChatContent>(1, (chat1) => {
                this.RtbMsgList.AppendText(chat1.Content);
                this.RtbSend.Text = "";
            }, chat);
        }
Ejemplo n.º 18
0
        public static void SendFile(byte[] ext, byte[] sndfile)//TCP , SendPhoto
        {
            if (ready)
            {
                NetworkStream ns      = new NetworkStream(ClientSocket);
                byte[]        extsend = ext;
                ns.Write(ext, 0, ext.Length);
                ChatContent.Add("[" + name + "] 已發送副檔名.\n");

                byte[] buffer = sndfile;
                ns.Write(BitConverter.GetBytes(sndfile.Length), 0, 4);
                ns.Write(buffer, 0, buffer.Length);
                ChatContent.Add("[" + name + "] 已發送檔案.\n");
            }
            else
            {
                ChatContent.Add("[Error**]未連線\r\n");
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 点击好友聊天方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnFriendChat_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (btn.BackColor == Color.Gray)
            {
                return;
            }
            string str = (string)btn.Tag;
            //IPEndPoint chatIp = new IPEndPoint(IPAddress.Parse(str), 23333);

            // 判断集合里有没有此键,没有就创建一个,并发送一条请求通信消息 2协议
            FriendChat showForm = null;

            if (!dic.ContainsKey(str))
            {
                Socket      s    = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                byte        b    = 2;
                List <byte> list = new List <byte>();
                list.Add(b);

                // 初始化聊天对象
                JavaScriptSerializer js = new JavaScriptSerializer();
                ChatContent          cc = new ChatContent();
                cc.SendIP   = this.IP;
                cc.ChatType = 0;
                cc.Content  = string.Empty;
                string strCc = js.Serialize(cc);
                list.AddRange(Encoding.UTF8.GetBytes(strCc));

                IPEndPoint lastComIP = new IPEndPoint(IPAddress.Parse(str), 23333);
                // 向对方请求通信
                s.SendTo(list.ToArray(), lastComIP);
                showForm = new FriendChat(str, this.IP);
                dic.Add(str, showForm);
            }
            else
            {
                showForm = dic[str];
            }
            showForm.Show();
        }
Ejemplo n.º 20
0
 private void ShowMessage()
 {
     stackInput.Clear();
     while (true)
     {
         if (stackInput.Count < 1)
         {
             readData.Suspend();
         }
         else
         {
             ChatContent temp = stackInput.Pop();
             if (temp.Receiver == "" || temp.Receiver == null)
             {
                 ShowChat(temp);
             }
             SendChatContent(temp);
         }
     }
 }
Ejemplo n.º 21
0
        public override void OnReceive(int subCode, object value)
        {
            switch (subCode)
            {
            case ChatCode.SRES:
                ChatDto dto      = value as ChatDto;
                int     userId   = dto.userId;
                int     chatType = dto.chatType;
                string  text     = ChatContent.GetText(chatType);

                msg.userId   = userId;
                msg.chatType = chatType;
                msg.text     = text;
                Dispatch(AreaCode.UI, UIEvent.PLAYER_CHAT, msg);
                Dispatch(AreaCode.AUDIO, AudioEvent.PLAY_EFFECT_AUDIO, "Chat/Chat_" + chatType);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 22
0
 public void InitChatText(List <MessageType> list)
 {
     foreach (MessageType mt in list)
     {
         string      style = null;
         ChatContent cc    = ChatContent.GetChatContentByStr(mt.Content, ref style);
         recRichBox.AppendText(cc.Time.ToString("yyyy-MM-dd HH:mm:ss") + " " + DestUser.Name + "(" + DestUser.Account + ")" + "\n");
         recRichBox.SelectionColor = cc.Color;
         recRichBox.SelectionFont  = new Font(cc.FontFamily, cc.Size, cc.FontStyle);
         recRichBox.AppendText(cc.Content + "\n");
         FormatChatText();
         UserChatRecord ur = new UserChatRecord()
         {
             MyId    = GlobalClass.CurrentUser.Id,
             UserId  = DestUser.Id,
             Time    = cc.Time,
             Content = cc.Content,
             Style   = style,
             Role    = 1
         };
         UserChatRecordManager.AddRecord(ur);
     }
 }
Ejemplo n.º 23
0
        public void ReceiveMsg(string str)
        {
            string style = null;

            recRichBox.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + DestUser.Name + "(" + DestUser.Account + ")" + "\n");
            ChatContent cc = ChatContent.GetChatContentByStr(str, ref style);

            recRichBox.SelectionColor = cc.Color;
            recRichBox.SelectionFont  = new Font(cc.FontFamily, cc.Size, cc.FontStyle);
            recRichBox.AppendText(cc.Content + "\n");
            FormatChatText();
            UserChatRecord ur = new UserChatRecord()
            {
                MyId    = GlobalClass.CurrentUser.Id,
                UserId  = DestUser.Id,
                Time    = cc.Time,
                Content = cc.Content,
                Style   = style,
                Role    = 1
            };

            UserChatRecordManager.AddRecord(ur);
        }
Ejemplo n.º 24
0
 public static int Connect(byte[] sendname, string ip)//TCP
 {
     try
     {
         if (!ready)
         {
             if (LoopConnect(ip) == ClientStatus.Connected)
             {
                 ready = true;
             }
             else
             {
                 return(-1);
             }
         }
         ClientSocket.Send(sendname);
         ChatContent.Add("[" + name + "] 已與伺服器連線\r\n");
         return(1);
     }
     catch
     {
         return(-1);
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// 窗体抖动方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picJitter_Click(object sender, EventArgs e)
        {
            ChatContent cc = new ChatContent();

            cc.ChatType = 2;
            cc.SendIP   = this.MyIP;
            cc.Content  = string.Empty;
            JavaScriptSerializer js = new JavaScriptSerializer();
            string strCc            = js.Serialize(cc);

            List <byte> list = new List <byte>();
            byte        b    = 2;

            list.Add(b);
            byte[] bCc = Encoding.UTF8.GetBytes(strCc);
            list.AddRange(bCc);
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //s.Connect(FriendIP);

            IPEndPoint sendIP = new IPEndPoint(IPAddress.Parse(this.FriendIP), this.comPort);

            s.SendTo(list.ToArray(), sendIP);
            s.Close();
        }
Ejemplo n.º 26
0
        private async Task<Dictionary<int, ChatContent>> PerformAddContent(int roomid, int userid, string content, SqlConnection sql)
        {
            Dictionary<int, ChatContent> retVal = new Dictionary<int, ChatContent>();

            var command = sql.CreateCommand();
            // the joins on the initial insert statement guarantee the statement won't execute if the person isn't actually in the room.
            command.CommandText = "insert into chat.content (personid, roomid, text) select p.personid, r.roomid, @t from chat.person p inner join chat.personroomjoin j on p.personid = j.personid inner join chat.room r on j.roomid = r.roomid where r.roomid=@r and p.personid=@p; select contentid, r.roomid, name, text, timestamp from chat.room r inner join chat.content c on r.roomid = c.roomid inner join chat.person p on p.personid = c.personid where contentid = SCOPE_IDENTITY();";
            command.Parameters.AddWithValue("@r", roomid);
            command.Parameters.AddWithValue("@p", userid);
            command.Parameters.AddWithValue("@t", content);

            using(var reader = await command.ExecuteReaderAsync())
            {
                while(await reader.ReadAsync())
                {
                    var entry = new ChatContent() { ContentID = reader.GetInt32(0), RoomID = reader.GetInt32(1), Name = reader.GetString(2), Text = reader.GetString(3), Timestamp = reader.GetDateTime(4) };
                    retVal.Add(entry.ContentID, entry);
                }
            }

            if (retVal.Count > 0)
                publish(retVal, "chat.content." + roomid);

            return retVal;
        }
Ejemplo n.º 27
0
 private async Task<Dictionary<int, ChatContent>> GetRecentRoomContent(int roomid, SqlConnection sql)
 {
     Dictionary<int, ChatContent> retVal = new Dictionary<int, ChatContent>();
     var command = sql.CreateCommand();
     command.CommandText = "select top(100) contentid, r.roomid, name, text, timestamp from chat.room r inner join chat.content c on r.roomid = c.roomid inner join chat.person p on p.personid = c.personid where r.roomid = @r order by contentid desc;";
     command.Parameters.AddWithValue("@r", roomid);
     using(var reader = await command.ExecuteReaderAsync())
     {
         while(await reader.ReadAsync())
         {
             var entry = new ChatContent() { ContentID = reader.GetInt32(0), RoomID = reader.GetInt32(1), Name = reader.GetString(2), Text = reader.GetString(3), Timestamp = reader.GetDateTime(4) };
             retVal.Add(entry.ContentID, entry);
         }
     }
     return retVal;
 }
Ejemplo n.º 28
0
        private static void ReceiveLoop()
        {
            _master.Clear();
            _read.Clear();
            _master.Add(ClientSocket);
            _master.Add(uc.Client);
            while (true)
            {
                _read = new ArrayList(_master);
                try
                {
                    Socket.Select(_read, null, null, 1000);
                    for (int i = 0; i < _read.Count; i++)
                    {
                        if (_read[i] == uc.Client)
                        {
                            byte[] recbyte = uc.Receive(ref ipep_c);
                            string textrec = Encoding.Default.GetString(recbyte);
                            ChatContent.Add(textrec);
                        }
                        else
                        {
                            if (ready)
                            {
                                try
                                {
                                    NetworkStream ns      = new NetworkStream(ClientSocket);
                                    byte[]        extbuf  = new byte[3];
                                    byte[]        sizebuf = new byte[4];

                                    if (!alreadyrecving)
                                    {
                                        ReadAllData(ns, extbuf);
                                        string extension = Encoding.Default.GetString(extbuf);
                                        ReadAllData(ns, sizebuf);//1st get size

                                        int    count = BitConverter.ToInt32(sizebuf, 0);
                                        byte[] getf  = new byte[count];
                                        ReadAllData(ns, getf);
                                        switch (extension)
                                        {
                                        case "jpg":
                                            pictureExtension = extension;
                                            CurrentPicture   = getf;
                                            ChatContent.Add("[" + Name + "] 收到" + extension + "圖片, Size = " + getf.Length + "\n");
                                            break;

                                        case "png":
                                            pictureExtension = extension;
                                            CurrentPicture   = getf;
                                            ChatContent.Add("[" + Name + "] 收到" + extension + "圖片, Size = " + getf.Length + "\n");
                                            break;

                                        case "bmp":
                                            pictureExtension = extension;
                                            CurrentPicture   = getf;
                                            ChatContent.Add("[" + Name + "] 收到" + extension + "圖片, Size = " + getf.Length + "\n");
                                            break;

                                        case "gif":
                                            pictureExtension = extension;
                                            CurrentPicture   = getf;
                                            ChatContent.Add("[" + Name + "] 收到" + extension + "圖片, Size = " + getf.Length + "\n");
                                            break;

                                        default:
                                            fileExtension = extension;
                                            CurrentFile   = getf;
                                            ChatContent.Add("[" + Name + "] 收到" + extension + "檔案, Size = " + getf.Length + "\n");
                                            break;
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }//while
        }
Ejemplo n.º 29
0
 internal void SendChatContent(ChatContent data)
 {
     clientDataTrans.SendData(new MyTransportObject(data));
 }
Ejemplo n.º 30
0
        /// <summary>
        /// 接收消息方法
        /// </summary>
        private void Receive()
        {
            try
            {
                // 用来存储获得的数据
                byte[] receiveBytes = new byte[1024 * 1024];


                // 用来存放接受数据的ip改变情况
                EndPoint p = new IPEndPoint(IPAddress.Any, 23333);

                // 不停地循环监听收到的消息
                while (true)
                {
                    int i = listenSocket.ReceiveFrom(receiveBytes, ref p);
                    if (receiveBytes[0] == 2)// 2代表请求通信,接收定义好的端口好,new出窗体对象,并隐藏
                    {
                        // 反序列化
                        string content = Encoding.UTF8.GetString(receiveBytes, 1, i - 1);
                        JavaScriptSerializer javass = new JavaScriptSerializer();
                        ChatContent          cc     = javass.Deserialize <ChatContent>(content);

                        if (cc.ChatType == 0)
                        {
                            sp.SoundLocation = @"../../voices/system.wav";
                            sp.Play();
                            if (!dic.ContainsKey(cc.SendIP))
                            {
                                FriendChat fc = new FriendChat(cc.SendIP, this.IP);
                                fc.Hide();
                                dic.Add(cc.SendIP, fc);
                            }
                        }

                        // 如果不可见,就不进行操作,防止线程问题
                        if (!dic[cc.SendIP].Visible)
                        {
                            continue;
                        }

                        if (cc.ChatType == 1)       // 发的文字
                        {
                            sp.SoundLocation = @"../../voices/msg.wav";
                            sp.Play();
                            FontSet(dic[cc.SendIP].rtbShow, cc.Content, Color.FromArgb(Convert.ToInt32(cc.FontColor)));

                            dic[cc.SendIP].rtbShow.AppendText(cc.SendIP + ":" + cc.Content + "\r\n");
                        }
                        else if (cc.ChatType == 2)  // 发的窗口抖动
                        {
                            for (int j = 0; j < 200; j++)
                            {
                                dic[cc.SendIP].Left += 30;
                                dic[cc.SendIP].Top  += 30;
                                dic[cc.SendIP].Left -= 30;
                                dic[cc.SendIP].Top  -= 30;
                            }
                        }

                        continue;
                    }



                    // 解析数据,获得IP,IP是自己的则跳出执行下一个循环
                    JavaScriptSerializer jss = new JavaScriptSerializer();
                    Friend   fri             = jss.Deserialize <Friend>(Encoding.UTF8.GetString(receiveBytes, 1, i - 1));
                    EndPoint requestIP       = new IPEndPoint(IPAddress.Parse(fri.IP), 23333);
                    if (fri.IP == this.IP)
                    {
                        continue;
                    }
                    // 判断发过来的消息是要干嘛
                    if (receiveBytes[0] == 0) // 0代表找好友,返回个人信息,并返回1协议
                    {
                        // 播放声音提醒好友上线
                        sp.SoundLocation = @"../../voices/Global.wav";
                        sp.Play();

                        // 在集合中添加此在线用户
                        onlineList.Add(fri);
                        // 调用下面的分析方法
                        Arrange(receiveBytes, i);

                        List <byte> list = new List <byte>();
                        // 使用协议1
                        byte b = 1;
                        list.Add(b);
                        //list.AddRange(Encoding.UTF8.GetBytes(ip));
                        // 将此机器的IP地址发送给所有机器


                        //使用Json来序列化自己的信息
                        Friend f = new Friend();
                        f.IP        = this.IP;
                        f.Name      = this.MyName;
                        f.Photo     = this.MyPhoto;
                        f.Signature = this.Signature;
                        JavaScriptSerializer js = new JavaScriptSerializer();
                        string strF             = js.Serialize(f);
                        list.AddRange(Encoding.UTF8.GetBytes(strF));

                        listenSocket.SendTo(list.ToArray(), requestIP);
                    }
                    else if (receiveBytes[0] == 1) // 1代表返回了好友信息,接收不再发广播
                    {
                        // 播放声音提醒好友上线
                        sp.SoundLocation = @"../../voices/Global.wav";
                        sp.Play();

                        onlineList.Add(fri);
                        Arrange(receiveBytes, i);
                    }
                    else if (receiveBytes[0] == 6)// 6表示此用户已下线
                    {
                        onlineList.Remove(fri);
                        UpdateFriendState(fri, false);
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 31
0
 public Task DeleteAsync(ChatContent parameters)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
 public HashSet <string> DeleteValidation(ChatContent parameters)
 {
     return(ValidationMessages);
 }