Beispiel #1
0
        private void GroupChatting_Btn_Click(object sender, RoutedEventArgs e)
        {
            if (client == null)
            {
                MessageBox.Show("먼저 로그인해주세요.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            string getUserProtocol = myName + "<GiveMeUserList>";

            byte[] byteData = new byte[getUserProtocol.Length];
            byteData = Encoding.Default.GetBytes(getUserProtocol);

            client.GetStream().Write(byteData, 0, byteData.Length);

            UserListWindow userListWindow = new UserListWindow(StaticDefine.GROUP_CHATTING);

            if (userListWindow.ShowDialog() == true)
            {
                string groupChattingUserStrData = MainWindow.myName;
                foreach (var item in userListWindow.GroupChattingReceivers)
                {
                    groupChattingUserStrData += "#";
                    groupChattingUserStrData += item.userName;
                }


                string chattingStartMessage = string.Format("{0}<GroupChattingStart>", groupChattingUserStrData);
                byte[] chattingStartByte    = Encoding.Default.GetBytes(chattingStartMessage);

                client.GetStream().Write(chattingStartByte, 0, chattingStartByte.Length);
            }
        }
Beispiel #2
0
        private void OneOnOneChatting_Btn_Click(object sender, RoutedEventArgs e)
        {
            if (client == null)
            {
                MessageBox.Show("먼저 로그인해주세요.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }


            string getUserProtocol = myName + "<GiveMeUserList>";

            byte[] byteData = new byte[getUserProtocol.Length];
            byteData = Encoding.Default.GetBytes(getUserProtocol);

            client.GetStream().Write(byteData, 0, byteData.Length);

            UserListWindow userListWindow = new UserListWindow(StaticDefine.ONE_ON_ONE_CHATTING);

            if (userListWindow.ShowDialog() == true)
            {
                if (chattingThreadDic.ContainsKey(userListWindow.OneOnOneReceiver))
                {
                    MessageBox.Show("해당유저와는 이미 채팅중입니다.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                string chattingStartMessage = string.Format("{0}<ChattingStart>", userListWindow.OneOnOneReceiver);
                byte[] chattingStartByte    = Encoding.Default.GetBytes(chattingStartMessage);

                client.GetStream().Write(chattingStartByte, 0, chattingStartByte.Length);
            }
        }
Beispiel #3
0
        private void ParsingReceiveMessage(List <string> messageList)
        {
            foreach (var item in messageList)
            {
                string chattingPartner = "";
                string message         = "";

                if (item.Contains('<'))
                {
                    string[] splitedMsg = item.Split('<');

                    chattingPartner = splitedMsg[0];
                    message         = splitedMsg[1];

                    // 하트비트
                    if (chattingPartner == "관리자")
                    {
                        ObservableCollection <User> tempUserList = new ObservableCollection <User>();
                        string[] splitedUser = message.Split('$');
                        foreach (var el in splitedUser)
                        {
                            if (string.IsNullOrEmpty(el))
                            {
                                continue;
                            }
                            tempUserList.Add(new User(el));
                        }
                        UserListWindow.ChangeUserListView(tempUserList);
                        messageList.Clear();
                        return;
                    }

                    // 그룹채팅
                    else if (chattingPartner.Contains("#"))
                    {
                        string[]      splitedChattingPartner = chattingPartner.Split('#');
                        List <string> chattingPartners       = new List <string>();

                        foreach (var el in splitedChattingPartner)
                        {
                            if (string.IsNullOrEmpty(el))
                            {
                                continue;
                            }
                            chattingPartners.Add(el);
                        }

                        string sender = chattingPartners[0];

                        int chattingRoomNum = GetChattingRoomNum(chattingPartners);

                        if (chattingRoomNum < 0)
                        {
                            Thread groupChattingThread = new Thread(() => ThreadStartingPoint(chattingPartners));
                            groupChattingThread.SetApartmentState(ApartmentState.STA);
                            groupChattingThread.IsBackground = true;
                            groupChattingThread.Start();
                        }
                        else
                        {
                            if (groupChattingThreadDic[chattingRoomNum].chattingThread.IsAlive)
                            {
                                groupChattingThreadDic[chattingRoomNum].chattingWindow.ReceiveMessage(sender, message);
                            }
                        }
                        messageList.Clear();
                        return;
                    }

                    // 1:1채팅
                    else
                    {
                        if (!chattingThreadDic.ContainsKey(chattingPartner))
                        {
                            if (message == "ChattingStart")
                            {
                                Thread chattingThread = new Thread(() => ThreadStartingPoint(chattingPartner));
                                chattingThread.SetApartmentState(ApartmentState.STA);
                                chattingThread.IsBackground = true;
                                chattingThread.Start();
                            }
                        }
                        else
                        {
                            if (chattingThreadDic[chattingPartner].chattingThread.IsAlive)
                            {
                                chattingThreadDic[chattingPartner].chattingWindow.ReceiveMessage(chattingPartner, message);
                            }
                        }
                        messageList.Clear();
                        return;
                    }
                }
            }
            messageList.Clear();
        }