* fixed 'Received a message that claimed a size larger than the packet, ending early' warning which caused clients to not load in properly

* removed unnecessary unsafe buffer copy from Transport.Send override
This commit is contained in:
Quentin Leon 2021-11-01 05:42:52 -07:00 коммит произвёл GitHub
Родитель b08829c71c
Коммит 93febe1faa
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 9 добавлений и 13 удалений

Просмотреть файл

@ -134,18 +134,14 @@ namespace Netcode.Transports.Facepunch
}
}
public override unsafe void Send(ulong clientId, ArraySegment<byte> data, NetworkDelivery delivery)
public override void Send(ulong clientId, ArraySegment<byte> data, NetworkDelivery delivery)
{
var sendType = NetworkDeliveryToSendType(delivery);
byte* buffer = stackalloc byte[data.Count];
fixed (byte* pointer = data.Array)
Buffer.MemoryCopy(pointer + data.Offset, buffer, data.Count, data.Count);
if (clientId == ServerClientId)
connectionManager.Connection.SendMessage((IntPtr)buffer, data.Count , sendType);
connectionManager.Connection.SendMessage(data.Array, data.Offset, data.Count, sendType);
else if (connectedClients.TryGetValue(clientId, out Client user))
user.connection.SendMessage((IntPtr)buffer, data.Count, sendType);
user.connection.SendMessage(data.Array, data.Offset, data.Count, sendType);
else if (LogLevel <= LogLevel.Normal)
Debug.LogWarning($"[{nameof(FacepunchTransport)}] - Failed to send packet to remote client with ID {clientId}, client not connected.");
}
@ -211,7 +207,7 @@ namespace Netcode.Transports.Facepunch
{
byte[] payload = new byte[size];
Marshal.Copy(data, payload, 0, size);
InvokeOnTransportEvent(NetworkEvent.Data, ServerClientId, new ArraySegment<byte>(payload, 0, size - 1), Time.realtimeSinceStartup);
InvokeOnTransportEvent(NetworkEvent.Data, ServerClientId, new ArraySegment<byte>(payload, 0, size), Time.realtimeSinceStartup);
}
#endregion