Esempio n. 1
0
    // 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;
        }
    }
Esempio n. 2
0
    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);
    }