コード例 #1
0
    public static int OnConnectCallFunc(int Id, IntPtr data, int len, Int64 sockindex)
    {
        //	GUILayout.Label ("=====" + msg);
        //msg1 = msg;

        //		readPaket.IgnoreBytes(1);
        //		readPaket.Read(nServerId);
        //		readPaket.Read(nGameId);
        //		readPaket.Read(nUserId);
        //		readPaket.Read(nUserGuid);

        Debug.Log(string.Format("======{0}", Id));

        switch (Id)
        {
        case (int)msg_id.ID_CONNECTION_REQUEST_ACCEPTED:
        {
            Debug.Log(string.Format("==ID_CONNECTION_REQUEST_ACCEPTED===={0}", Id));
            socketindex = sockindex;

            SendEntergame(101, 2, m_myPlayer.m_nUid);
        }
        break;

        case (int)msg_id.PT_HOST_MESSAGE:
        {
            Debug.Log(string.Format("==PT_HOST_MESSAGE===={0}", Id));

            //读出内存中的每二个消息ID
            int msg2id = (int)Marshal.ReadInt32(data, 1);
            Debug.Log(string.Format("==msg2 id===={0}", msg2id));
            switch (msg2id)
            {
            case (int)host_msg.PT_DDZ_MATCH_ACCEPT:
            {
                PT_DDZ_MATCH_ACCEPT_INFO info = (PT_DDZ_MATCH_ACCEPT_INFO)(PtrToStruct(data, typeof(PT_DDZ_MATCH_ACCEPT_INFO)));

                Dictionary <int, CUser> m_Userlist = m_GameTable.m_UserlistById;

                for (int i = 0; i < info.usernum; i++)
                {
                    CUser user = new CUser();
                    user.m_nId    = info.userindex[i].uid;
                    user.m_nIndex = info.userindex[i].index;

                    m_Userlist[user.m_nId] = user;
                }
                Debug.Log("===match accept===");
            }
            break;

            case (int)host_msg.PT_DDZ_GAME_START:

            {
                Debug.Log("===game start===");

                PT_DDZ_GAME_START_INFO info1;
                //	byte[] by1 = new byte[len];


                //	Marshal.Copy ((IntPtr)data, by1, 0, len);

                //跳过第一个字节,255
                info1 = (PT_DDZ_GAME_START_INFO)(PtrToStruct(data, typeof(PT_DDZ_GAME_START_INFO)));

                //  info1.pai.CopyTo(m_GameTable.m_UserlistById[m_myPlayer.m_nUid].m_nPai, 0);

                //    m_GameTable.m_UserlistById[m_myPlayer.m_nUid].m_nPai = info1.pai;

                //      m_GameTable.m_UserlistById[m_myPlayer.m_nUid].m_nPaiNum = 17;

                for (int i = 0; i < 17; i++)
                {
                    m_GameTable.m_UserlistById[m_myPlayer.m_nUid].m_nPai.Add(info1.pai[i]);
                }


                m_GameTable.SetPlayerPai(info1.pai, 17);

                //set di pai
                m_GameTable.SetTablePai(info1.dipai, 3);


                GameObject playerObj = GameObject.Find("Player");
                HandCards  cards     = playerObj.GetComponent <HandCards>();


                //for (int i = 0; i < 17; i++)
                //{
                //    Card card = m_GameTable.m_Cardlist[info1.pai[i]];

                //    cards.AddCard(card);

                //    m_GameTable.m_Pokerlist[]
                //}


                //   GetInteractionMgr().OnGameStart(info1);



                //自己先开始操作,叫分
                if (info1.nActUid == m_myPlayer.m_nUid)
                {
                    //显示叫分
                }
            }
            break;

            case (int)host_msg.PT_DDZ_BALANCE:
            {
            }
            break;

            case (int)host_msg.PT_DDZ_CHUPAI:
            {
            }
            break;

            case (int)host_msg.PT_DDZ_JIAOFEN:
            {
            }
            break;

            case (int)host_msg.PT_DDZ_PASS:
            {
            }
            break;

            case (int)host_msg.PT_DDZ_USER_CHUPAI:
            {
                PT_DDZ_USER_CHUPAI_INFO info = (PT_DDZ_USER_CHUPAI_INFO)(PtrToStruct(data, typeof(PT_DDZ_USER_CHUPAI_INFO)));


                Debug.Log(string.Format("PT_DDZ_USER_CHUPAI:{0}", info.nUid));



                //   m_GameTable.m_nPai = info.nPai;



                m_GameTable.SetTablePai(info.nPai, info.nNum);
                m_GameTable.m_nChupaiUserId = info.nUid;
                m_GameTable.m_nActId        = info.nActUid;

                if (info.nUid == CPlayer.Instance().m_nUid)
                {
                    //PlayCard playCard = GameObject.Find("Player").GetComponent<PlayCard>();

                    //playCard.PlayCardsEx();

                    m_GameTable.SortMyCard(info.nPai, info.nNum);
                }

                if (info.nActUid == CPlayer.Instance().m_nUid)
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_DAPAI);
                }
                else
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_NONE);
                }
            }
            break;

            case (int)host_msg.PT_DDZ_USER_PASS:
            {
                PT_DDZ_USER_PASS_INFO info = (PT_DDZ_USER_PASS_INFO)(PtrToStruct(data, typeof(PT_DDZ_USER_PASS_INFO)));

                m_GameTable.m_nActId = info.nActUid;

                if (info.nActUid == CPlayer.Instance().m_nUid)
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_DAPAI);
                }
                else
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_NONE);
                }

                Debug.Log(string.Format("PT_DDZ_USER_PASS_uid:{0}", info.nUid));
            }
            break;


            case (int)host_msg.PT_DDZ_DZPAI:
            {
                PT_DDZ_DZPAI_INFO info = (PT_DDZ_DZPAI_INFO)(PtrToStruct(data, typeof(PT_DDZ_DZPAI_INFO)));

                m_GameTable.m_nActId   = info.nActUid;
                m_GameTable.m_nDipai   = info.pai;
                m_GameTable.m_nJiaoFen = info.nJiaoFen;
                m_GameTable.m_nDizhuId = info.nUserId;

                if (info.nUserId == CPlayer.Instance().m_nUid)
                {
                    //GameController m_Controller = GetGameController();
                    //m_Controller.CardsOnTableEx(CharacterType.Player);


                    m_GameTable.SetDiPai(info.pai, 3);
                }

                if (info.nActUid == CPlayer.Instance().m_nUid)
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_DAPAI);
                }
                else
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_NONE);
                }
            }
            break;

            case (int)host_msg.PT_DDZ_USER_JIAOPAI:
            {
                PT_DDZ_USER_JIAOPAI_INFO info = (PT_DDZ_USER_JIAOPAI_INFO)(PtrToStruct(data, typeof(PT_DDZ_USER_JIAOPAI_INFO)));


                if (info.nActUid == CPlayer.Instance().m_nUid)
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_JIAODIZHU);
                }
                else
                {
                    GetInteractionMgr().SetGameSate(GAME_OPT_STATE.GAME_NONE);
                }
            }
            break;

            case (int)host_msg.PT_DDZ_GAME_END:
            {
                PT_DDZ_GAME_END_INFO info = (PT_DDZ_GAME_END_INFO)(PtrToStruct(data, typeof(PT_DDZ_GAME_END_INFO)));


                Debug.Log(string.Format("PT_DDZ_GAME_END_INFO"));
            }
            break;



            default:
            {
                Debug.Log(string.Format("==PT_ENTER_GAME_ACCEPT==11=={0}", msg2id));
            }
            break;
            }
        }
        break;

        case (int)msg_id.PT_ENTER_GAME_ACCEPT:
        {
            Debug.Log(string.Format("==PT_ENTER_GAME_ACCEPT===={0}", System.Runtime.InteropServices.Marshal.SizeOf(typeof(PT_ENTER_GAME_ACCEPT_INFO))));

            PT_ENTER_GAME_ACCEPT_INFO info1;
            //	byte[] by1 = new byte[len];


            //	Marshal.Copy ((IntPtr)data, by1, 0, len);

            //跳过第一个字节,255
            info1 = (PT_ENTER_GAME_ACCEPT_INFO)(PtrToStruct(data, typeof(PT_ENTER_GAME_ACCEPT_INFO)));



            Debug.Log(string.Format("==PT_ENTER_GAME_ACCEPT==11=={0}", info1.id));
        }
        break;

        default:
        {
            Debug.Log(string.Format("==default===={0}", Id));
        }
        break;
        }

        /*
         * if (Id == 16) {
         *
         * }
         *
         * if (Id == 255) {
         * //						PT_ENTER_GAME_REQUEST_INFO info1;
         * //
         * //						byte[] by1 = new byte[len];
         * //
         * //
         * //						Marshal.Copy ((IntPtr)data, by1, 0, len);
         * //
         * //						//跳过第一个字节,255
         * //
         * //						info1 = (PT_ENTER_GAME_REQUEST_INFO)(BytesToStruct (by1, 1, len - 1, typeof(PT_ENTER_GAME_REQUEST_INFO)));
         * //
         * //						int gg = 0;
         * //
         * //						gg++;
         *
         *
         *
         *
         *
         *
         * }
         */

        return(1);
    }