Asgard.BifrostClient.GetStats C# (CSharp) Метод

GetStats() публичный Метод

public GetStats ( ) : NetStats
Результат Asgard.Core.Network.NetStats
        public NetStats GetStats()
        {
            if (Peer == null || Peer.Statistics == null || Peer.Connections.Count == 0)
                return null;

            if (_stats == null)
            {
                _lastNetCheck = (float)Lidgren.Network.NetTime.Now;
                _stats = new NetStats();
                _stats.TotalInBytes = Peer.Statistics.ReceivedBytes;
                _stats.TotalOutBytes = Peer.Statistics.SentBytes;
            }

            var diff = (float)Lidgren.Network.NetTime.Now - _lastNetCheck;

            if (diff > 10f)
            {
                _lastNetCheck = (float)Lidgren.Network.NetTime.Now;
                _stats = new NetStats();
                _stats.TotalInBytes = Peer.Statistics.ReceivedBytes;
                _stats.TotalOutBytes = Peer.Statistics.SentBytes;
                _stats.AvgPing = Peer.Connections[0].AverageRoundtripTime/2f*1000f;
                return _stats;
            }

            _stats.BytesInPerSec = (float)Math.Round((Peer.Statistics.ReceivedBytes - _stats.TotalInBytes) / diff, 2);
            _stats.BytesOutPerSec = (float)Math.Round((Peer.Statistics.SentBytes - _stats.TotalOutBytes) / diff, 2);
            _stats.AvgPing = Peer.Connections[0].AverageRoundtripTime/2f*1000f;
            return _stats;
        }