void OnEnterMatchRsp(object msg, int app_type, int app_id) { bs.matchclient.EnterMatchRsp rsp = (bs.matchclient.EnterMatchRsp)msg; //记录下table_logic的app_id UserData.enter_match.table_logic_appid = (int)rsp.tablelogic_appid; //如果tableid不为0就是断线重连 if (rsp.table_id != 0) { UserData.enter_match.table_id = rsp.table_id; //向match_phase发送 bs.matchclient.BackGameReq back_req = new bs.matchclient.BackGameReq(); int back_app_type = (int)Middleware.EnumAppType.TableLogic; int back_app_id = UserData.enter_match.table_logic_appid; back_req.group_id = UserData.enter_match.group_id; back_req.match_id = UserData.enter_match.match_id; back_req.table_id = UserData.enter_match.table_id; Middleware.SendMessage <bs.matchclient.BackGameReq>(back_req, (int)Middleware.EnumCommandKind.MatchClient, (int)bs.matchclient.CMDID_MatchClient.IDBackGameReq, back_app_type, back_app_id); //向table_logic发送 //CMDGameddz_game_data_req game_data; bs.gameddz.game_data_req game_data = new bs.gameddz.game_data_req(); //CMDMatchClient_GameData data_rsp; bs.matchclient.GameData data_req = new bs.matchclient.GameData(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); Serializer.Serialize <bs.gameddz.game_data_req>(stream, game_data); byte[] buff = stream.ToArray(); data_req.data = buff; //game_data.my_message_.SerializeToString(&data); data_req.data = buff; data_req.data_id = (int)bs.gameddz.CMDID_Gameddz.IDGameDataReq; data_req.game_kind = UserData.the_game_kind; Middleware.SendMessage <bs.matchclient.GameData>(data_req, (int)Middleware.EnumCommandKind.MatchClient, (int)bs.matchclient.CMDID_MatchClient.IDGameData, back_app_type, back_app_id); return; } if (bs.matchclient.EnterMatchRsp.EnterResult.OK != rsp.result_code) { //进入比赛失败的处理 } SendPlayerActionReq(app_type, app_id); }
// Update is called once per frame void Update() { int kind_id = 0, sub_id = 0, app_type = 0, app_id = 0; object msg = Middleware.RecvMessage(ref kind_id, ref sub_id, ref app_type, ref app_id); if (msg == null) { return; } switch (kind_id) { case (int)Middleware.EnumCommandKind.Client: switch (sub_id) { case (int)bs.client.CMDID_Client.IDLoginRsp: //登录回复 { //bs.client.LoginRsp req = Serializer.Deserialize<bs.client.LoginRsp>(stream); bs.client.LoginRsp rsp = (bs.client.LoginRsp)msg; Debug.LogFormat("user_id={0}, result={1}", rsp.user_id, rsp.login_result); if (rsp.login_result == bs.client.LoginRsp.Result.SUCCESS) { UserData.user_id = rsp.user_id; show_text.GetComponent <Text>().text = "登录成功"; } } break; default: break; } break; case (int)Middleware.EnumCommandKind.HallClient: switch (sub_id) { case (int)bs.hallclient.CMDID_HallClient.IDAllGroupRsp: OnAllGroupRsp(msg, app_type, app_id); break; case (int)bs.hallclient.CMDID_HallClient.IDAllListRsp: OnAllListRsp(msg, app_type, app_id); break; case (int)bs.hallclient.CMDID_HallClient.IDAllPlanRsp: OnAllPlanRsp(msg, app_type, app_id); break; case (int)bs.hallclient.CMDID_HallClient.IDPlanAllStartPoint: OnAllStarPointRsp(msg, app_type, app_id); break; case (int)bs.hallclient.CMDID_HallClient.IDGetMatchDetailRsp: OnMatchDetailRsp(msg, app_type, app_id); break; default: break; } break; case (int)Middleware.EnumCommandKind.Gate: switch (sub_id) { case (int)bs.gate.CMDID_Gate.IDHelloRsp: // Debug.LogFormat("send loginreq"); // Middleware.status = 1; SendLoginReq(); break; default: break; } break; case (int)Middleware.EnumCommandKind.MatchClient: switch (sub_id) { case (int)bs.matchclient.CMDID_MatchClient.IDJoinRsp: //报名回复 { bs.matchclient.JoinRsp rsp = (bs.matchclient.JoinRsp)msg; //UserData.PlanInfo info = new UserData.PlanInfo((int)rsp.plan_id); Debug.LogFormat("receive joinrsp, result={0}", rsp.result); } break; case (int)bs.matchclient.CMDID_MatchClient.IDMatchStart: //开赛通知 { bs.matchclient.MatchStart rsp = (bs.matchclient.MatchStart)msg; UserData.enter_match.match_id = rsp.match_id; UserData.enter_match.group_id = rsp.group_id; UserData.enter_match.mp_appid = app_id; } break; case (int)bs.matchclient.CMDID_MatchClient.IDEnterMatchRsp: //进入比赛通知 OnEnterMatchRsp(msg, app_type, app_id); break; case (int)bs.matchclient.CMDID_MatchClient.IDTableStatusInd: { bs.matchclient.TableStatus rsp = (bs.matchclient.TableStatus)msg; UserData.enter_match.table_logic_appid = app_id; UserData.enter_match.table_id = rsp.table_id; //遍历users_rm,直到找到自己的座位号 for (int i = 0; i < rsp.users_rm.Count; i++) { if (rsp.users_rm[i].user_id == UserData.user_id) { UserData.enter_match.seat_id = rsp.users_rm[i].seat_index; } } //如果是拆桌,那么发送举手 if (rsp.table_stat == bs.matchclient.TableStatus.State.Dismiss) { SendPlayerActionReq(app_type, app_id); } } break; case (int)bs.matchclient.CMDID_MatchClient.IDGameData: { bs.matchclient.GameData data = (bs.matchclient.GameData)msg; majiang_interface.GetComponent <MajiangInterface>().ProcessGameData(data.data, data.data_id); } break; default: break; } break; default: break; } }
public static object RecvMessage(ref int kind_id, ref int sub_id, ref int app_type, ref int app_id) { int check_kind_id = 0; int size = GetMsgBuffSize(ref check_kind_id); if (0 == size && 0 == check_kind_id) //因为还有像hellorsp这样的没有报文长度但是有返回的报文,不能只靠size是否为0来判断 { return(null); } byte[] buff = new byte[size]; //int kind_id = 0; GetMsgBuff(buff, ref kind_id, ref sub_id); System.IO.Stream stream = new System.IO.MemoryStream(buff); switch (kind_id) { case (int)Middleware.EnumCommandKind.HallClient: switch (sub_id) { case (int)bs.hallclient.CMDID_HallClient.IDAllGroupRsp: { bs.hallclient.AllGroupRsp req = Serializer.Deserialize <bs.hallclient.AllGroupRsp>(stream); return(req); } case (int)bs.hallclient.CMDID_HallClient.IDAllListRsp: { bs.hallclient.AllListRsp req = Serializer.Deserialize <bs.hallclient.AllListRsp>(stream); return(req); } case (int)bs.hallclient.CMDID_HallClient.IDAllPlanRsp: { bs.hallclient.AllPlanRsp req = Serializer.Deserialize <bs.hallclient.AllPlanRsp>(stream); return(req); } case (int)bs.hallclient.CMDID_HallClient.IDPlanAllStartPoint: { bs.hallclient.PlanAllStartPoint req = Serializer.Deserialize <bs.hallclient.PlanAllStartPoint>(stream); return(req); } case (int)bs.hallclient.CMDID_HallClient.IDGetMatchDetailRsp: { bs.hallclient.GetMatchDetailRsp req = Serializer.Deserialize <bs.hallclient.GetMatchDetailRsp>(stream); return(req); } default: break; } break; case (int)EnumCommandKind.Client: switch (sub_id) { case (int)bs.client.CMDID_Client.IDLoginRsp: { bs.client.LoginRsp req = Serializer.Deserialize <bs.client.LoginRsp>(stream); return(req); } default: break; } break; case (int)EnumCommandKind.Gate: switch (sub_id) { case (int)bs.gate.CMDID_Gate.IDHelloRsp: { bs.gate.HelloRsp req = new bs.gate.HelloRsp(); Debug.LogFormat("get hellorsp"); return(req); } default: break; } break; case (int)Middleware.EnumCommandKind.MatchClient: switch (sub_id) { case (int)bs.matchclient.CMDID_MatchClient.IDJoinRsp: //报名回复 { bs.matchclient.JoinRsp req = Serializer.Deserialize <bs.matchclient.JoinRsp>(stream); return(req); } case (int)bs.matchclient.CMDID_MatchClient.IDMatchStart: //开赛通知 { bs.matchclient.MatchStart req = Serializer.Deserialize <bs.matchclient.MatchStart>(stream); return(req); } case (int)bs.matchclient.CMDID_MatchClient.IDEnterMatchRsp: //进入比赛通知 { bs.matchclient.EnterMatchRsp req = Serializer.Deserialize <bs.matchclient.EnterMatchRsp>(stream); return(req); } case (int)bs.matchclient.CMDID_MatchClient.IDTableStatusInd: { bs.matchclient.TableStatus req = Serializer.Deserialize <bs.matchclient.TableStatus>(stream); return(req); } case (int)bs.matchclient.CMDID_MatchClient.IDGameData: { bs.matchclient.GameData req = Serializer.Deserialize <bs.matchclient.GameData>(stream); return(req); } default: break; } break; default: break; } return(null); }