public NetStats GetStats()
{
if (Peer == null || Peer.Statistics == null)
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;
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);
return _stats;
}