// 그림 맞추기방 버튼 private void OpenPaintGame(object sender, EventArgs e) { if (ClientList.CheckedItems.Count == 0) { MsgBoxHelper.Error("사용자를 선택해주세요."); return; } for (int i = ClientList.CheckedItems.Count - 1; i >= 0; i--) { if (Nick_label.Text.Equals(ClientList.CheckedItems[i].ToString())) { MsgBoxHelper.Error("본인을 제외한 사용자를 선택해주세요."); return; } } pg = new Paint_Game(this, Nick_label.Text); pg.Show(); }
// 데이터 수신 함수 void DataReceived(IAsyncResult ar) { AsyncObject obj = (AsyncObject)ar.AsyncState; string text = Encoding.UTF8.GetString(obj.Buffer); string[] arrDts = text.Split('\x01'); this.Invoke(new MethodInvoker(delegate() { if (arrDts[0] == "1") // 전체 채팅 { AppendText(txtHistory, string.Format("[받음]{0}: {1}", arrDts[1], arrDts[2])); } else if (arrDts[0] == "2") // 그림방 채팅 { foreach (Form OpenForm in Application.OpenForms) { if (OpenForm.Text == "Drawing Catch ( " + crenick + " )") { pg.recvChat = text; return; } } pg = new Paint_Game(this, Nick_label.Text); recvDt = text; pg.Show(); } else if (arrDts[0] == "3") // 그림 받기 { int cnt = int.Parse(arrDts[3]); foreach (Form OpenForm in Application.OpenForms) { if (OpenForm.Text == "Drawing Catch ( " + crenick + " )") { Byte[] Img = Convert.FromBase64String(arrDts[2]); TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); Bitmap Imgbit = (Bitmap)tc.ConvertFrom(Img); pg.recvPicture = Imgbit; return; } } pg = new Paint_Game(this, Nick_label.Text); pg.Show(); } else if (arrDts[0] == "4")// ******************************************************************************************배열 1씩 더하ㅡㄴ중 { int cnt = int.Parse(arrDts[4]); foreach (Form OpenForm in Application.OpenForms) { if (OpenForm.Text == "Drawing Catch ( " + crenick + " )") { if (arrDts[5] == "1" || arrDts[5] == "2") { pg.recvState = text; return; } else { pg.recvStart = text; return; } } } pg = new Paint_Game(this, Nick_label.Text); recvDt = text; pg.Show(); } else if (arrDts[0] == "5") { int cnt = int.Parse(arrDts[5]); foreach (Form OpenForm in Application.OpenForms) { if (OpenForm.Text == "Drawing Catch ( " + crenick + " )") { pg.recvCollect = text; return; } } pg = new Paint_Game(this, mainSock.LocalEndPoint.ToString()); recvDt = text; pg.Show(); } else if (arrDts[0] == "6") { int cnt = int.Parse(arrDts[5]); foreach (Form OpenForm in Application.OpenForms) { if (OpenForm.Text == "Drawing Catch ( " + crenick + " )") { pg.recvEnd = text; return; } } pg = new Paint_Game(this, Nick_label.Text); recvDt = text; pg.Show(); } else if (arrDts[0] == "7") { if (arrDts[1] == "1") { MessageBox.Show("사용 가능한 닉네임입니다!"); button2.Enabled = false; } else { MessageBox.Show("이미 사용중인 닉네임입니다!"); } } else if (arrDts[0] == "8") // 참여 { ClientList.Items.Clear(); for (int i = 2; i < arrDts.Length - 1; i++) { ClientList.Items.Add(arrDts[i]); } AppendText(txtHistory, string.Format("{0}", arrDts[1])); } else if (arrDts[0] == "9") // 퇴장 { ClientList.Items.Clear(); for (int i = 2; i < arrDts.Length - 1; i++) { ClientList.Items.Add(arrDts[i]); } AppendText(txtHistory, string.Format("{0}", arrDts[1])); } else if (arrDts[0] == "0") // 서버 종료 { mainSock.Disconnect(true); ClientList.Items.Clear(); AppendText(txtHistory, string.Format("서버와의 연결이 종료되었습니다.")); ServerConnected = false; obj.ClearBuffer(); mainSock.Close(); mainSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); return; } })); obj.ClearBuffer(); obj.WorkingSocket.BeginReceive(obj.Buffer, 0, 50000, 0, DataReceived, obj); }