private void cmdEnterRoom(byte[] packet, int size_packet) { string id = Encoding.UTF8.GetString(packet, Macro.SIZE_HEADER, Macro.SIZE_ID); int idx = Macro.SIZE_HEADER + Macro.SIZE_ID; int room_number = BitConverter.ToInt32(packet, idx); byte status = packet[idx + 4]; string room_subject = Encoding.UTF8.GetString(packet, idx + 4 + 1, Macro.SIZE_ROOM_SUBJECT); byte[] key = new byte[Macro.SIZE_SECRET_KEY]; Array.Copy(packet, idx + 4 + 1 + Macro.SIZE_ROOM_SUBJECT, key, 0, Macro.SIZE_SECRET_KEY); int count_member = BitConverter.ToInt32(packet, idx + 4 + 1 + Macro.SIZE_ROOM_SUBJECT + Macro.SIZE_SECRET_KEY); string chat = ""; if (id == UserData.ud.id) { UserData.ud.addMyRoom(room_number, status, room_subject, key, chat, count_member); } else { MyRoom room = UserData.ud.findMyRoom(room_number); if (room != null) { room.Count_member++; } } MyRoom r = UserData.ud.findMyRoom(room_number); r.bCreateRoom = true; sendViewRoom(room_number); }
public void sendChattingMessage(MyRoom my_room, string message) { byte[] buffer = new byte[Macro.SIZE_BUFFER]; int idx_buffer = 0; // send valueToPacket(buffer, idx_buffer, Macro.CMD_CHATTING_MESSAGE, Macro.SIZE_CMD); idx_buffer = Macro.SIZE_HEADER; // id idx_buffer = stringToPacket(buffer, idx_buffer, UserData.ud.id, Macro.SIZE_ID); // room number idx_buffer = valueToPacket(buffer, idx_buffer, my_room.room_number, 4); // message if (my_room.Status == Macro.ROOM_INFO_STATUS_NORMAL) { idx_buffer = stringToPacket(buffer, idx_buffer, message, Encoding.UTF8.GetByteCount(message)); } else if (my_room.Status == Macro.ROOM_INFO_STATUS_SECRET) { idx_buffer = stringToCypherPacket(buffer, idx_buffer, message, my_room.secret_key); } // length valueToPacket(buffer, Macro.SIZE_CMD, idx_buffer, Macro.SIZE_PACKET_LENGTH); sendBuffer(buffer, 0, idx_buffer); }
public WindowChatting(MyRoom _my_room) { InitializeComponent(); // this.Owner = WindowRoomList.wnd; my_room = _my_room; textBlock_chat.Text = ""; textBlock_chat.Text += my_room.Log_chatting.ToString(); textBox_input.Focus(); textBox_input.KeyDown += TextBox_input_KeyDown; my_room.wnd = this; this.Loaded += WindowChatting_Loaded; this.Closed += WindowChatting_Closed; button_invite.Click += Button_invite_Click; this.KeyDown += WindowChatting_KeyDown; this.MouseLeftButtonDown += WindowChatting_MouseLeftButtonDown; this.PreviewMouseLeftButtonDown += WindowChatting_PreviewMouseLeftButtonDown; this.MouseLeftButtonUp += WindowChatting_MouseLeftButtonUp; my_room.grd.Children.OfType <Button>().FirstOrDefault().Background = Brushes.White; if (my_room.notice != null) { my_room.notice.Close(); } }
public int delMyRoom(int room_number) { if (!UserData.ud.dic_my_rooms.ContainsKey(room_number)) { return(-1); } MyRoom my_room = UserData.ud.dic_my_rooms[room_number]; if (my_room != null) { if (my_room.Count_member <= 1) { delTotalRoom(room_number); } if (my_room.wnd != null) { my_room.wnd.Close(); } WindowRoomList.wnd.delButtonMyList(my_room.grd); UserData.ud.dic_my_rooms.Remove(room_number); return(0); } return(-1); }
private void cmdViewRoom(byte[] packet, int size_packet) { int room_number = BitConverter.ToInt32(packet, Macro.SIZE_HEADER + Macro.SIZE_ID); MyRoom my_room = UserData.ud.findMyRoom(room_number); if (my_room == null) { return; } if (my_room.wnd != null) { my_room.wnd.Focus(); return; } /* cmdMyRoomList 와 cmdChattingMessage 로 업데이트를 하는데 굳이 chatting log 업데이트를 해야하나 * if (my_room.Status == Macro.ROOM_INFO_STATUS_SECRET) * { * byte[] buffer_plain = Rijndael.decrypt( * // packet * packet, * // offset * Macro.SIZE_HEADER + Macro.SIZE_ID + 4, * // size * size_packet - (Macro.SIZE_HEADER + Macro.SIZE_ID + 4), * // key * my_room.secret_key * ); * * if (buffer_plain != null) * { * my_room.setLogChatting( * // log chatting * Encoding.UTF8.GetString(buffer_plain, 0, buffer_plain.Length) * ); * } * } * else * { * my_room.setLogChatting( * // log chatting * Encoding.UTF8.GetString( * // packet * packet, * // offset * Macro.SIZE_HEADER + Macro.SIZE_ID + 4, * // size * size_packet - (Macro.SIZE_HEADER + Macro.SIZE_ID + 4)) * ); * } */ WindowChatting wnd = new WindowChatting(my_room); // wnd.Left = wnd.Show(); }
public Window_notice(MyRoom r) { InitializeComponent(); //this.Owner = WindowRoomList.wnd; this.Loaded += Window_notice_Loaded; this.MouseLeftButtonDown += Window_notice_MouseLeftButtonDown; this.Closed += Window_notice_Closed; room = r; delay_timer.Interval = TimeSpan.FromSeconds(2); delay_timer.Tick += Delay_timer_Tick; delay_timer.Start(); textBlock_roomNumber.Text = r.room_number.ToString(); textBlock_message.Text = r.Chatting_last_line.Substring(22); }
private void cmdLeaveRoom(byte[] packet, int size_packet) { string id = Encoding.UTF8.GetString(packet, Macro.SIZE_HEADER, Macro.SIZE_ID); int room_number = BitConverter.ToInt32(packet, Macro.SIZE_HEADER + Macro.SIZE_ID); if (id == UserData.ud.id) { UserData.ud.delMyRoom(room_number); } else { MyRoom room = UserData.ud.findMyRoom(room_number); if (room != null) { room.Count_member--; } } }
private void cmdChattingMessage(byte[] packet, int size_packet) { int room_number = BitConverter.ToInt32(packet, Macro.SIZE_HEADER + Macro.SIZE_ID); MyRoom my_room = UserData.ud.findMyRoom(room_number); if (my_room == null) { return; } if (my_room.Status == Macro.ROOM_INFO_STATUS_SECRET) { byte[] buffer_plain = Rijndael.decrypt( packet, Macro.SIZE_HEADER + Macro.SIZE_ID + 4, size_packet - (Macro.SIZE_HEADER + Macro.SIZE_ID + 4), my_room.secret_key ); if (buffer_plain != null) { my_room.addLogChatting( // message Encoding.UTF8.GetString(buffer_plain, 0, buffer_plain.Length) ); } } else if (my_room.Status == Macro.ROOM_INFO_STATUS_NORMAL) { my_room.addLogChatting( // message Encoding.UTF8.GetString( packet, Macro.SIZE_HEADER + Macro.SIZE_ID + 4, size_packet - (Macro.SIZE_HEADER + Macro.SIZE_ID + 4)) ); } if (my_room.wnd != null) { my_room.wnd.updateChat(); } }
private void cmdCreateRoom(byte[] packet, int size_packet) { int idx = Macro.SIZE_HEADER + Macro.SIZE_ID; int room_number = BitConverter.ToInt32(packet, idx); byte status = packet[idx + 4]; string subject = Encoding.UTF8.GetString(packet, idx + 4 + 1, Macro.SIZE_ROOM_SUBJECT); byte[] key = new byte[Macro.SIZE_SECRET_KEY]; Array.Copy(packet, idx + 4 + 1 + Macro.SIZE_ROOM_SUBJECT, key, 0, Macro.SIZE_SECRET_KEY); string chat = ""; if (status == Macro.ROOM_INFO_STATUS_NORMAL) { UserData.ud.addTotalRoom(room_number, status, subject, 1); } UserData.ud.addMyRoom(room_number, status, subject, key, chat, 1); MyRoom r = UserData.ud.findMyRoom(room_number); r.bCreateRoom = true; sendViewRoom(room_number); }