public void OpenMessageRoom(ChatRoom room) { Form openForm = BlindChatUtil.GetFormWithName(room.ID.ToString()); if (openForm != null) { ExecuteWithInvoke(openForm, delegate { if (openForm.WindowState == FormWindowState.Minimized) { openForm.WindowState = FormWindowState.Normal; openForm.Location = new Point(openForm.Location.X + openForm.Width, openForm.Location.Y); } openForm.Activate(); }); } else { Task tMessageRoom = new Task(() => { MessageRoom messageRoom = new MessageRoom(_UserID, room, GetMessageList(room.ID)); messageRoom.SendChatMessage = ChatMessageSend; messageRoom.Location = new Point(form.Location.X + form.Width, form.Location.Y); Application.Run(messageRoom); }); tMessageRoom.Start(); } }
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(); }); }
public void ChatMessageSend(string text, uint userID, int roomID) { ChatMessage message = new ChatMessage(); message.Message = text; message.UserID = userID; message.RoomID = roomID; ChatPacketSend(BlindChatUtil.StructToChatPacket(message)); }
public void CreateRoom(string text, uint[] users) { //한 방에는 최대 20명 NewRoomStruct newRoom = new NewRoomStruct(); newRoom.Name = text; newRoom.UserID = users; ChatPacketSend(BlindChatUtil.StructToChatPacket(newRoom)); }
public void AddMessage(ChatMessage message) { string sql = $"insert into ChatMessage (message, userID, roomID, time) values (\'{message.Message}\', {message.UserID}, {message.RoomID}, \'{message.Time}\');"; DB.ExecuteNonQuery(sql); sql = $"update ChatRoom set LastMessageTime = \'{message.Time}\' where ID={message.RoomID}"; DB.ExecuteNonQuery(sql); foreach (ChatRoom a in BlindChat.roomList) { if (a.ID == message.RoomID) { ChatRoom tmpRoom = a; tmpRoom.LastMessageTime = message.Time; BlindChat.roomList[roomList.IndexOf(a)] = tmpRoom; break; } } ExecuteWithInvoke(this.form, delegate { //UI._RoomControl.LoadRooms(); foreach (Room_Item item in UI._RoomControl.RoomItem_LayoutPanel.Controls) { if (item.ID == message.RoomID) { DateTime time = DateTime.Parse(message.Time); item.Time = time.ToString("tt hh:mm"); UI._RoomControl.RoomItem_LayoutPanel.Controls.SetChildIndex((Control)item, 0); UI._RoomControl.RoomItem_LayoutPanel.Invalidate(); } } }); MessageRoom form = BlindChatUtil.GetFormWithName(message.RoomID.ToString()) as MessageRoom; if (form != null) { ExecuteWithInvoke(form, delegate { form.AddMessage(message); }); } }
public static void InviteUser(uint userID, int roomID) { ChatRoomJoined roomJoined = new ChatRoomJoined(); roomJoined.UserID = userID; roomJoined.RoomID = roomID; ChatPacketSend(BlindChatUtil.StructToChatPacket(roomJoined)); //Invitation inv = new Invitation(); //inv.Name = roomName; //inv.RoomID = roomID; //inv.UserID = userID; //ChatPacketSend(BlindChatUtil.StructToChatPacket(inv)); }
public static void ExitRoom(uint userID, int roomID) { ChatRoomJoined roomJoined = new ChatRoomJoined(); roomJoined.UserID = userID; roomJoined.RoomID = roomID; roomJoined.Time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ChatPacketSend(BlindChatUtil.StructToChatPacket(roomJoined, ChatType.Exit)); Form form = BlindChatUtil.GetFormWithName(roomJoined.RoomID.ToString()); if (form != null) { form.Close(); } }
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 { } } }
public static ChatPacket StructToChatPacket(ChatTimeStamp time) { byte[] data = BlindNetUtil.StructToByte(time); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Time)); }
public static ChatPacket StructToChatPacket(ChatMessage message) { byte[] data = BlindNetUtil.StructToByte(message); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Message)); }
public static ChatPacket StructToChatPacket(ChatRoomJoined roomJoined, ChatType type = ChatType.RoomJoined) { byte[] data = BlindNetUtil.StructToByte(roomJoined); return(BlindChatUtil.ByteToChatPacket(data, type)); }
public static ChatPacket StructToChatPacket(ChatRoom room) { byte[] data = BlindNetUtil.StructToByte(room); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Room)); }
public static ChatPacket StructToChatPacket(User user) { byte[] data = BlindNetUtil.StructToByte(user); return(BlindChatUtil.ByteToChatPacket(data, ChatType.User)); }
public static ChatPacket StructToChatPacket(NewRoomStruct newRoom) { byte[] data = BlindNetUtil.StructToByte(newRoom); return(BlindChatUtil.ByteToChatPacket(data, ChatType.NewRoom)); }
public static ChatPacket StructToChatPacket(Invitation inv) { byte[] data = BlindNetUtil.StructToByte(inv); return(BlindChatUtil.ByteToChatPacket(data, ChatType.Invitation)); }