public void FakeReceiveMsg(ByteBuffer buffer) { System.Timers.Timer timer = new System.Timers.Timer(); timer.Interval = delay; timer.AutoReset = false; int start = 0; int type = buffer.GetInt(start, ref start); if (type == 0) { int frameIdx = buffer.GetInt(start, ref start); timer.Elapsed += (sender, e) => { GetNewTick(frameIdx); }; } else { string jsonStr = buffer.GetString(start, ref start); FrameOpt opt = JsonConvert.DeserializeObject <FrameOpt>(jsonStr); //Console.WriteLine("cnmcnm"); timer.Elapsed += (sender, e) => { GetNewOpt(opt); }; } timer.Enabled = true; }
public void Handle(FrameOpt opt) { if (opt == null) { Debug.Log("why null?"); } //Debug.Log("handle:"); switch (opt.optType) { case eOptType.MVOE: string optContent = opt.optContent; //Debug.Log(realOpt.Velocity); if (optContent != null) { LogicActor target = GetActor(opt.actorId); if (target != null) { string[] vString = optContent.Split(','); target.Volocity = new VInt2(int.Parse(vString[0]), int.Parse(vString[1])); } } break; default: break; } }
private void GetNewOpt(FrameOpt opt) { List <FrameOpt> optList = NowOpts[0]; lock (optList) { optList.Clear(); optList.Add(opt); } }
public void SendLocalOpt(FrameOpt opt) { ByteBuffer byteBuffer = new ByteBuffer(); byteBuffer.AddInt(1); string jsonStr = JsonConvert.SerializeObject(opt); byteBuffer.AddString(jsonStr); GameMain.GetInstance().netManager.Send(byteBuffer); }
public void MainTick(object sender, ElapsedEventArgs e) { LogicFrame frame = new LogicFrame(FrameIdx++); foreach (var kv in plyLastFrameInfo) { if (FrameIdx - kv.Value > 50) { //掉线 isDiaoxian = true; } else { isDiaoxian = false; } } foreach (var kv in NowOpts) { if (kv.Value.Count == 0) { FrameOpt emptyOpt = new FrameOpt(); emptyOpt.actorId = kv.Key; emptyOpt.optType = eOptType.MVOE; emptyOpt.optContent = "0,0"; frame.frameOpts.Add(emptyOpt); if (isDiaoxian) { //伪造回家包 } } else { frame.frameOpts.Add(kv.Value[0]); } kv.Value.Clear(); } FrameList.AddLast(new LinkedListNode <LogicFrame>(frame)); frame.dtime = (int)TickInteval; //LinkedListNode<LogicFrame> node = FrameList.Last; //Debug.Log("svr frame:" + frame.frameIdx); string ret = JsonConvert.SerializeObject(frame); ByteBuffer byteBuffer = new ByteBuffer(); byteBuffer.AddInt((int)eNetMsgType.FRAME); byteBuffer.AddString(ret); FakeSendMsg(byteBuffer); }
public int sendFrameEvent(byte[] data, FrameOpt opt = FrameOpt.ONLY_CLIENT) { if (!mState.HaveInRoom()) { return(-1); } if (data.Length > 1024) { return(-21); } var buf = _mPro.en(SDKHotelCmdID.FrameBroadcastCmdid, MVS.RoomID, (uint)0, data, (int)opt); this._mHNw?.send(buf); return(0); }
private void LogicUpdate(LogicFrame frame) { //handle frame if (frame.frameIdx != this.frameIdx + 1) { Debug.Log(this.frameIdx + " " + frame.frameIdx); Debug.Log("zhenshu错误 丢弃"); return; } this.frameIdx = frame.frameIdx; this.LastDtime = frame.dtime; //Debug.Log("opt shu:" + frame.frameOpts.Count); //handle input for (int i = 0; i < frame.frameOpts.Count; i++) { FrameOpt opt = frame.frameOpts[i]; Handle(opt); } battleMgr.Update(frame.dtime); //执行所有update for (int i = 0; i < LogicActorList.Count; i++) { LogicActorList[i].Update(frame.dtime); } //发送本机的命令 //SendLocalOpt(); SendAck(); }
// 在逻辑帧中更新 // 指令需要缓存吗 ? 缓存的结果是 public void Update() { if (Pawn == null) { return; } VInt2 moveVec = VInt2.zero; if (inputModule.isA) { moveVec.x -= 1; } if (inputModule.isD) { moveVec.x += 1; } if (inputModule.isS) { moveVec.y -= 1; } if (inputModule.isW) { moveVec.y += 1; } if (moveVec.x == 0 && moveVec.y == 0) { return; } FrameOpt moveOpt = new FrameOpt(); moveOpt.actorId = Pawn.ActorId; moveOpt.optType = eOptType.MVOE; moveOpt.optContent = moveVec.x + "," + moveVec.y; Pawn.mgr.SendLocalOpt(moveOpt); }