com.unity.netcode.gameobjects@1.3.1

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).

## [1.3.1] - 2023-03-27

### Added

- Added detection and graceful handling of corrupt packets for additional safety. (#2419)

### Changed

- The UTP component UI has been updated to be more user-friendly for new users by adding a simple toggle to switch between local-only (127.0.0.1) and remote (0.0.0.0) binding modes, using the toggle "Allow Remote Connections" (#2408)
- Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.3. (#2450)
- `NetworkShow()` of `NetworkObject`s are delayed until the end of the frame to ensure consistency of delta-driven variables like `NetworkList`.
- Dirty `NetworkObject` are reset at end-of-frame and not at serialization time.
- `NetworkHide()` of an object that was just `NetworkShow()`n produces a warning, as remote clients will _not_ get a spawn/despawn pair.
- Renamed the NetworkTransform.SetState parameter `shouldGhostsInterpolate` to `teleportDisabled` for better clarity of what that parameter does. (#2228)
- Network prefabs are now stored in a ScriptableObject that can be shared between NetworkManagers, and have been exposed for public access. By default, a Default Prefabs List is created that contains all NetworkObject prefabs in the project, and new NetworkManagers will default to using that unless that option is turned off in the Netcode for GameObjects settings. Existing NetworkManagers will maintain their existing lists, which can be migrated to the new format via a button in their inspector. (#2322)

### Fixed

- Fixed issue where changes to a layer's weight would not synchronize unless a state transition was occurring.(#2399)
- Fixed issue where `NetworkManager.LocalClientId` was returning the `NetworkTransport.ServerClientId` as opposed to the `NetworkManager.m_LocalClientId`. (#2398)
- Fixed issue where a dynamically spawned `NetworkObject` parented under an in-scene placed `NetworkObject` would have its `InScenePlaced` value changed to `true`. This would result in a soft synchronization error for late joining clients. (#2396)
- Fixed a UTP test that was failing when you install Unity Transport package 2.0.0 or newer. (#2347)
- Fixed issue where `NetcodeSettingsProvider` would throw an exception in Unity 2020.3.x versions. (#2345)
- Fixed server side issue where, depending upon component ordering, some NetworkBehaviour components might not have their OnNetworkDespawn method invoked if the client side disconnected. (#2323)
- Fixed a case where data corruption could occur when using UnityTransport when reaching a certain level of send throughput. (#2332)
- Fixed an issue in `UnityTransport` where an exception would be thrown if starting a Relay host/server on WebGL. This exception should only be thrown if using direct connections (where WebGL can't act as a host/server). (#2321)
- Fixed `NetworkAnimator` issue where it was not checking for `AnimatorStateTtansition.destinationStateMachine` and any possible sub-states defined within it. (#2309)
- Fixed `NetworkAnimator` issue where the host client was receiving the ClientRpc animation updates when the host was the owner.(#2309)
- Fixed `NetworkAnimator` issue with using pooled objects and when specific properties are cleaned during despawn and destroy.(#2309)
- Fixed issue where `NetworkAnimator` was checking for animation changes when the associated `NetworkObject` was not spawned.(#2309)
- Corrected an issue with the documentation for BufferSerializer (#2401)
This commit is contained in:
Unity Technologies
2023-03-27 00:00:00 +00:00
parent fe02ca682e
commit 8060718e04
69 changed files with 3128 additions and 888 deletions

View File

@@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.TestTools;
namespace Unity.Netcode.EditorTests
{
public class MessageCorruptionTests
{
private struct TestMessage : INetworkMessage, INetworkSerializeByMemcpy
{
public ForceNetworkSerializeByMemcpy<Guid> Value;
public static bool Handled;
public static bool Deserialized;
public void Serialize(FastBufferWriter writer, int targetVersion)
{
writer.WriteValueSafe(Value);
}
public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int receivedMessageVersion)
{
Deserialized = true;
reader.ReadValueSafe(out Value);
return true;
}
public void Handle(ref NetworkContext context)
{
Handled = true;
}
public int Version => 0;
}
private class TestMessageProvider : IMessageProvider
{
public List<MessagingSystem.MessageWithHandler> GetMessages()
{
return new List<MessagingSystem.MessageWithHandler>
{
new MessagingSystem.MessageWithHandler
{
MessageType = typeof(TestMessage),
Handler = MessagingSystem.ReceiveMessage<TestMessage>,
GetVersion = MessagingSystem.CreateMessageAndGetVersion<TestMessage>
}
};
}
}
public enum TypeOfCorruption
{
OffsetPlus,
OffsetMinus,
CorruptBytes,
Truncated,
AdditionalGarbageData,
}
private class TestMessageSender : IMessageSender
{
public TypeOfCorruption Corruption;
public List<byte[]> MessageQueue = new List<byte[]>();
public unsafe void Send(ulong clientId, NetworkDelivery delivery, FastBufferWriter batchData)
{
switch (Corruption)
{
case TypeOfCorruption.OffsetPlus:
{
using var subWriter = new FastBufferWriter(batchData.Length + 1, Allocator.Temp);
subWriter.WriteByteSafe(0);
subWriter.WriteBytesSafe(batchData.GetUnsafePtr(), batchData.Length);
MessageQueue.Add(subWriter.ToArray());
break;
}
case TypeOfCorruption.OffsetMinus:
{
using var subWriter = new FastBufferWriter(batchData.Length - 1, Allocator.Temp);
subWriter.WriteBytesSafe(batchData.GetUnsafePtr() + 1, batchData.Length - 1);
MessageQueue.Add(subWriter.ToArray());
break;
}
case TypeOfCorruption.CorruptBytes:
batchData.Seek(batchData.Length - 2);
var currentByte = batchData.GetUnsafePtr()[0];
batchData.WriteByteSafe((byte)(currentByte == 0 ? 1 : 0));
MessageQueue.Add(batchData.ToArray());
break;
case TypeOfCorruption.Truncated:
batchData.Truncate(batchData.Length - 1);
MessageQueue.Add(batchData.ToArray());
break;
case TypeOfCorruption.AdditionalGarbageData:
batchData.Seek(batchData.Length);
batchData.WriteByteSafe(0);
MessageQueue.Add(batchData.ToArray());
break;
}
}
}
private MessagingSystem m_MessagingSystem;
private TestMessageSender m_MessageSender;
[SetUp]
public void SetUp()
{
TestMessage.Handled = false;
TestMessage.Deserialized = false;
m_MessageSender = new TestMessageSender();
m_MessagingSystem = new MessagingSystem(m_MessageSender, this, new TestMessageProvider());
m_MessagingSystem.ClientConnected(0);
m_MessagingSystem.SetVersion(0, XXHash.Hash32(typeof(TestMessage).FullName), 0);
}
[TearDown]
public void TearDown()
{
m_MessagingSystem.Dispose();
}
private TestMessage GetMessage()
{
return new TestMessage
{
Value = Guid.NewGuid()
};
}
[Test]
public unsafe void WhenPacketsAreCorrupted_TheyDontGetProcessed([Values] TypeOfCorruption typeOfCorruption)
{
m_MessageSender.Corruption = typeOfCorruption;
switch (typeOfCorruption)
{
case TypeOfCorruption.OffsetMinus:
case TypeOfCorruption.OffsetPlus:
LogAssert.Expect(LogType.Error, new Regex("Received a packet with an invalid Magic Value\\."));
break;
case TypeOfCorruption.Truncated:
case TypeOfCorruption.AdditionalGarbageData:
LogAssert.Expect(LogType.Error, new Regex("Received a packet with an invalid Batch Size Value\\."));
break;
case TypeOfCorruption.CorruptBytes:
LogAssert.Expect(LogType.Error, new Regex("Received a packet with an invalid Hash Value\\."));
break;
}
// Dummy batch header
var batchHeader = new BatchHeader
{
BatchCount = 1
};
var messageHeader = new MessageHeader
{
MessageSize = (ushort)UnsafeUtility.SizeOf<TestMessage>(),
MessageType = m_MessagingSystem.GetMessageType(typeof(TestMessage)),
};
var message = GetMessage();
var writer = new FastBufferWriter(1300, Allocator.Temp);
using (writer)
{
writer.TryBeginWrite(FastBufferWriter.GetWriteSize(batchHeader) +
FastBufferWriter.GetWriteSize(messageHeader) +
FastBufferWriter.GetWriteSize(message));
writer.WriteValue(batchHeader);
writer.WriteValue(messageHeader);
writer.WriteValue(message);
// Fill out the rest of the batch header
writer.Seek(0);
batchHeader = new BatchHeader
{
Magic = BatchHeader.MagicValue,
BatchSize = writer.Length,
BatchHash = XXHash.Hash64(writer.GetUnsafePtr() + sizeof(BatchHeader), writer.Length - sizeof(BatchHeader)),
BatchCount = 1
};
writer.WriteValue(batchHeader);
m_MessageSender.Send(0, NetworkDelivery.Reliable, writer);
var receivedMessage = m_MessageSender.MessageQueue[0];
m_MessageSender.MessageQueue.Clear();
m_MessagingSystem.HandleIncomingData(0, new ArraySegment<byte>(receivedMessage), 0);
Assert.IsFalse(TestMessage.Deserialized);
Assert.IsFalse(TestMessage.Handled);
}
}
}
}