fix(houses): Converts house packets (1 of 2) (#502)
- [X] Adds `ToSpan()` for SpanWriter.
- [X] Moves house files to UOContent/Multis/Houses
- [X] Adds house packets
### SpanWriter.ToSpan()
`ToSpan()` returns an `SpanOwner` struct which allows access to the buffer as a Span by calling `Span`.
Example:
```cs
public SpanOwner CreatePacket()
{
var writer = new SpanWriter(0x400);
// write some stuff
return writer.ToSpan();
}
```
In this example, we are creating a packet and returning the `SpanOwner` for caching. This means in the future we can do something like this:
```cs
ns.Send(_cachedPacket.Span);
```
Where `_cachedPacket` is the `SpanOwner`
Notes:
Do not use a SpanWriter, or attempt to dispose of it after calling `ToSpan()`. Doing so will probably cause an NPE.
This commit is contained in:
parent
952a3e0265
commit
d070efeab3
14 changed files with 267 additions and 73 deletions
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
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).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendBeginHouseCustomization(serial);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x1001u)]
|
||||
public void TestEndHouseCustomization(uint serial)
|
||||
{
|
||||
var expected = new EndHouseCustomization(serial).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendEndHouseCustomization(serial);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x1001u, 0)]
|
||||
[InlineData(0x1001u, 100)]
|
||||
public void TestDesignStateGeneral(uint serial, int revision)
|
||||
{
|
||||
var expected = new DesignStateGeneral(serial, revision).Compile();
|
||||
|
||||
var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDesignStateGeneral(serial, revision);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Projects/UOContent.Tests/Tests/Multis/Houses/HousePackets.cs
Normal file
46
Projects/UOContent.Tests/Tests/Multis/Houses/HousePackets.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
namespace Server.Network
|
||||
{
|
||||
public class BeginHouseCustomization : Packet
|
||||
{
|
||||
public BeginHouseCustomization(Serial house) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(17);
|
||||
|
||||
Stream.Write((short)0x20);
|
||||
Stream.Write(house);
|
||||
Stream.Write((byte)0x04);
|
||||
Stream.Write((ushort)0x0000);
|
||||
Stream.Write((ushort)0xFFFF);
|
||||
Stream.Write((ushort)0xFFFF);
|
||||
Stream.Write((byte)0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public class EndHouseCustomization : Packet
|
||||
{
|
||||
public EndHouseCustomization(Serial house) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(17);
|
||||
|
||||
Stream.Write((short)0x20);
|
||||
Stream.Write(house);
|
||||
Stream.Write((byte)0x05);
|
||||
Stream.Write((ushort)0x0000);
|
||||
Stream.Write((ushort)0xFFFF);
|
||||
Stream.Write((ushort)0xFFFF);
|
||||
Stream.Write((byte)0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DesignStateGeneral : Packet
|
||||
{
|
||||
public DesignStateGeneral(Serial house, int revision) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(13);
|
||||
|
||||
Stream.Write((short)0x1D);
|
||||
Stream.Write(house);
|
||||
Stream.Write(revision);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue