Example #1
0
        /// <summary>
        /// Check if the current time of the system is correct
        /// </summary>
        private async Task CheckTime()
        {
            TimeSpan difference = DateTime.UtcNow - SettingsService.Instance.LastCheckedSystemTime;

            // check the time again after 8 hours or always in debug mode
            if (System.Diagnostics.Debugger.IsAttached || difference.TotalHours > 8)
            {
                if (NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable && SettingsService.Instance.UseNTPServerCorrection)
                {
                    try
                    {
                        DateTime time = await NetworkTimeService.GetNetworkTimeAsync(SettingsService.Instance.NTPServerString);

                        TimeSpan timespan = time.Subtract(DateTime.UtcNow);
                        if (Math.Abs(timespan.TotalSeconds) >= 15) // difference of 15 seconds or more
                        {
                            _ntpServerTimeDifference = timespan;
                            SystemTimeNotCorrectError();
                        }
                        _checkedTimeSynchronisation = true;
                        SettingsService.Instance.LastCheckedSystemTime = DateTime.UtcNow;
                    }
                    catch (Exception exc)
                    {
                        Logger.Log("NTP exception: " + exc.Message, Category.Exception, Priority.High);
                        //TrackingManager.TrackException(exc);
                    }
                }
            }
        }
Example #2
0
 public RoundTripTimeService(IUdpClient udpClient, NetworkTimeService networkTimeService)
 {
     this.udpClient          = udpClient;
     this.networkTimeService = networkTimeService;
     this.udpClient.OnMessageReceive
     .Where(message => message[0] == MessageId.PING_RESP)
     .Subscribe(OnMessageReceived);
 }
Example #3
0
 public MatchSimulation(byte localPlayerUnitId, Int64 matchStartTimestamp, MatchInputProvider matchInputProvider,
                        MatchSpawnService matchEventProvider, IUdpClient udpClient, NetworkTimeService networkTimeService)
 {
     this.localPlayerUnitId   = localPlayerUnitId;
     this.matchStartTimestamp = matchStartTimestamp;
     inputProvider            = matchInputProvider;
     eventProvider            = matchEventProvider;
     this.udpClient           = udpClient;
     this.networkTimeService  = networkTimeService;
     SimulationFrameSubject   = new Subject <byte>();
 }
Example #4
0
 public void InitializeUdpClient(string ip, int port)
 {
     UDPClient          = new UdpClient(ip, port);
     AckedMessageHelper = new AckedMessageHelper(UDPClient);
     NetworkTimeService = new NetworkTimeService();
 }