public List <ClientTime> FillClientTimes(IDataReader reader, List <ClientTime> rows, int start, int pageLength) { for (int i = 0; i < start; i++) { if (!reader.Read()) { return(rows); } } for (int i = 0; i < pageLength; i++) { if (!reader.Read()) { break; } var smallReport = new ClientTime { ClientId = DataHelper.GetInteger(reader[ReportFieldNames.CustomerId]), Time = DataHelper.GetDecimal(reader[ReportFieldNames.Time]), InsertionDate = DataHelper.GetDateTime(reader[ReportFieldNames.InsertionDate]), UserId = DataHelper.GetInteger(reader[ReportFieldNames.UserId]) }; rows.Add(smallReport); } return(rows); }
void ReceviceAffirmMsg(AffirmMsg msg, params object[] objs) { ConnectStatusComponent csc = m_world.GetSingletonComp <ConnectStatusComponent>(); csc.rtt = ClientTime.GetTime() - msg.time; //TODO 服务器确认后这里可以清除下缓存 }
void SelfCommandLogic(EntityBase entity) { //Debug.Log("SelfCommandLogic " + m_world.FrameCount); if (m_world.IsLocal) { //构建一份新指令并发送 T ncmd = new T(); ncmd.frame = m_world.FrameCount; ncmd.id = entity.ID; BuildCommand(ncmd); entity.ChangeComp(ncmd); } else { //先取服务器缓存 AddComp(entity); PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(ComponentType.PlayerCommandRecordComponent); T cmd = (T)rc.GetInputCahae(m_world.FrameCount); cmd = (T)cmd.DeepCopy(); entity.ChangeComp(cmd); //构建一份新指令并发送 T ncmd = new T(); ncmd.frame = m_world.FrameCount + 1; ncmd.id = entity.ID; BuildCommand(ncmd); if (ncmd.EqualsCmd(cmd)) { sameCmdCache.frame = m_world.FrameCount + 1; sameCmdCache.time = ClientTime.GetTime(); sameCmdCache.id = entity.ID; if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(sameCmdCache); } } else { ncmd.frame = m_world.FrameCount + 1; ncmd.time = ClientTime.GetTime(); if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(ncmd); } } } }
public void UpdateTime_OverflowTest() { var time = new ClientTime(); long toAdd = UnixTimeStamp.GetEpochUtcNow(); time.offsetList.Add(-1000); time.offsetList.Add(1000); for (int i = 0; i < ClientTime.Capacity - 2; i++) { time.UpdateTime(toAdd); } Assert.Equal(ClientTime.Capacity, time.offsetList.Count); Assert.Equal(ClientTime.Capacity, time.offsetList.Capacity); Assert.Equal(-1000, time.offsetList[0]); Assert.Equal(1000, time.offsetList[^ 1]);
public void NowTest() { var time = new ClientTime(); var actual = time.Now; var expected = UnixTimeStamp.GetEpochUtcNow(); Assert.True(Math.Abs(expected - actual) < 3); for (int i = 0; i < 6; i++) { time.UpdateTime(expected + 20); } actual = time.Now; expected = UnixTimeStamp.GetEpochUtcNow(); var diff = Math.Abs(expected - actual); Assert.True(diff > 15 && diff < 25); }
public void WrongClockEventTest() { var time = new ClientTime(); bool raised = false; time.WrongClockEvent += (sender, e) => { raised = true; }; // Now + 1 min long toAdd = UnixTimeStamp.GetEpochUtcNow() + (ClientTime.MaxIgnoredTimeOffset + 60); for (int i = 0; i < ClientTime.MinIgnoreCount - 1; i++) { time.UpdateTime(toAdd); Assert.False(raised); } time.UpdateTime(toAdd); Assert.True(raised); }
void SelfCommandLogic(EntityBase entity) { T comp = new T(); comp.frame = m_world.FrameCount; comp.id = entity.ID; BuildCommand(comp); entity.ChangeComp(comp); AddComp(entity); //缓存起来 PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); rc.RecordCommand(comp); if (!m_world.m_isLocal) { comp.time = ClientTime.GetTime(); ProtocolAnalysisService.SendCommand(comp); } }
void SelfCommandLogic(EntityBase entity) { //Debug.Log("SelfCommandLogic " + m_world.FrameCount); //先取服务器缓存 AddComp(entity); PlayerCommandRecordComponent rc = entity.GetComp <PlayerCommandRecordComponent>(); T cmd = (T)rc.GetInputCahae(m_world.FrameCount); //没有的话构建一份 if (cmd == null) { cmd = new T(); cmd.frame = m_world.FrameCount; cmd.id = entity.ID; BuildCommand(cmd); rc.RecordCommand(cmd); //Debug.Log("Self cmd " + entity.ID + " content " + Serializer.Serialize(cmd) + " " + m_world.FrameCount); } else { //Debug.Log("读取 服务器缓存 输入"); } if (!m_world.IsLocal) { T record = (T)rc.GetInputCahae(m_world.FrameCount - 1); cmd.frame = m_world.FrameCount - 1; if (record != null && record.EqualsCmd(cmd)) { sameCmdCache.frame = m_world.FrameCount; sameCmdCache.time = ClientTime.GetTime(); sameCmdCache.id = entity.ID; if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(sameCmdCache); } //Debug.Log("send same " + m_world.FrameCount + " id " + sameCmdCache.id); } else { //Debug.Log("send cmd " + m_world.FrameCount + " id " + cmd.id); cmd.frame = m_world.FrameCount; cmd.time = ClientTime.GetTime(); if (NetworkManager.IsConnect) { ProtocolAnalysisService.SendCommand(cmd); } } } entity.ChangeComp(cmd); }
public override string ToString() { return(ClientTime.ToString() + ", " + ClientId + ", " + Identifier + ", " + Value); }