Converts secure trade packets (#329)
This commit is contained in:
parent
77f665502b
commit
8c4c30da7d
4 changed files with 184 additions and 184 deletions
|
|
@ -8,8 +8,9 @@ namespace Server.Tests.Network
|
|||
{
|
||||
public class SecureTradePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory, InlineData("short-name"),
|
||||
InlineData("this is a really long name that is more than 30 characters, probably")]
|
||||
[Theory]
|
||||
[InlineData("short-name")]
|
||||
[InlineData("this is a really long name that is more than 30 characters, probably")]
|
||||
public void TestDisplaySecureTrade(string name)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
|
|
@ -18,26 +19,13 @@ namespace Server.Tests.Network
|
|||
var firstCont = new Container(World.NewItem);
|
||||
var secondCont = new Container(World.NewItem);
|
||||
|
||||
var data = new DisplaySecureTrade(m, firstCont, secondCont, name).Compile();
|
||||
var expected = new DisplaySecureTrade(m, firstCont, secondCont, name).Compile();
|
||||
|
||||
var hasName = name.Length > 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplaySecureTrade(m, firstCont, secondCont, name);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[17 + (hasName ? 30 : 0)];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6F); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x2F); // Length
|
||||
expectedData.Write(ref pos, (byte)TradeFlag.Display); // Command
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, firstCont.Serial);
|
||||
expectedData.Write(ref pos, secondCont.Serial);
|
||||
expectedData.Write(ref pos, hasName);
|
||||
if (hasName)
|
||||
{
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -45,17 +33,13 @@ namespace Server.Tests.Network
|
|||
{
|
||||
var cont = new Container(World.NewItem);
|
||||
|
||||
var data = new CloseSecureTrade(cont).Compile();
|
||||
var expected = new CloseSecureTrade(cont).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendCloseSecureTrade(cont);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6F); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x8); // Length
|
||||
expectedData.Write(ref pos, (byte)TradeFlag.Close); // Command
|
||||
expectedData.Write(ref pos, cont.Serial);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(true, false), InlineData(false, true)]
|
||||
|
|
@ -67,38 +51,28 @@ namespace Server.Tests.Network
|
|||
var secondCont = new Container(World.NewItem);
|
||||
|
||||
var cont = first ? firstCont : secondCont;
|
||||
var data = new UpdateSecureTrade(cont, first, second).Compile();
|
||||
var expected = new UpdateSecureTrade(cont, first, second).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendUpdateSecureTrade(cont, first, second);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6F); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x10); // Length
|
||||
expectedData.Write(ref pos, (byte)TradeFlag.Update); // Command
|
||||
expectedData.Write(ref pos, cont.Serial);
|
||||
expectedData.Write(ref pos, first ? 1 : 0); // true if first
|
||||
expectedData.Write(ref pos, second ? 1 : 0); // true if second
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(100000, 30, TradeFlag.UpdateGold), InlineData(250000, 50000, TradeFlag.UpdateLedger)]
|
||||
[Theory]
|
||||
[InlineData(100000, 30, TradeFlag.UpdateGold)]
|
||||
[InlineData(250000, 50000, TradeFlag.UpdateLedger)]
|
||||
public void TestUpdateGoldSecureTrade(int gold, int plat, TradeFlag flag)
|
||||
{
|
||||
var cont = new Container(World.NewItem);
|
||||
var data = new UpdateSecureTrade(cont, flag, gold, plat).Compile();
|
||||
var expected = new UpdateSecureTrade(cont, flag, gold, plat).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendUpdateSecureTrade(cont, flag, gold, plat);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6F); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x10); // Length
|
||||
expectedData.Write(ref pos, (byte)flag); // Command
|
||||
expectedData.Write(ref pos, cont.Serial);
|
||||
expectedData.Write(ref pos, gold);
|
||||
expectedData.Write(ref pos, plat);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -110,25 +84,13 @@ namespace Server.Tests.Network
|
|||
var cont = new Container(World.NewItem);
|
||||
var itemInCont = new Item(World.NewItem) { Parent = cont };
|
||||
|
||||
var data = new SecureTradeEquip(itemInCont, m).Compile();
|
||||
Span<byte> expectedData = stackalloc byte[20];
|
||||
var pos = 0;
|
||||
var expected = new SecureTradeEquip(itemInCont, m).Compile();
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x25); // Packet ID
|
||||
expectedData.Write(ref pos, itemInCont.Serial);
|
||||
expectedData.Write(ref pos, (short)itemInCont.ItemID);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (short)itemInCont.Amount);
|
||||
expectedData.Write(ref pos, (short)itemInCont.X);
|
||||
expectedData.Write(ref pos, (short)itemInCont.Y);
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, (short)itemInCont.Hue);
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSecureTradeEquip(itemInCont, m);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -140,31 +102,15 @@ namespace Server.Tests.Network
|
|||
var cont = new Container(World.NewItem);
|
||||
var itemInCont = new Item(World.NewItem) { Parent = cont };
|
||||
|
||||
var data = new SecureTradeEquip6017(itemInCont, m).Compile();
|
||||
var expected = new SecureTradeEquip6017(itemInCont, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[21];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges |= ProtocolChanges.ContainerGridLines;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x25); // Packet ID
|
||||
expectedData.Write(ref pos, itemInCont.Serial);
|
||||
expectedData.Write(ref pos, (short)itemInCont.ItemID);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (short)itemInCont.Amount);
|
||||
expectedData.Write(ref pos, (short)itemInCont.X);
|
||||
expectedData.Write(ref pos, (short)itemInCont.Y);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, (short)itemInCont.Hue);
|
||||
ns.SendSecureTradeEquip(itemInCont, m);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue