## Breaking Changes
Incoming packet registration signature has changed to:
```cs
delegate* void OnReceiveCallback(NetState state, SpanReader reader, int packetLength);
IncomingPackets.Register(int packetID, int length, bool ingame, OnReceiveCallback onReceive);
```
For example, an incoming packet handler signature would now look like this:
```cs
public static void SomeIncomingPacket(NetState state, SpanReader reader, int packetLength)
{
// Parse the data
}
```
## Summary
Updates the network Pipe class to use a mirrored memory technique. This technique involves mapping the same physical memory to two contiguous virtual memory spaces so the byte buffer appears duplicated. This allows writing to a double-sized array to wrap around without the need for the `CircularBuffer` classes.
In practice this allows us to use `Span<byte>` as if the buffer was a regular array.
### Bug Fixes
- [X] Fixes bad fixed length string parsing
81 lines
2.4 KiB
C#
81 lines
2.4 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Server;
|
|
using Server.Multis;
|
|
using Server.Network;
|
|
using Server.Tests;
|
|
using Server.Tests.Network;
|
|
using Xunit;
|
|
|
|
namespace UOContent.Tests
|
|
{
|
|
public class HousePacketTests
|
|
{
|
|
[Theory]
|
|
[InlineData(0x1001u)]
|
|
public void TestBeginHouseCustomization(uint serial)
|
|
{
|
|
var expected = new BeginHouseCustomization((Serial)serial).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendBeginHouseCustomization((Serial)serial);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0x1001u)]
|
|
public void TestEndHouseCustomization(uint serial)
|
|
{
|
|
var expected = new EndHouseCustomization((Serial)serial).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendEndHouseCustomization((Serial)serial);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0x1001u, 0)]
|
|
[InlineData(0x1001u, 100)]
|
|
public void TestDesignStateGeneral(uint serial, int revision)
|
|
{
|
|
var expected = new DesignStateGeneral((Serial)serial, revision).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendDesignStateGeneral((Serial)serial, revision);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestHouseDesignStateDetailed()
|
|
{
|
|
Serial serial = (Serial)0x40000001;
|
|
var revision = 10;
|
|
var tiles = new MultiTileEntry[250];
|
|
for (var i = 0; i < tiles.Length; i++)
|
|
{
|
|
tiles[i] = new MultiTileEntry(
|
|
(ushort)i,
|
|
(byte)i,
|
|
(byte)i,
|
|
(byte)(i / 50),
|
|
TileFlag.None
|
|
);
|
|
}
|
|
var mcl = new MultiComponentList(tiles.ToList());
|
|
|
|
var expected = new DesignStateDetailed(
|
|
serial, revision, mcl.Min.X, mcl.Min.Y, mcl.Max.X, mcl.Max.Y, tiles
|
|
).Compile();
|
|
|
|
var actual = HousePackets.CreateHouseDesignStateDetailed(serial, revision, mcl);
|
|
|
|
AssertThat.Equal(actual, expected);
|
|
}
|
|
}
|
|
}
|