Beispiel #1
0
        /// <summary>
        /// 重构指令数据
        /// </summary>
        private void ReconstructionCmd(ref byte[] cmd)
        {
            string str = "";

            //当前执行的数组指令
            byte[] currentCmd;
            byte[] buffer;
            //当前执行的时刻值
            int currentTime;
            //当前执行的指令发出的玩家
            NetNodeInfo currentPlayer;

            //查看具体指令
            //str = "[>解码列表<]" + "[当前运行]" + ServerNetModel.CurrentFrame + "[缓存]" + ServerNetModel.NodeCmdQueue.Count + "[帧]";
            //读取指令过程
            for (int i = 0; i < cmd.Length; i++)
            {
                switch (CmdManager.ToCmd(cmd, ref i, out currentCmd))
                {
                case CmdEnum.Heartbeat:
                    str += "<" + "[心跳]" + ">" + ",";
                    break;

                case CmdEnum.BasetimeInform:
                    //BasetimeCmd basetime = new BasetimeCmd(currentCmd);
                    ////根据服务端发出的指令帧来进行本地更新,这里表示服务端已经完成了该基时帧的封包
                    //str += "<" + "[指令帧]" + basetime.frame + "[最大有效时间]" + basetime.maxValidTime + "[时间]" + basetime.time + "/" + ServerNetModel.TickTime +"[误差]" + (ServerNetModel.TickTime - basetime.time) + "[验证]" + basetime.verify + ">" + "\n";
                    break;

                case CmdEnum.Sync:
                    //SyncCmd sync = new SyncCmd(currentCmd);
                    //str += "<" + "[服务端当前帧]" + sync.frame + "[同步时间]" + sync.time + ">" + "\n";
                    break;

                case CmdEnum.Player:
                    //PlayerCmd playerCmd = new PlayerCmd(currentCmd);
                    //str += "<" + "[玩家]" + playerCmd.player.name + "[识别码]" + playerCmd.player.id + ">" + ",";
                    break;

                case CmdEnum.Key:
                    KeyCmd keyCmd = new KeyCmd(currentCmd);
                    //str += "<" + "[指令帧]" + keyCmd.frame + "[按键]" + (keyCmd.isDown ? "<按下>" : "<释放>") + keyCmd.key + "[偏移]" + keyCmd.offsetTime + ">";
                    int l = i - currentCmd.Length + 1;
                    keyCmd.frame = CurrentFrame;
                    buffer       = keyCmd.ToBytes();
                    for (int j = 0; j < buffer.Length; j++)
                    {
                        cmd[l + j] = buffer[j];
                    }
                    //str += "\n";
                    break;

                case CmdEnum.Order:
                    OrderCmd orderCmd = new OrderCmd(currentCmd);
                    //str += "<" + "[指令帧]" + keyCmd.frame + "[按键]" + (keyCmd.isDown ? "<按下>" : "<释放>") + keyCmd.key + "[偏移]" + keyCmd.offsetTime + ">";
                    int o = i - currentCmd.Length + 1;
                    orderCmd.frame = CurrentFrame;
                    buffer         = orderCmd.ToBytes();
                    for (int j = 0; j < buffer.Length; j++)
                    {
                        cmd[o + j] = buffer[j];
                    }
                    break;

                case CmdEnum.CreateEntity:
                    //CreateEntityCmd createCmd = new CreateEntityCmd(currentCmd);
                    ////创建单位
                    //UniquenessEntity uniqueness;
                    //if(ServerNetModel.UniquenessEntityRandDic.TryGetValue(createCmd.index,out uniqueness))
                    //{
                    //    uniqueness.isUsed = true;
                    //    str += "<" + "[创建实体]" + createCmd.index + "[识别码]" + createCmd.id + "[创建者]" + createCmd.player + ">" + ",";
                    //}
                    //else
                    //{
                    //    str += "<" + "[创建实体无效]" + ">" + ",";
                    //}
                    break;

                case CmdEnum.RequestCreateEntity:
                    //RequestCreateEntityCmd requestCmd = new RequestCreateEntityCmd(currentCmd);
                    break;

                default:
                    //Loger.Log("未知指令");
                    str += "<" + "[未知]" + ">" + ",";
                    break;
                }
            }
            if (str != "")
            {
                //Console.WriteLine(str);
            }
        }