From 53f4383555605988873daabda78273fe48a569e4 Mon Sep 17 00:00:00 2001 From: hide1202 Date: Sun, 4 Oct 2015 10:01:24 +0900 Subject: [PATCH 1/4] Remove goto statement in NetPeer.Internal. --- Lidgren.Network/NetPeer.Internal.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index 7c3e8c6..dec6df3 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -69,15 +69,8 @@ namespace Lidgren.Network return; // remove all callbacks regardless of sync context - RestartRemoveCallbacks: - for (int i = 0; i < m_receiveCallbacks.Count; i++) - { - if (m_receiveCallbacks[i].Item2.Equals(callback)) - { - m_receiveCallbacks.RemoveAt(i); - goto RestartRemoveCallbacks; - } - } + m_receiveCallbacks.RemoveAll(tuple => tuple.Item2.Equals(callback)); + if (m_receiveCallbacks.Count < 1) m_receiveCallbacks = null; } From 6dac4d74570392a8aae631019204fdc6b138e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Leone?= Date: Sun, 13 Dec 2015 03:10:25 +0100 Subject: [PATCH 2/4] Added byte to WriteAt --- Lidgren.Network/NetBuffer.Write.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lidgren.Network/NetBuffer.Write.cs b/Lidgren.Network/NetBuffer.Write.cs index 03e18ff..72f937c 100644 --- a/Lidgren.Network/NetBuffer.Write.cs +++ b/Lidgren.Network/NetBuffer.Write.cs @@ -101,6 +101,16 @@ namespace Lidgren.Network m_bitLength += 8; } + /// + /// Writes a byte at a given offset in the buffer + /// + public void WriteAt(Int32 offset, byte source) { + int newBitLength = Math.Max(m_bitLength, offset + 8); + EnsureBufferSize(newBitLength); + NetBitWriter.WriteByte((byte) source, 8, m_data, offset); + m_bitLength = newBitLength; + } + /// /// Writes a signed byte /// From 208f129e3f61e81b234f8c0a5dcade283c4fc470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Leone?= Date: Sun, 13 Dec 2015 03:42:39 +0100 Subject: [PATCH 3/4] Unity Support. Just compile with __CONSTRAINED__ and UNITY keyworkds and add a reference to UnityEngine.dll --- Lidgren.Network/Encryption/NetAESEncryption.cs | 12 ++++++++++++ Lidgren.Network/Platform/PlatformConstrained.cs | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Lidgren.Network/Encryption/NetAESEncryption.cs b/Lidgren.Network/Encryption/NetAESEncryption.cs index 5ed5582..9ab9557 100644 --- a/Lidgren.Network/Encryption/NetAESEncryption.cs +++ b/Lidgren.Network/Encryption/NetAESEncryption.cs @@ -7,18 +7,30 @@ namespace Lidgren.Network public class NetAESEncryption : NetCryptoProviderBase { public NetAESEncryption(NetPeer peer) +#if UNITY + : base(peer, new RijndaelManaged()) +#else : base(peer, new AesCryptoServiceProvider()) +#endif { } public NetAESEncryption(NetPeer peer, string key) +#if UNITY + : base(peer, new RijndaelManaged()) +#else : base(peer, new AesCryptoServiceProvider()) +#endif { SetKey(key); } public NetAESEncryption(NetPeer peer, byte[] data, int offset, int count) +#if UNITY + : base(peer, new RijndaelManaged()) +#else : base(peer, new AesCryptoServiceProvider()) +#endif { SetKey(data, offset, count); } diff --git a/Lidgren.Network/Platform/PlatformConstrained.cs b/Lidgren.Network/Platform/PlatformConstrained.cs index 77ff6c5..3308bbf 100644 --- a/Lidgren.Network/Platform/PlatformConstrained.cs +++ b/Lidgren.Network/Platform/PlatformConstrained.cs @@ -1,4 +1,4 @@ -#if __CONSTRAINED__ || UNITY_STANDALONE_LINUX +#if __CONSTRAINED__ || UNITY_STANDALONE_LINUX || UNITY using System; using System.Collections.Generic; using System.Net; @@ -29,9 +29,9 @@ namespace Lidgren.Network public static IPAddress GetMyAddress(out IPAddress mask) { mask = null; -#if UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_IOS try { +#if UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_IOS || UNITY if (!(UnityEngine.Application.internetReachability == UnityEngine.NetworkReachability.NotReachable)) { return null; From c8e2b011e0ecfa1101005a89c26b9c97cb9997c7 Mon Sep 17 00:00:00 2001 From: Michael Lidgren Date: Fri, 5 Feb 2016 11:44:46 +0100 Subject: [PATCH 4/4] Unnecessary code removed --- Lidgren.Network/NetConnection.Latency.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Lidgren.Network/NetConnection.Latency.cs b/Lidgren.Network/NetConnection.Latency.cs index c4e0205..b7b031e 100644 --- a/Lidgren.Network/NetConnection.Latency.cs +++ b/Lidgren.Network/NetConnection.Latency.cs @@ -46,15 +46,7 @@ namespace Lidgren.Network internal void InitializePing() { - double now = NetTime.Now; - - // randomize ping sent time (0.25 - 1.0 x ping interval) - m_sentPingTime = now; - m_sentPingTime -= (m_peerConfiguration.PingInterval * 0.25f); // delay ping for a little while - m_sentPingTime -= (MWCRandom.Instance.NextSingle() * (m_peerConfiguration.PingInterval * 0.75f)); - m_timeoutDeadline = now + (m_peerConfiguration.m_connectionTimeout * 2.0); // initially allow a little more time - - // make it better, quick :-) + m_timeoutDeadline = NetTime.Now + (m_peerConfiguration.m_connectionTimeout * 2.0); // initially allow a little more time SendPing(); }