Beispiel #1
0
        internal override void OnSyncServerTime(DateTime serverTime, int id)
        {
            if (id != lastSendHeartbeatSeqId)
            {
                Logs.Error("服务器同步时间有问题,id编号错误 {0} {1}", id.ToString(), lastSendHeartbeatSeqId.ToString());
                return;
            }

            lastRecvHeartbetaSeqId = id;

            //  服务器当前的时间可以视为服务器发过来的时间,再加上网络延迟
            //  网络延迟 = (当前时间 - 发送心跳包的时间) / 2
            var ts            = DateTime.Now - lastSendTime;
            var nowServerTime = serverTime.AddMilliseconds(ts.TotalMilliseconds / 2);

            OneServer.SetServerTime(nowServerTime);
        }