mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Transport.MaxPacketSize moved to TransportLayer.GetMaxPacketSize because it depends on the layer
This commit is contained in:
parent
7056ccd428
commit
1289dee8b3
@ -174,9 +174,9 @@ protected virtual bool SendBytes( byte[] bytes, int channelId = Channels.Default
|
||||
{
|
||||
if (logNetworkMessages) { Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + BitConverter.ToString(bytes)); }
|
||||
|
||||
if (bytes.Length > Transport.MaxPacketSize)
|
||||
if (bytes.Length > Transport.layer.GetMaxPacketSize())
|
||||
{
|
||||
Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + Transport.MaxPacketSize + " bytes");
|
||||
Debug.LogError("NetworkConnection:SendBytes cannot send packet larger than " + Transport.layer.GetMaxPacketSize() + " bytes");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public sealed class NetworkIdentity : MonoBehaviour
|
||||
public bool localPlayerAuthority { get { return m_LocalPlayerAuthority; } set { m_LocalPlayerAuthority = value; } }
|
||||
public NetworkConnection clientAuthorityOwner { get { return m_ClientAuthorityOwner; }}
|
||||
|
||||
public NetworkBehaviour[] NetworkBehaviours
|
||||
public NetworkBehaviour[] NetworkBehaviours
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -425,7 +425,7 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo
|
||||
|
||||
// original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might
|
||||
// be useful for debugging.
|
||||
if (bytes.Length > Transport.MaxPacketSize)
|
||||
if (bytes.Length > Transport.layer.GetMaxPacketSize())
|
||||
{
|
||||
Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp);
|
||||
}
|
||||
@ -612,7 +612,7 @@ internal void HandleCommand(int componentIndex, int cmdHash, NetworkReader reade
|
||||
return;
|
||||
}
|
||||
NetworkBehaviour invokeComponent = m_NetworkBehaviours[componentIndex];
|
||||
|
||||
|
||||
invokeFunction(invokeComponent, reader);
|
||||
}
|
||||
|
||||
|
@ -72,9 +72,9 @@ public void WriteBytesAndSize(byte[] buffer, int offset, int count)
|
||||
writer.Write(false); // notNull?
|
||||
return;
|
||||
}
|
||||
if (count > Transport.MaxPacketSize)
|
||||
if (count > Transport.layer.GetMaxPacketSize())
|
||||
{
|
||||
Debug.LogError("NetworkWriter WriteBytesAndSize: size is too large (" + count + ") bytes. The maximum buffer size is " + Transport.MaxPacketSize + " bytes.");
|
||||
Debug.LogError("NetworkWriter WriteBytesAndSize: size is too large (" + count + ") bytes. The maximum buffer size is " + Transport.layer.GetMaxPacketSize() + " bytes.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ namespace Mirror
|
||||
public class LLAPITransport : TransportLayer
|
||||
{
|
||||
readonly ConnectionConfig connectionConfig;
|
||||
readonly GlobalConfig globalConfig;
|
||||
readonly int channelId; // always use first channel
|
||||
byte error;
|
||||
|
||||
@ -36,6 +37,7 @@ public LLAPITransport(GlobalConfig globalConfig = null, ConnectionConfig connect
|
||||
globalConfig.MinTimerTimeout = 1;
|
||||
globalConfig.MaxTimerTimeout = 12000;
|
||||
}
|
||||
this.globalConfig = globalConfig;
|
||||
NetworkTransport.Init(globalConfig);
|
||||
|
||||
// create connection config if none passed
|
||||
@ -257,5 +259,10 @@ public void Shutdown()
|
||||
clientConnectionId = -1;
|
||||
Debug.Log("LLAPITransport.Shutdown");
|
||||
}
|
||||
|
||||
public int GetMaxPacketSize()
|
||||
{
|
||||
return globalConfig.MaxPacketSize;
|
||||
}
|
||||
}
|
||||
}
|
@ -100,5 +100,11 @@ public virtual void Shutdown()
|
||||
client.Disconnect();
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
public int GetMaxPacketSize()
|
||||
{
|
||||
// Telepathy's limit is Array.Length, which is int
|
||||
return int.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
@ -116,5 +116,12 @@ public void Shutdown()
|
||||
client.Shutdown();
|
||||
if (server != null) server.Shutdown();
|
||||
}
|
||||
|
||||
public int GetMaxPacketSize()
|
||||
{
|
||||
if (server != null) return server.GetMaxPacketSize();
|
||||
if (client != null) return client.GetMaxPacketSize();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,6 @@ namespace Mirror
|
||||
// Transport class used by HLAPI ///////////////////////////////////////////
|
||||
public static class Transport
|
||||
{
|
||||
// hlapi needs to know max packet size to show warnings
|
||||
public static int MaxPacketSize = ushort.MaxValue;
|
||||
|
||||
// selected transport layer
|
||||
// the transport is normally initialized in NetworkManager InitializeTransport
|
||||
// initialize it yourself if you are not using NetworkManager
|
||||
@ -39,5 +36,6 @@ public interface TransportLayer
|
||||
|
||||
// common
|
||||
void Shutdown();
|
||||
int GetMaxPacketSize();
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ public void TestWritingLargeMessage()
|
||||
[Test]
|
||||
public void TestWritingHugeArray()
|
||||
{
|
||||
Transport.MaxPacketSize = 1000000;
|
||||
// try serializing array > 64KB and see what happens
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
writer.WriteBytesAndSize(new byte[100000]);
|
||||
|
Loading…
Reference in New Issue
Block a user