## 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
119 lines
3.5 KiB
C#
119 lines
3.5 KiB
C#
using System;
|
|
using Server;
|
|
using Server.Engines.Mahjong;
|
|
using Server.Tests;
|
|
using Server.Tests.Network;
|
|
using Xunit;
|
|
|
|
namespace UOContent.Tests
|
|
{
|
|
[Collection("Sequential Tests")]
|
|
public class MahjongPacketTests : IClassFixture<ServerFixture>
|
|
{
|
|
[Fact]
|
|
public void TestMahjongJoinGame()
|
|
{
|
|
Serial game = (Serial)0x1024u;
|
|
|
|
var expected = new MahjongJoinGame(game).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMahjongJoinGame(game);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void TestMahjongPlayersInfo(bool showScores)
|
|
{
|
|
var m = new Mobile((Serial)0x1);
|
|
m.DefaultMobileInit();
|
|
|
|
var game = new MahjongGame { ShowScores = showScores };
|
|
game.Players.Join(m);
|
|
|
|
var expected = new MahjongPlayersInfo(game, m).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMahjongPlayersInfo(game, m);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true, true)]
|
|
[InlineData(true, false)]
|
|
[InlineData(false, true)]
|
|
[InlineData(false, false)]
|
|
public void TestMahjongGeneralInfo(bool showScores, bool spectatorVision)
|
|
{
|
|
var game = new MahjongGame { ShowScores = showScores, SpectatorVision = spectatorVision};
|
|
|
|
var expected = new MahjongGeneralInfo(game).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMahjongGeneralInfo(game);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void TestMahjongTilesInfo(bool spectatorVision)
|
|
{
|
|
var m = new Mobile((Serial)0x1);
|
|
m.DefaultMobileInit();
|
|
|
|
var game = new MahjongGame { SpectatorVision = spectatorVision };
|
|
game.Players.Join(m);
|
|
|
|
var expected = new MahjongTilesInfo(game, m).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMahjongTilesInfo(game, m);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void TestMahjongTileInfo(bool spectatorVision)
|
|
{
|
|
var m = new Mobile((Serial)0x1);
|
|
m.DefaultMobileInit();
|
|
|
|
var game = new MahjongGame { SpectatorVision = spectatorVision };
|
|
game.Players.Join(m);
|
|
|
|
var expected = new MahjongTileInfo(game.Tiles[0], m).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMahjongTileInfo(game.Tiles[0], m);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestMahjongRelieve()
|
|
{
|
|
Serial game = (Serial)0x1024u;
|
|
|
|
var expected = new MahjongRelieve(game).Compile();
|
|
|
|
var ns = PacketTestUtilities.CreateTestNetState();
|
|
ns.SendMahjongRelieve(game);
|
|
|
|
var result = ns.SendPipe.Reader.AvailableToRead();
|
|
AssertThat.Equal(result, expected);
|
|
}
|
|
}
|
|
}
|