Esempio n. 1
0
        protected override void OnClockSync(PacketClockSync msg)
        {
            // reply with the server time, but use the same packet to reply
            // in order to preserve the original timestamps
            long now = DateTime.UtcNow.Ticks;

            try
            {
                LatencyMs = (int)Math.Ceiling(TimeSpan.FromTicks((now - msg.SentOnUTC) * 2).TotalMilliseconds);
                //Log1.Logger("Server.Network").Debug("Clock sync request. " + LatencyMs + "ms latency.");
            }
            catch {}

            msg.ReplyPacket = msg;
            msg.PacketID    = Packet.NextPacketId; // give it a new packet id
            // packet will be time stamped on send
        }
Esempio n. 2
0
        private void RequestSyncSample()
        {
            // got the lock
            if (Owner.IsAlive)
            {
                //Log.LogMsg("Requesting clock sample from server.");

                m_CurrentSyncStep++;
                PacketClockSync msg = Owner.CreatePacket((int)PacketType.ClockSync, 0, false, false) as PacketClockSync;
                msg.StartTime = DateTime.UtcNow.Ticks;
                Owner.Send(msg);

                if (m_CurrentSyncStep >= NumSamplesForSync)
                {
                    // end of sampling sequence.  evaluate results and restart sequence, if appropriate
                    m_CurrentSyncStep = 0;
                    Recalculate();
                    if (TimeBetweenSyncs > 0)
                    {
                        SetTimer(TimeBetweenSyncs);
                    }
                }
                else
                {
                    // more samples to be taken.  determine when and kick it off.
                    int nextStepDelay = GetTimeBetweenSyncSteps();
                    if (nextStepDelay > 0)
                    {
                        SetTimer(nextStepDelay);
                    }
                    else
                    {
                        RequestSyncSample();
                    }
                }
            }
        }
Esempio n. 3
0
        protected override void OnClockSync(PacketClockSync msg)
        {
            // reply with the server time, but use the same packet to reply
            // in order to preserve the original timestamps
            long now = DateTime.UtcNow.Ticks;

            try
            {
                LatencyMs = (int)Math.Ceiling(TimeSpan.FromTicks((now - msg.SentOnUTC) * 2).TotalMilliseconds);
                //Log1.Logger("Server.Network").Debug("Clock sync request. " + LatencyMs + "ms latency.");
            }
            catch{}

            msg.ReplyPacket = msg;
            msg.PacketID = Packet.NextPacketId; // give it a new packet id
            // packet will be time stamped on send
        }
Esempio n. 4
0
 protected override void OnClockSync(PacketClockSync msg)
 {
     Clock.AddSample(msg.StartTime, DateTime.UtcNow.Ticks, msg.SentOnUTC);
 }
Esempio n. 5
0
 protected override void OnClockSync(PacketClockSync msg)
 {
     Clock.AddSample(msg.StartTime, DateTime.UtcNow.Ticks, msg.SentOnUTC);
 }
Esempio n. 6
0
 /// <summary>
 /// Fires when we receive a clock synchronization packet
 /// </summary>
 /// <param name="sender">the connection sending the sync packet</param>
 /// <param name="msg">the sync data</param>
 protected virtual void OnClockSync(PacketClockSync msg)
 {
 }