Exemplo n.º 1
0
        private void ReceiveMessages()
        {
            while (Connected)
            {
                // Show the messages in the log TextBox

                Resp = srReceiver.ReadLine();
                if (Resp == null)
                {
                    Connected = false;
                    OnConnectionChange();
                    break;
                }
                if (Resp.StartsWith("PING"))
                {
                    SendToServer("PONG");
                }

                if (Resp.StartsWith("FRIENDS"))
                {
                    Factory.FriendsMan.StartPopulate(Resp.Substring(8));
                }
                if (Resp.StartsWith("CHAT FROM"))
                {
                    String[] split = Resp.Split(' ');
                    Console.WriteLine("Incoming Chat from {0}", split[2]);
                    bool found = false;
                    if (Chats.Count != 0)
                    {
                        foreach (ChatWindow cw in Chats)
                        {
                            if (cw.User == split[2])
                            {
                                found = true;
                                string message = "";
                                for (int i = 3; i < split.Length; i++)
                                {
                                    message = message + split[i] + ' ';
                                }
                                Addline(cw, cw.User, message); // a function that adds a line to the current chat
                            }
                        }
                    }
                    if (!found)
                    {
                        ShowChatWindow(split[2], split[3]);
                    }
                }
            }
        }