## 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
91 lines
2.5 KiB
C#
91 lines
2.5 KiB
C#
using System;
|
|
using Server.Network;
|
|
using Server.Targeting;
|
|
using Xunit;
|
|
|
|
namespace Server.Tests.Network
|
|
{
|
|
public class TestMultiTarget : MultiTarget
|
|
{
|
|
public TestMultiTarget(
|
|
int multiID,
|
|
Point3D offset,
|
|
int range = 10,
|
|
bool allowGround = true,
|
|
TargetFlags flags = TargetFlags.None
|
|
) : base(multiID, offset, range, allowGround, flags)
|
|
{
|
|
}
|
|
}
|
|
|
|
public class TestTarget : Target
|
|
{
|
|
public TestTarget(
|
|
int range,
|
|
bool allowGround,
|
|
TargetFlags flags
|
|
) : base(range, allowGround, flags)
|
|
{
|
|
}
|
|
}
|
|
|
|
public class TargetPacketsTests
|
|
{
|
|
[Fact]
|
|
public void TestMultiTargetReqHS()
|
|
{
|
|
var multiID = 0x1024;
|
|
var p = new Point3D(1000, 100, 10);
|
|
MultiTarget t = new TestMultiTarget(multiID, p);
|
|
|
|
var expected = new MultiTargetReqHS(t).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.ProtocolChanges |= ProtocolChanges.HighSeas;
|
|
ns.SendMultiTargetReq(t);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestMultiTargetReq()
|
|
{
|
|
var multiID = 0x1024;
|
|
var p = new Point3D(1000, 100, 10);
|
|
MultiTarget t = new TestMultiTarget(multiID, p);
|
|
|
|
var expected = new MultiTargetReq(t).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMultiTargetReq(t);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestCancelTarget()
|
|
{
|
|
var expected = new CancelTarget().Compile();
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendCancelTarget();
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestTargetReq()
|
|
{
|
|
var t = new TestTarget(10, true, TargetFlags.Beneficial);
|
|
var expected = new TargetReq(t).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendTargetReq(t);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
}
|
|
}
|