1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 08:36:34 +09:00
This commit is contained in:
Michael Lidgren
2016-02-25 07:35:18 +01:00
5 changed files with 27 additions and 20 deletions

View File

@@ -7,18 +7,30 @@ namespace Lidgren.Network
public class NetAESEncryption : NetCryptoProviderBase public class NetAESEncryption : NetCryptoProviderBase
{ {
public NetAESEncryption(NetPeer peer) public NetAESEncryption(NetPeer peer)
#if UNITY
: base(peer, new RijndaelManaged())
#else
: base(peer, new AesCryptoServiceProvider()) : base(peer, new AesCryptoServiceProvider())
#endif
{ {
} }
public NetAESEncryption(NetPeer peer, string key) public NetAESEncryption(NetPeer peer, string key)
#if UNITY
: base(peer, new RijndaelManaged())
#else
: base(peer, new AesCryptoServiceProvider()) : base(peer, new AesCryptoServiceProvider())
#endif
{ {
SetKey(key); SetKey(key);
} }
public NetAESEncryption(NetPeer peer, byte[] data, int offset, int count) public NetAESEncryption(NetPeer peer, byte[] data, int offset, int count)
#if UNITY
: base(peer, new RijndaelManaged())
#else
: base(peer, new AesCryptoServiceProvider()) : base(peer, new AesCryptoServiceProvider())
#endif
{ {
SetKey(data, offset, count); SetKey(data, offset, count);
} }

View File

@@ -101,6 +101,16 @@ namespace Lidgren.Network
m_bitLength += 8; m_bitLength += 8;
} }
/// <summary>
/// Writes a byte at a given offset in the buffer
/// </summary>
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;
}
/// <summary> /// <summary>
/// Writes a signed byte /// Writes a signed byte
/// </summary> /// </summary>

View File

@@ -46,15 +46,7 @@ namespace Lidgren.Network
internal void InitializePing() internal void InitializePing()
{ {
double now = NetTime.Now; m_timeoutDeadline = NetTime.Now + (m_peerConfiguration.m_connectionTimeout * 2.0); // initially allow a little more time
// 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 :-)
SendPing(); SendPing();
} }

View File

@@ -69,15 +69,8 @@ namespace Lidgren.Network
return; return;
// remove all callbacks regardless of sync context // remove all callbacks regardless of sync context
RestartRemoveCallbacks: m_receiveCallbacks.RemoveAll(tuple => tuple.Item2.Equals(callback));
for (int i = 0; i < m_receiveCallbacks.Count; i++)
{
if (m_receiveCallbacks[i].Item2.Equals(callback))
{
m_receiveCallbacks.RemoveAt(i);
goto RestartRemoveCallbacks;
}
}
if (m_receiveCallbacks.Count < 1) if (m_receiveCallbacks.Count < 1)
m_receiveCallbacks = null; m_receiveCallbacks = null;
} }

View File

@@ -1,4 +1,4 @@
#if __CONSTRAINED__ || UNITY_STANDALONE_LINUX #if __CONSTRAINED__ || UNITY_STANDALONE_LINUX || UNITY
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
@@ -27,9 +27,9 @@ namespace Lidgren.Network
public static IPAddress GetMyAddress(out IPAddress mask) public static IPAddress GetMyAddress(out IPAddress mask)
{ {
mask = null; mask = null;
#if UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_IOS
try try
{ {
#if UNITY_ANDROID || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_LINUX || UNITY_IOS || UNITY
if (!(UnityEngine.Application.internetReachability == UnityEngine.NetworkReachability.NotReachable)) if (!(UnityEngine.Application.internetReachability == UnityEngine.NetworkReachability.NotReachable))
{ {
return null; return null;