Ejemplo n.º 1
0
        public void ExecuteExit(ChatPacket packet)
        {
            ChatRoomJoined roomJoined = BlindChatUtil.ChatPacketToStruct <ChatRoomJoined>(packet);

            if (roomJoined.UserID == _UserID)
            {
                string sql = $"delete from ChatRoomJoined where RoomID = {roomJoined.RoomID};";
                DB.ExecuteNonQuery(sql);
                sql = $"delete from ChatRoom where ID = {roomJoined.RoomID};";
                DB.ExecuteNonQuery(sql);

                roomList.RemoveAt(roomList.FindIndex(x => x.ID == roomJoined.RoomID));
            }
            else
            {
                string sql = $"delete from ChatRoomJoined where UserID = {roomJoined.UserID} and RoomID = {roomJoined.RoomID}";
                DB.ExecuteNonQuery(sql);

                //ChatMessage message = new ChatMessage();
                //message.RoomID = roomJoined.RoomID;
                //message.UserID = 0;
                //message.Time = roomJoined.Time;

                //User user = BlindChat.userList.Find(x => x.ID == roomJoined.UserID);
                //message.Message = $"{user.Name}님이 나갔습니다.";

                //AddMessage(message);
            }


            ExecuteWithInvoke(form, delegate
            {
                UI._RoomControl.LoadRooms();
            });
        }
Ejemplo n.º 2
0
        public void Run()
        {
            ChatPacket    packet;
            ChatTimeStamp syncTime;

            User           user;
            ChatRoom       room;
            ChatRoomJoined roomJoined;
            ChatMessage    message;

            DB.Open();

            sendSock = new BlindSocket();
            sendSock.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.CHATPORT);

            recvSock = new BlindSocket();
            recvSock.ConnectWithECDH(BlindNetConst.ServerIP, BlindNetConst.CHATPORT + 1);


            syncTime = DB.GetAllTime();
            packet   = BlindChatUtil.StructToChatPacket(syncTime);
            ChatPacketSend(packet);


            //string sql;
            while (true)
            {
                packet = ChatPacketReceive();

                if (packet.Type == ChatType.User)
                {
                    //사용자 UI에 표시
                    user = BlindChatUtil.ChatPacketToStruct <User>(packet);
                    AddUser(user);
                }
                else if (packet.Type == ChatType.Room)
                {
                    //방추가 UI에 표시
                    room = BlindChatUtil.ChatPacketToStruct <ChatRoom>(packet);
                    AddRoom(room);
                }
                else if (packet.Type == ChatType.RoomJoined)
                {
                    //방인원 UI에 표시
                    roomJoined = BlindChatUtil.ChatPacketToStruct <ChatRoomJoined>(packet);
                    AddMember(roomJoined);
                }
                else if (packet.Type == ChatType.Message)
                {
                    //메시지 UI에 표시
                    message = BlindChatUtil.ChatPacketToStruct <ChatMessage>(packet);
                    AddMessage(message);
                }
                else if (packet.Type == ChatType.Reset)
                {
                    if (!Start)
                    {
                        LoadList();
                        LoadUI();
#if DEBUG
                        MessageBox.Show("데이터 로드 완료");
#endif
                    }
                    Start = true;
                }
                else if (packet.Type == ChatType.Exit)
                {
                    ExecuteExit(packet);
                }
                else
                {
                }
            }
        }