Exemplo n.º 1
0
        /*解析登录信息的,手贱+傻逼,不小心写多
         *      private static void GetLoginInfo(ref byte[] btRecv,ref PackageMetaData pmdData){
         *  string strUserName="",strUserPass="";
         *  int nNameLen = 0;
         *  for (int i=pmdData.nHeaderLen;btRecv[i]!='\0';i++) {
         *      byte[] arrTmpByte = new byte[] { btRecv[i] };
         *      strUserName += System.Text.Encoding.ASCII.GetString(arrTmpByte);
         *      nNameLen++;
         *  }
         *  for (int i=(pmdData.nHeaderLen+nNameLen+1); btRecv[i] != '\0';i++) {
         *      byte[] arrTmpByte = new byte[] { btRecv[i] };
         *      strUserPass += System.Text.Encoding.ASCII.GetString(arrTmpByte);
         *  }
         *  pmdData.Set("name",strUserName);
         *  pmdData.Set("password", strUserPass);
         * }*/
        //包内容编号(int)|时间戳(long)|玩家id(int)
        private static PackageMetaData ParseHeader(byte[] btRecv)
        {
            PackageMetaData data = new PackageMetaData();

            data.Set("type", BitConverter.ToInt32(btRecv, 0).ToString());
            data.Set("time", BitConverter.ToInt64(btRecv, sizeof(System.Int32)).ToString());
            data.Set("id", BitConverter.ToInt32(btRecv, sizeof(System.Int32) + sizeof(System.Int64)).ToString());
            return(data);
        }
Exemplo n.º 2
0
        private static void GetPosition(ref byte[] btRecv, ref PackageMetaData pmdData)
        {
            double lfX = BitConverter.ToSingle(btRecv, pmdData.nHeaderLen);
            double lfY = BitConverter.ToSingle(btRecv, pmdData.nHeaderLen + sizeof(System.Single));
            double lfZ = BitConverter.ToSingle(btRecv, pmdData.nHeaderLen + 2 * sizeof(System.Single));

            pmdData.Set("x", lfX.ToString());
            pmdData.Set("y", lfY.ToString());
            pmdData.Set("z", lfZ.ToString());
        }
Exemplo n.º 3
0
        public static PackageMetaData Parse(byte[] btRecv)
        {
            PackageMetaData pdata        = ParseHeader(btRecv);
            int             nHeaderLen   = sizeof(System.Int32) * 2 + sizeof(System.Int64);
            int             nPackageType = int.Parse(pdata.Get("type"));

            //Console.WriteLine("type int:" +nPackageType.ToString());
            pdata.nHeaderLen = nHeaderLen;
            //包类型编号小于0的没有内容
            if (nPackageType >= 0)
            {
                switch (nPackageType)
                {
                case 0:
                    GetPosition(ref btRecv, ref pdata);
                    break;
                }
            }
            return(pdata);
        }