private void DataArrival(byte[] Data, IPAddress Ip, int Port) //当有数据到达后的处理进程 { Publec_Class Pub_class = new Publec_Class(); try { ClassMsg msg = new ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as ClassMsg; switch (msg.msgCommand) { case MsgCommand.Logined: //登录成功 Publec_Class.UserID = msg.SID; Publec_Class.Fraction = msg.Fraction; Publec_Class.UserSex = msg.Sex; Publec_Class.ClientIP = Pub_class.MyHostIP(); //获取当前计算机的IP地址 DialogResult = DialogResult.OK; udpSocket1.Active = false; this.Close(); break; } } catch { } }
private void DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) //当有数据到达后的处理进程 { try { ClassMsg msg = new ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as ClassMsg; switch (msg.msgCommand) { case MsgCommand.UserList: //进入大厅获取在线用户列表 { frmClient.Format_ListV(listView_user, imageList2); GetUserList(Data, Ip, Port); break; } case MsgCommand.Close: //退出大厅 { udpSocket1.Active = false; this.Close(); break; } case MsgCommand.ComeToHallH: { frmClient.Data_List(listView_user, msg.UserName, msg.Fraction.ToString(), msg.CPhoto.ToString()); break; } case MsgCommand.ExitToHall: { frmClient.ReMove_List(listView_user, msg.UserName); break; } case MsgCommand.BeginToGameL: { Frm_Chessboard FrmChessboard = new Frm_Chessboard(); if (FrmChessboard.ShowDialog() == DialogResult.OK) { //frmClient.Format_ListV(listView_user, imageList2); ClassMsg msg1 = new ClassMsg(); msg1.AreaMark = Publec_Class.TAreaM.ToString(); msg1.RoomMark = Publec_Class.TRoomM.ToString(); msg1.RIP = PubClass.MyHostIP(); msg1.RPort = Publec_Class.ServerPort; msg1.SIP = Publec_Class.ServerIP; msg1.SPort = "11000"; msg1.sendKind = SendKind.SendCommand; msg1.msgCommand = MsgCommand.ComeToHall; msg1.CPhoto = Publec_Class.CaputID; //发送消息 udpSocket1.Send(IPAddress.Parse(Publec_Class.ServerIP), 11000, new ClassSerializers().SerializeBinary(msg1).ToArray()); msg.sendKind = SendKind.SendCommand; msg.msgCommand = MsgCommand.EndToGame; udpSocket1.Send(IPAddress.Parse(Publec_Class.ServerIP), 11000, new ClassSerializers().SerializeBinary(msg).ToArray()); } break; } case MsgCommand.ExitToArea: { if (Convert.ToInt32(msg.AreaMark) == Publec_Class.TAreaM && Convert.ToInt32(msg.RoomMark) == Publec_Class.TRoomM) { frmClient.ReMove_List(listView_user, msg.UserName); } break; } case MsgCommand.BeginToGameH: { frmClient.AddDeskMsg(flowPanel_Oppose, msg, imageList1, Ip.ToString(), msg.msgCommand); break; } case MsgCommand.EndToGameH: { frmClient.AddDeskMsg(flowPanel_Oppose, msg, imageList1, Ip.ToString(), msg.msgCommand); PressGame = false; break; } case MsgCommand.EndRival: { frmClient.Game_TerraInfo(Data); break; } case MsgCommand.ComeToSay: { frmClient.AddMsgText(RTB_Dialog, msg, msg.msgCommand); break; } } } catch { } }