public void CheckReceiveCmdStack() { BaseCmd cmd; while (ReceiveCmdStack.TryPop(out cmd)) { byte[] buffer; switch (cmd.type) { case CmdEnum.Key: KeyCmd key = (KeyCmd)cmd; key.frame = CurrentFrame; buffer = key.ToBytes(); break; case CmdEnum.Order: OrderCmd order = (OrderCmd)cmd; order.frame = CurrentFrame; buffer = order.ToBytes(); break; case CmdEnum.CreateEntity: CreateEntityCmd create = (CreateEntityCmd)cmd; create.frame = CurrentFrame; buffer = create.ToBytes(); Console.WriteLine("[服务端同意创建]" + create.player + "[识别]" + create.id + "[索引]" + create.index + "[当前帧]" + CurrentFrame + "[时间]" + TickTime); break; default: buffer = cmd.ToBytes(); break; } NodeCmdBuffer.Push(buffer); } }
void IsKeyArgument(CommandLineArgumentParser arguments, ref int valid) { if (arguments.StartWith("/key")) { if (arguments.Has("-d")) { if (EntityControl.Instance.MasterEntityControllIndex == 0) { Console.WriteLine("[无可操作实体]"); valid += 1; return; } CommandLineArgument node = arguments.Get("-d"); IntVector2 vector = IntVector2.Zero; int value = 0; string s1 = null; if (node != null) { s1 = node.Take(); if (s1 != null && !int.TryParse(s1, out value)) { value = 0; } } string s2 = null; if (s1 != null && node.Next != null) { s2 = node.Next.Take(); if (s2 != null && !IntVector2.TryParse(s2, out vector)) { vector = IntVector2.Zero; } } DriverOrderCode orderCode = new DriverOrderCode().SetTragerPoint(vector).SetValue(value).SetOrigin(EntityControl.Instance.MasterEntityControllIndex); OrderCmd cmd = OrderCmd.Instance(orderCode.ToBytes()); ControlModel.NetCtrl.WhenCollectCmd(cmd.ToBytes()); Console.WriteLine("[索引]" + orderCode.index + "[速度]" + orderCode.vector + "[旋转]" + orderCode.value + "[长度]" + cmd.ToBytes().Length); valid += 1; return; } Console.WriteLine("[无效指令]"); valid += 1; return; } else { return; } }
/// <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); } }