1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-06 02:11:06 +09:00

Initializing ping to random start to make network stream more unpredictable

This commit is contained in:
lidgren
2010-12-09 07:56:34 +00:00
parent 2e78b3e685
commit be902b8010
5 changed files with 14 additions and 2 deletions

Binary file not shown.

View File

@@ -138,7 +138,7 @@ namespace Lidgren.Network
om.m_messageType = NetMessageType.ConnectionEstablished;
m_peer.SendLibrary(om, m_remoteEndpoint);
m_sentPingTime = (float)NetTime.Now - (m_peerConfiguration.PingInterval / 2.0f); // delay ping for a little while
InitializePing();
if (m_status != NetConnectionStatus.Connected)
SetStatus(NetConnectionStatus.Connected, "Connected to " + NetUtility.ToHexString(m_remoteUniqueIdentifier));
}
@@ -285,7 +285,7 @@ namespace Lidgren.Network
case NetConnectionStatus.RespondedConnect:
// awesome
m_peer.AcceptConnection(this);
m_sentPingTime = (float)NetTime.Now - (m_peerConfiguration.PingInterval / 2.0f); // delay ping for a little while
InitializePing();
SetStatus(NetConnectionStatus.Connected, "Connected to " + NetUtility.ToHexString(m_remoteUniqueIdentifier));
return;
}

View File

@@ -14,6 +14,14 @@ namespace Lidgren.Network
/// </summary>
public float AverageRoundtripTime { get { return m_averageRoundtripTime; } }
internal void InitializePing()
{
// randomize ping sent time (0.25 - 1.0 x ping interval)
m_sentPingTime = (float)NetTime.Now;
m_sentPingTime -= (m_peerConfiguration.PingInterval * 0.25f); // delay ping for a little while
m_sentPingTime -= (NetRandom.Instance.NextSingle() * (m_peerConfiguration.PingInterval * 0.75f));
}
internal void SendPing()
{
m_peer.VerifyNetworkThread();

View File

@@ -156,6 +156,9 @@ namespace Lidgren.Network
}
}
/// <summary>
/// Returns default(T) if queue is empty
/// </summary>
public T TryPeek(int offset)
{
if (m_size == 0)

View File

@@ -144,6 +144,7 @@ namespace DurableServer
else
{
StringBuilder bdr = new StringBuilder();
bdr.AppendLine("Uptime: " + (NetTime.ToReadable(NetTime.Now)));
bdr.Append(Server.Statistics.ToString());
bdr.Append(Server.Connections[0].Statistics.ToString());
bdr.AppendLine("RECEIVED Reliable ordered: " +