Formats UO Content (#201)
This commit is contained in:
parent
86b7b3aed1
commit
ad3775c4d7
3249 changed files with 431083 additions and 440981 deletions
|
|
@ -1,39 +1,39 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public static class AttributeNormalizerUtilities
|
||||
{
|
||||
public static void WriteAttribute(this Span<byte> data, ref int pos, int cur, int max, bool normalize)
|
||||
{
|
||||
if (normalize && AttributeNormalizer.Enabled && max != 0)
|
||||
{
|
||||
int maximum = AttributeNormalizer.Maximum;
|
||||
|
||||
data.Write(ref pos, (ushort)maximum);
|
||||
data.Write(ref pos, (ushort)(cur * maximum / max));
|
||||
return;
|
||||
}
|
||||
|
||||
data.Write(ref pos, (ushort)max);
|
||||
data.Write(ref pos, (ushort)cur);
|
||||
}
|
||||
|
||||
public static void WriteReverseAttribute(this Span<byte> data, ref int pos, int cur, int max, bool normalize)
|
||||
{
|
||||
if (normalize && AttributeNormalizer.Enabled && max != 0)
|
||||
{
|
||||
int maximum = AttributeNormalizer.Maximum;
|
||||
|
||||
data.Write(ref pos, (ushort)(cur * maximum / max));
|
||||
data.Write(ref pos, (ushort)maximum);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Write(ref pos, (ushort)cur);
|
||||
data.Write(ref pos, (ushort)max);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public static class AttributeNormalizerUtilities
|
||||
{
|
||||
public static void WriteAttribute(this Span<byte> data, ref int pos, int cur, int max, bool normalize)
|
||||
{
|
||||
if (normalize && AttributeNormalizer.Enabled && max != 0)
|
||||
{
|
||||
var maximum = AttributeNormalizer.Maximum;
|
||||
|
||||
data.Write(ref pos, (ushort)maximum);
|
||||
data.Write(ref pos, (ushort)(cur * maximum / max));
|
||||
return;
|
||||
}
|
||||
|
||||
data.Write(ref pos, (ushort)max);
|
||||
data.Write(ref pos, (ushort)cur);
|
||||
}
|
||||
|
||||
public static void WriteReverseAttribute(this Span<byte> data, ref int pos, int cur, int max, bool normalize)
|
||||
{
|
||||
if (normalize && AttributeNormalizer.Enabled && max != 0)
|
||||
{
|
||||
var maximum = AttributeNormalizer.Maximum;
|
||||
|
||||
data.Write(ref pos, (ushort)(cur * maximum / max));
|
||||
data.Write(ref pos, (ushort)maximum);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Write(ref pos, (ushort)cur);
|
||||
data.Write(ref pos, (ushort)max);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,43 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public static class GumpUtilities
|
||||
{
|
||||
public static readonly byte[] NoMoveBuffer = Encoding.ASCII.GetBytes("{ nomove }");
|
||||
public static readonly byte[] NoCloseBuffer = Encoding.ASCII.GetBytes("{ noclose }");
|
||||
public static readonly byte[] NoDisposeBuffer = Encoding.ASCII.GetBytes("{ nodispose }");
|
||||
public static readonly byte[] NoResizeBuffer = Encoding.ASCII.GetBytes("{ noresize }");
|
||||
|
||||
public const string NoMove = "{ nomove }";
|
||||
public const string NoClose = "{ noclose }";
|
||||
public const string NoDispose = "{ nodispose }";
|
||||
public const string NoResize = "{ noresize }";
|
||||
|
||||
public static void WritePacked(this Span<byte> dest, ref int pos, ReadOnlySpan<byte> source)
|
||||
{
|
||||
int length = source.Length;
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
#if NO_LOCAL_INIT
|
||||
dest.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
ulong packLength = (ulong)dest.Length - 8;
|
||||
|
||||
ZlibError ce = Zlib.Pack(dest.Slice(pos + 8), ref packLength, source, ZlibQuality.Default);
|
||||
if (ce != ZlibError.Okay) Console.WriteLine("ZLib error: {0} (#{1})", ce, (int)ce);
|
||||
|
||||
dest.Write(ref pos, (int)(4 + packLength));
|
||||
dest.Write(ref pos, length);
|
||||
pos += (int)packLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public static class GumpUtilities
|
||||
{
|
||||
public const string NoMove = "{ nomove }";
|
||||
public const string NoClose = "{ noclose }";
|
||||
public const string NoDispose = "{ nodispose }";
|
||||
public const string NoResize = "{ noresize }";
|
||||
public static readonly byte[] NoMoveBuffer = Encoding.ASCII.GetBytes("{ nomove }");
|
||||
public static readonly byte[] NoCloseBuffer = Encoding.ASCII.GetBytes("{ noclose }");
|
||||
public static readonly byte[] NoDisposeBuffer = Encoding.ASCII.GetBytes("{ nodispose }");
|
||||
public static readonly byte[] NoResizeBuffer = Encoding.ASCII.GetBytes("{ noresize }");
|
||||
|
||||
public static void WritePacked(this Span<byte> dest, ref int pos, ReadOnlySpan<byte> source)
|
||||
{
|
||||
var length = source.Length;
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
#if NO_LOCAL_INIT
|
||||
dest.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
var packLength = (ulong)dest.Length - 8;
|
||||
|
||||
ZlibError ce = Zlib.Pack(dest.Slice(pos + 8), ref packLength, source, ZlibQuality.Default);
|
||||
if (ce != ZlibError.Okay) Console.WriteLine("ZLib error: {0} (#{1})", ce, (int)ce);
|
||||
|
||||
dest.Write(ref pos, (int)(4 + packLength));
|
||||
dest.Write(ref pos, length);
|
||||
pos += (int)packLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,90 +1,90 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class ArrowPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestCancelArrow()
|
||||
{
|
||||
Span<byte> data = new CancelArrow().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0); // Command
|
||||
expectedData.Write(ref pos, 0xFFFFFFFF); // X, Y
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(100, 10)]
|
||||
[InlineData(100000, 100000)]
|
||||
public void TestSetArrow(int x, int y)
|
||||
{
|
||||
Span<byte> data = new SetArrow(x, y).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, (ushort)x);
|
||||
expectedData.Write(ref pos, (ushort)y);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(100, 10)]
|
||||
[InlineData(100000, 100000)]
|
||||
public void TestCancelArrowHS(int x, int y)
|
||||
{
|
||||
Serial serial = 0x01;
|
||||
Span<byte> data = new CancelArrowHS(x, y, serial).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[10];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Command
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)x);
|
||||
expectedData.Write(ref pos, (ushort)y);
|
||||
expectedData.Write(ref pos, serial);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(100, 10)]
|
||||
[InlineData(100000, 100000)]
|
||||
public void TestSetArrowHS(int x, int y)
|
||||
{
|
||||
Serial serial = 0x01;
|
||||
Span<byte> data = new SetArrowHS(x, y, serial).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[10];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, (ushort)x);
|
||||
expectedData.Write(ref pos, (ushort)y);
|
||||
expectedData.Write(ref pos, serial);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class ArrowPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestCancelArrow()
|
||||
{
|
||||
var data = new CancelArrow().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0); // Command
|
||||
expectedData.Write(ref pos, 0xFFFFFFFF); // X, Y
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(100, 10)]
|
||||
[InlineData(100000, 100000)]
|
||||
public void TestSetArrow(int x, int y)
|
||||
{
|
||||
var data = new SetArrow(x, y).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, (ushort)x);
|
||||
expectedData.Write(ref pos, (ushort)y);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(100, 10)]
|
||||
[InlineData(100000, 100000)]
|
||||
public void TestCancelArrowHS(int x, int y)
|
||||
{
|
||||
Serial serial = 0x01;
|
||||
var data = new CancelArrowHS(x, y, serial).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[10];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Command
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)x);
|
||||
expectedData.Write(ref pos, (ushort)y);
|
||||
expectedData.Write(ref pos, serial);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(100, 10)]
|
||||
[InlineData(100000, 100000)]
|
||||
public void TestSetArrowHS(int x, int y)
|
||||
{
|
||||
Serial serial = 0x01;
|
||||
var data = new SetArrowHS(x, y, serial).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[10];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBA); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, (ushort)x);
|
||||
expectedData.Write(ref pos, (ushort)y);
|
||||
expectedData.Write(ref pos, serial);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,92 +1,92 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class AttributeNormalizerTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerEnabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = true;
|
||||
AttributeNormalizer.Maximum = 25;
|
||||
|
||||
PacketWriter stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.Write(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (ushort)AttributeNormalizer.Maximum);
|
||||
expectedData.Write(ref pos, (ushort)(cur * 25 / max));
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerReversedEnabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = true;
|
||||
AttributeNormalizer.Maximum = 25;
|
||||
|
||||
PacketWriter stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.WriteReverse(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (ushort)(cur * 25 / max));
|
||||
expectedData.Write(ref pos, (ushort)AttributeNormalizer.Maximum);
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerDisabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = false;
|
||||
|
||||
PacketWriter stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.Write(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, max);
|
||||
expectedData.Write(ref pos, cur);
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerReversedDisabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = false;
|
||||
|
||||
PacketWriter stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.WriteReverse(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, cur);
|
||||
expectedData.Write(ref pos, max);
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class AttributeNormalizerTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerEnabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = true;
|
||||
AttributeNormalizer.Maximum = 25;
|
||||
|
||||
var stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.Write(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (ushort)AttributeNormalizer.Maximum);
|
||||
expectedData.Write(ref pos, (ushort)(cur * 25 / max));
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerReversedEnabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = true;
|
||||
AttributeNormalizer.Maximum = 25;
|
||||
|
||||
var stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.WriteReverse(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (ushort)(cur * 25 / max));
|
||||
expectedData.Write(ref pos, (ushort)AttributeNormalizer.Maximum);
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerDisabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = false;
|
||||
|
||||
var stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.Write(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, max);
|
||||
expectedData.Write(ref pos, cur);
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAttributeNormalizerReversedDisabled()
|
||||
{
|
||||
AttributeNormalizer.Enabled = false;
|
||||
|
||||
var stream = new PacketWriter(4);
|
||||
|
||||
const ushort cur = 50;
|
||||
const ushort max = 100;
|
||||
|
||||
AttributeNormalizer.WriteReverse(stream, cur, max);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, cur);
|
||||
expectedData.Write(ref pos, max);
|
||||
|
||||
AssertThat.Equal(stream.ToArray(), expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,80 +1,80 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class CombatPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestSwing()
|
||||
{
|
||||
Serial attacker = 0x1000;
|
||||
Serial defender = 0x2000;
|
||||
|
||||
Span<byte> data = new Swing(attacker, defender).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[10];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x2F); // Packet ID
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, attacker);
|
||||
expectedData.Write(ref pos, defender);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void TestSetWarMode(bool warmode)
|
||||
{
|
||||
Span<byte> data = new SetWarMode(warmode).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x72); // Packet ID
|
||||
expectedData.Write(ref pos, warmode);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x32);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestChangeCombatant()
|
||||
{
|
||||
Serial combatant = 0x1000;
|
||||
|
||||
Span<byte> data = new ChangeCombatant(combatant).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xAA); // Packet ID
|
||||
expectedData.Write(ref pos, combatant);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class CombatPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestSwing()
|
||||
{
|
||||
Serial attacker = 0x1000;
|
||||
Serial defender = 0x2000;
|
||||
|
||||
var data = new Swing(attacker, defender).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[10];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x2F); // Packet ID
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, attacker);
|
||||
expectedData.Write(ref pos, defender);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void TestSetWarMode(bool warmode)
|
||||
{
|
||||
var data = new SetWarMode(warmode).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x72); // Packet ID
|
||||
expectedData.Write(ref pos, warmode);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x32);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestChangeCombatant()
|
||||
{
|
||||
Serial combatant = 0x1000;
|
||||
|
||||
var data = new ChangeCombatant(combatant).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xAA); // Packet ID
|
||||
expectedData.Write(ref pos, combatant);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +1,56 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class DamagePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 0xFF)]
|
||||
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new DamagePacketOld(m.Serial, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[11];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)11); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x22); // Sub-packet
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, expectedAmount);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 1024)]
|
||||
[InlineData(100000, 0xFFFF)]
|
||||
public void TestDamage(int inputAmount, ushort expectedAmount)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new DamagePacket(m.Serial, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x0B); // Packet ID
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, expectedAmount);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class DamagePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 0xFF)]
|
||||
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var data = new DamagePacketOld(m.Serial, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[11];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)11); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x22); // Sub-packet
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, expectedAmount);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 1024)]
|
||||
[InlineData(100000, 0xFFFF)]
|
||||
public void TestDamage(int inputAmount, ushort expectedAmount)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var data = new DamagePacket(m.Serial, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x0B); // Packet ID
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, expectedAmount);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.HuePickers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class DisplayHuePickerTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayHuePicker()
|
||||
{
|
||||
const ushort itemID = 0xFF01;
|
||||
var huePicker = new HuePicker(itemID);
|
||||
|
||||
Span<byte> data = new DisplayHuePicker(huePicker).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x95);
|
||||
expectedData.Write(ref pos, huePicker.Serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
expectedData.Write(ref pos, itemID);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.HuePickers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class DisplayHuePickerTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayHuePicker()
|
||||
{
|
||||
const ushort itemID = 0xFF01;
|
||||
var huePicker = new HuePicker(itemID);
|
||||
|
||||
var data = new DisplayHuePicker(huePicker).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x95);
|
||||
expectedData.Write(ref pos, huePicker.Serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
expectedData.Write(ref pos, itemID);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,182 +1,204 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class EffectPackets
|
||||
{
|
||||
[Fact]
|
||||
public void TestParticleEffect()
|
||||
{
|
||||
EffectType effectType = EffectType.Moving;
|
||||
Serial serial = 0x4000;
|
||||
Serial from = 0x1000;
|
||||
Serial to = 0x2000;
|
||||
var itemId = 0x100;
|
||||
Point3D fromPoint = new Point3D(1000, 100, -10);
|
||||
Point3D toPoint = new Point3D(1500, 500, 0);
|
||||
byte speed = 3;
|
||||
byte duration = 2;
|
||||
bool direction = false;
|
||||
bool explode = false;
|
||||
int hue = 0x1024;
|
||||
int renderMode = 1;
|
||||
ushort effect = 3;
|
||||
ushort explodeEffect = 0;
|
||||
ushort explodeSound = 0;
|
||||
byte layer = 9;
|
||||
ushort unknown = 0;
|
||||
|
||||
Span<byte> data = new ParticleEffect(
|
||||
effectType, from, to, itemId,
|
||||
fromPoint, toPoint, speed, duration,
|
||||
direction, explode, hue, renderMode,
|
||||
effect, explodeEffect, explodeSound, serial,
|
||||
layer, unknown
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[49];
|
||||
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC7); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)effectType);
|
||||
expectedData.Write(ref pos, from);
|
||||
expectedData.Write(ref pos, to);
|
||||
expectedData.Write(ref pos, (ushort)itemId);
|
||||
expectedData.Write(ref pos, fromPoint);
|
||||
expectedData.Write(ref pos, toPoint);
|
||||
expectedData.Write(ref pos, speed);
|
||||
expectedData.Write(ref pos, duration);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
expectedData.Write(ref pos, direction);
|
||||
expectedData.Write(ref pos, explode);
|
||||
expectedData.Write(ref pos, hue);
|
||||
expectedData.Write(ref pos, renderMode);
|
||||
expectedData.Write(ref pos, effect);
|
||||
expectedData.Write(ref pos, explodeEffect);
|
||||
expectedData.Write(ref pos, explodeSound);
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, layer);
|
||||
expectedData.Write(ref pos, unknown);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestHuedEffect()
|
||||
{
|
||||
EffectType effectType = EffectType.Moving;
|
||||
Serial serial = 0x4000;
|
||||
Serial from = 0x1000;
|
||||
Serial to = 0x2000;
|
||||
var itemId = 0x100;
|
||||
Point3D fromPoint = new Point3D(1000, 100, -10);
|
||||
Point3D toPoint = new Point3D(1500, 500, 0);
|
||||
byte speed = 3;
|
||||
byte duration = 2;
|
||||
bool direction = false;
|
||||
bool explode = false;
|
||||
int hue = 0x1024;
|
||||
int renderMode = 1;
|
||||
|
||||
Span<byte> data = new HuedEffect(
|
||||
effectType, from, to, itemId,
|
||||
fromPoint, toPoint, speed, duration,
|
||||
direction, explode, hue, renderMode
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[36];
|
||||
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC0); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)effectType);
|
||||
expectedData.Write(ref pos, from);
|
||||
expectedData.Write(ref pos, to);
|
||||
expectedData.Write(ref pos, (ushort)itemId);
|
||||
expectedData.Write(ref pos, fromPoint);
|
||||
expectedData.Write(ref pos, toPoint);
|
||||
expectedData.Write(ref pos, speed);
|
||||
expectedData.Write(ref pos, duration);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
expectedData.Write(ref pos, direction);
|
||||
expectedData.Write(ref pos, explode);
|
||||
expectedData.Write(ref pos, hue);
|
||||
expectedData.Write(ref pos, renderMode);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestScreenEffect()
|
||||
{
|
||||
var type = ScreenEffectType.FadeOut;
|
||||
Span<byte> data = new ScreenEffect(type).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[28];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x70); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x04); // Effect
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 8;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (ushort)type); // Screen Effect Type
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBoltEffect()
|
||||
{
|
||||
IEntity entity = new Entity(0x1000, new Point3D(1000, 100, -10), Map.Felucca);
|
||||
var hue = 0x1024;
|
||||
Span<byte> data = new BoltEffect(entity, hue).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[36];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC0); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x01); // Effect
|
||||
|
||||
|
||||
expectedData.Write(ref pos, entity.Serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 6;
|
||||
#endif
|
||||
expectedData.Write(ref pos, entity.Location);
|
||||
expectedData.Write(ref pos, entity.Location);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 6;
|
||||
#endif
|
||||
expectedData.Write(ref pos, hue);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class EffectPackets
|
||||
{
|
||||
[Fact]
|
||||
public void TestParticleEffect()
|
||||
{
|
||||
var effectType = EffectType.Moving;
|
||||
Serial serial = 0x4000;
|
||||
Serial from = 0x1000;
|
||||
Serial to = 0x2000;
|
||||
var itemId = 0x100;
|
||||
var fromPoint = new Point3D(1000, 100, -10);
|
||||
var toPoint = new Point3D(1500, 500, 0);
|
||||
byte speed = 3;
|
||||
byte duration = 2;
|
||||
var direction = false;
|
||||
var explode = false;
|
||||
var hue = 0x1024;
|
||||
var renderMode = 1;
|
||||
ushort effect = 3;
|
||||
ushort explodeEffect = 0;
|
||||
ushort explodeSound = 0;
|
||||
byte layer = 9;
|
||||
ushort unknown = 0;
|
||||
|
||||
var data = new ParticleEffect(
|
||||
effectType,
|
||||
from,
|
||||
to,
|
||||
itemId,
|
||||
fromPoint,
|
||||
toPoint,
|
||||
speed,
|
||||
duration,
|
||||
direction,
|
||||
explode,
|
||||
hue,
|
||||
renderMode,
|
||||
effect,
|
||||
explodeEffect,
|
||||
explodeSound,
|
||||
serial,
|
||||
layer,
|
||||
unknown
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[49];
|
||||
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC7); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)effectType);
|
||||
expectedData.Write(ref pos, from);
|
||||
expectedData.Write(ref pos, to);
|
||||
expectedData.Write(ref pos, (ushort)itemId);
|
||||
expectedData.Write(ref pos, fromPoint);
|
||||
expectedData.Write(ref pos, toPoint);
|
||||
expectedData.Write(ref pos, speed);
|
||||
expectedData.Write(ref pos, duration);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
expectedData.Write(ref pos, direction);
|
||||
expectedData.Write(ref pos, explode);
|
||||
expectedData.Write(ref pos, hue);
|
||||
expectedData.Write(ref pos, renderMode);
|
||||
expectedData.Write(ref pos, effect);
|
||||
expectedData.Write(ref pos, explodeEffect);
|
||||
expectedData.Write(ref pos, explodeSound);
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, layer);
|
||||
expectedData.Write(ref pos, unknown);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestHuedEffect()
|
||||
{
|
||||
var effectType = EffectType.Moving;
|
||||
Serial serial = 0x4000;
|
||||
Serial from = 0x1000;
|
||||
Serial to = 0x2000;
|
||||
var itemId = 0x100;
|
||||
var fromPoint = new Point3D(1000, 100, -10);
|
||||
var toPoint = new Point3D(1500, 500, 0);
|
||||
byte speed = 3;
|
||||
byte duration = 2;
|
||||
var direction = false;
|
||||
var explode = false;
|
||||
var hue = 0x1024;
|
||||
var renderMode = 1;
|
||||
|
||||
var data = new HuedEffect(
|
||||
effectType,
|
||||
from,
|
||||
to,
|
||||
itemId,
|
||||
fromPoint,
|
||||
toPoint,
|
||||
speed,
|
||||
duration,
|
||||
direction,
|
||||
explode,
|
||||
hue,
|
||||
renderMode
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[36];
|
||||
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC0); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)effectType);
|
||||
expectedData.Write(ref pos, from);
|
||||
expectedData.Write(ref pos, to);
|
||||
expectedData.Write(ref pos, (ushort)itemId);
|
||||
expectedData.Write(ref pos, fromPoint);
|
||||
expectedData.Write(ref pos, toPoint);
|
||||
expectedData.Write(ref pos, speed);
|
||||
expectedData.Write(ref pos, duration);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 2;
|
||||
#endif
|
||||
expectedData.Write(ref pos, direction);
|
||||
expectedData.Write(ref pos, explode);
|
||||
expectedData.Write(ref pos, hue);
|
||||
expectedData.Write(ref pos, renderMode);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestScreenEffect()
|
||||
{
|
||||
var type = ScreenEffectType.FadeOut;
|
||||
var data = new ScreenEffect(type).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[28];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x70); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x04); // Effect
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 8;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (ushort)type); // Screen Effect Type
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBoltEffect()
|
||||
{
|
||||
IEntity entity = new Entity(0x1000, new Point3D(1000, 100, -10), Map.Felucca);
|
||||
var hue = 0x1024;
|
||||
var data = new BoltEffect(entity, hue).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[36];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC0); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0x01); // Effect
|
||||
|
||||
|
||||
expectedData.Write(ref pos, entity.Serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 6;
|
||||
#endif
|
||||
expectedData.Write(ref pos, entity.Location);
|
||||
expectedData.Write(ref pos, entity.Location);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 6;
|
||||
#endif
|
||||
expectedData.Write(ref pos, hue);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,97 +1,97 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class EquipmentPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayEquipmentInfo()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new Item(Serial.LastItem + 1);
|
||||
|
||||
var info = new EquipmentInfo(
|
||||
500000,
|
||||
m,
|
||||
false,
|
||||
new []
|
||||
{
|
||||
new EquipInfoAttribute(500001, 1),
|
||||
new EquipInfoAttribute(500002, 2),
|
||||
new EquipInfoAttribute(500002, 3)
|
||||
}
|
||||
);
|
||||
|
||||
Span<byte> data = new DisplayEquipmentInfo(item, info).Compile();
|
||||
|
||||
var attrs = info.Attributes;
|
||||
|
||||
int length = 17 + (info.Unidentified ? 4 : 0) + attrs.Length * 6;
|
||||
if (info.Crafter != null) length += 6 + (info.Crafter.Name?.Length ?? 0);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x10); // Subcommand
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, info.Number);
|
||||
if (info.Crafter != null)
|
||||
{
|
||||
var name = info.Crafter.Name ?? "";
|
||||
expectedData.Write(ref pos, -3);
|
||||
expectedData.Write(ref pos, (ushort)name.Length);
|
||||
expectedData.WriteAscii(ref pos, name);
|
||||
}
|
||||
|
||||
if (info.Unidentified) expectedData.Write(ref pos, -4);
|
||||
|
||||
for (var i = 0; i < attrs.Length; i++)
|
||||
{
|
||||
var attr = attrs[i];
|
||||
expectedData.Write(ref pos, attr.Number);
|
||||
expectedData.Write(ref pos, (ushort)attr.Charges);
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, (-1));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEquipUpdate()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new Item(Serial.LastItem + 1) { Parent = m };
|
||||
|
||||
Span<byte> data = new EquipUpdate(item).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[15];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0x2E); // Packet ID
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)item.ItemID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (byte)item.Layer);
|
||||
expectedData.Write(ref pos, item.Parent.Serial);
|
||||
expectedData.Write(ref pos, (ushort)item.Hue);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class EquipmentPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayEquipmentInfo()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new Item(Serial.LastItem + 1);
|
||||
|
||||
var info = new EquipmentInfo(
|
||||
500000,
|
||||
m,
|
||||
false,
|
||||
new[]
|
||||
{
|
||||
new EquipInfoAttribute(500001, 1),
|
||||
new EquipInfoAttribute(500002, 2),
|
||||
new EquipInfoAttribute(500002, 3)
|
||||
}
|
||||
);
|
||||
|
||||
var data = new DisplayEquipmentInfo(item, info).Compile();
|
||||
|
||||
var attrs = info.Attributes;
|
||||
|
||||
var length = 17 + (info.Unidentified ? 4 : 0) + attrs.Length * 6;
|
||||
if (info.Crafter != null) length += 6 + (info.Crafter.Name?.Length ?? 0);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x10); // Subcommand
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, info.Number);
|
||||
if (info.Crafter != null)
|
||||
{
|
||||
var name = info.Crafter.Name ?? "";
|
||||
expectedData.Write(ref pos, -3);
|
||||
expectedData.Write(ref pos, (ushort)name.Length);
|
||||
expectedData.WriteAscii(ref pos, name);
|
||||
}
|
||||
|
||||
if (info.Unidentified) expectedData.Write(ref pos, -4);
|
||||
|
||||
for (var i = 0; i < attrs.Length; i++)
|
||||
{
|
||||
var attr = attrs[i];
|
||||
expectedData.Write(ref pos, attr.Number);
|
||||
expectedData.Write(ref pos, (ushort)attr.Charges);
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, -1);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEquipUpdate()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new Item(Serial.LastItem + 1) { Parent = m };
|
||||
|
||||
var data = new EquipUpdate(item).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[15];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0x2E); // Packet ID
|
||||
expectedData.Write(ref pos, item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)item.ItemID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (byte)item.Layer);
|
||||
expectedData.Write(ref pos, item.Parent.Serial);
|
||||
expectedData.Write(ref pos, (ushort)item.Hue);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,250 +1,254 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class GumpPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestCloseGump()
|
||||
{
|
||||
var typeId = 100;
|
||||
var buttonId = 10;
|
||||
|
||||
Span<byte> data = new CloseGump(typeId, buttonId).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[13];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0xD); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x4); // Close Gump
|
||||
expectedData.Write(ref pos, typeId);
|
||||
expectedData.Write(ref pos, buttonId);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplaySignGump()
|
||||
{
|
||||
Serial gumpSerial = 0x1000;
|
||||
var gumpId = 100;
|
||||
var unknownString = "This is an unknown string";
|
||||
var caption = "This is a caption";
|
||||
|
||||
Span<byte> data = new DisplaySignGump(gumpSerial, gumpId, unknownString, caption).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[15 + unknownString.Length + caption.Length];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x8B);
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length);
|
||||
expectedData.Write(ref pos, gumpSerial);
|
||||
expectedData.Write(ref pos, (ushort)gumpId);
|
||||
expectedData.Write(ref pos, (ushort)(unknownString.Length + 1));
|
||||
expectedData.WriteAsciiNull(ref pos, unknownString);
|
||||
expectedData.Write(ref pos, (ushort)(caption.Length + 1));
|
||||
expectedData.WriteAsciiNull(ref pos, caption);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestFastGumpPacket()
|
||||
{
|
||||
NetState ns = new NetState(new AccountPacketTests.TestConnectionContext
|
||||
{
|
||||
RemoteEndPoint = IPEndPoint.Parse("127.0.0.1"),
|
||||
});
|
||||
|
||||
var gump = new ResurrectGump(2);
|
||||
|
||||
Span<byte> data = gump.Compile(ns).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[0x1000];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData[pos++] = 0xB0; // Packet ID
|
||||
pos += 2; // Length
|
||||
|
||||
expectedData.Write(ref pos, gump.Serial);
|
||||
expectedData.Write(ref pos, gump.TypeID);
|
||||
expectedData.Write(ref pos, gump.X);
|
||||
expectedData.Write(ref pos, gump.Y);
|
||||
pos += 2; // Layout Length
|
||||
|
||||
int layoutLength = 0;
|
||||
|
||||
if (!gump.Draggable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoMoveBuffer);
|
||||
layoutLength += GumpUtilities.NoMove.Length;
|
||||
}
|
||||
|
||||
if (!gump.Closable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoCloseBuffer);
|
||||
layoutLength += GumpUtilities.NoClose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Disposable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoDisposeBuffer);
|
||||
layoutLength += GumpUtilities.NoDispose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Resizable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoResizeBuffer);
|
||||
layoutLength += GumpUtilities.NoResize.Length;
|
||||
}
|
||||
|
||||
foreach (var entry in gump.Entries)
|
||||
{
|
||||
var str = entry.Compile(ns);
|
||||
expectedData.WriteAscii(ref pos, str);
|
||||
layoutLength += str.Length; // ASCII so 1:1
|
||||
}
|
||||
|
||||
expectedData.Slice(19, 2).Write((ushort)layoutLength);
|
||||
expectedData.Write(ref pos, (ushort)gump.Strings.Count);
|
||||
|
||||
for (var i = 0; i < gump.Strings.Count; ++i)
|
||||
expectedData.WriteBigUni(ref pos, gump.Strings[i] ?? "");
|
||||
|
||||
expectedData.Slice(1, 2).Write((ushort)pos); // Length
|
||||
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPackedGumpPacket()
|
||||
{
|
||||
NetState ns = new NetState(new AccountPacketTests.TestConnectionContext
|
||||
{
|
||||
RemoteEndPoint = IPEndPoint.Parse("127.0.0.1"),
|
||||
})
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Unpack
|
||||
};
|
||||
|
||||
var gump = new ResurrectGump(2);
|
||||
|
||||
Span<byte> data = gump.Compile(ns).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[0x1000];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData[pos++] = 0xDD; // Packet ID
|
||||
pos += 2; // Length
|
||||
|
||||
expectedData.Write(ref pos, gump.Serial);
|
||||
expectedData.Write(ref pos, gump.TypeID);
|
||||
expectedData.Write(ref pos, gump.X);
|
||||
expectedData.Write(ref pos, gump.Y);
|
||||
|
||||
var layoutList = new List<string>();
|
||||
int bufferLength = 1; // Null terminated
|
||||
|
||||
if (!gump.Draggable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoMove);
|
||||
bufferLength += GumpUtilities.NoMove.Length;
|
||||
}
|
||||
|
||||
if (!gump.Closable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoClose);
|
||||
bufferLength += GumpUtilities.NoClose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Disposable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoDispose);
|
||||
bufferLength += GumpUtilities.NoDispose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Resizable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoResize);
|
||||
bufferLength += GumpUtilities.NoResize.Length;
|
||||
}
|
||||
|
||||
foreach (var entry in gump.Entries)
|
||||
{
|
||||
var str = entry.Compile(ns);
|
||||
bufferLength += str.Length;
|
||||
layoutList.Add(str);
|
||||
}
|
||||
|
||||
IMemoryOwner<byte> memOwner = SlabMemoryPool.Shared.Rent(bufferLength);
|
||||
|
||||
Span<byte> buffer = memOwner.Memory.Span;
|
||||
int bufferPos = 0;
|
||||
|
||||
foreach (var layout in layoutList)
|
||||
buffer.WriteAscii(ref bufferPos, layout);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
buffer.Write(ref bufferPos, (byte)0); // Layout terminator
|
||||
#else
|
||||
bufferPos++;
|
||||
#endif
|
||||
|
||||
expectedData.WritePacked(ref pos, buffer.Slice(0, bufferPos));
|
||||
memOwner.Dispose();
|
||||
|
||||
expectedData.Write(ref pos, gump.Strings.Count);
|
||||
bufferLength = gump.Strings.Sum(str => 2 + str.Length * 2);
|
||||
memOwner = SlabMemoryPool.Shared.Rent(bufferLength);
|
||||
buffer = memOwner.Memory.Span;
|
||||
bufferPos = 0;
|
||||
|
||||
foreach (var str in gump.Strings)
|
||||
buffer.WriteBigUni(ref bufferPos, str);
|
||||
|
||||
expectedData.WritePacked(ref pos, buffer.Slice(0, bufferPos));
|
||||
|
||||
// Length
|
||||
expectedData.Slice(1, 2).Write((ushort)pos);
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
|
||||
public class ResurrectGump : Gump
|
||||
{
|
||||
public ResurrectGump(int msg) : base(100, 0)
|
||||
{
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(0, 0, 400, 350, 2600);
|
||||
|
||||
AddHtmlLocalized(0, 20, 400, 35, 1011022); // <center>Resurrection</center>
|
||||
|
||||
/* It is possible for you to be resurrected here by this healer. Do you wish to try?<br>
|
||||
* CONTINUE - You chose to try to come back to life now.<br>
|
||||
* CANCEL - You prefer to remain a ghost for now.
|
||||
*/
|
||||
AddHtmlLocalized(50, 55, 300, 140, 1011023 + msg, true, true);
|
||||
|
||||
AddButton(200, 227, 4005, 4007, 0);
|
||||
AddHtmlLocalized(235, 230, 110, 35, 1011012); // CANCEL
|
||||
|
||||
AddButton(65, 227, 4005, 4007, 1);
|
||||
AddHtmlLocalized(100, 230, 110, 35, 1011011); // CONTINUE
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class GumpPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestCloseGump()
|
||||
{
|
||||
var typeId = 100;
|
||||
var buttonId = 10;
|
||||
|
||||
var data = new CloseGump(typeId, buttonId).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[13];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0xD); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x4); // Close Gump
|
||||
expectedData.Write(ref pos, typeId);
|
||||
expectedData.Write(ref pos, buttonId);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplaySignGump()
|
||||
{
|
||||
Serial gumpSerial = 0x1000;
|
||||
var gumpId = 100;
|
||||
var unknownString = "This is an unknown string";
|
||||
var caption = "This is a caption";
|
||||
|
||||
var data = new DisplaySignGump(gumpSerial, gumpId, unknownString, caption).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[15 + unknownString.Length + caption.Length];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x8B);
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length);
|
||||
expectedData.Write(ref pos, gumpSerial);
|
||||
expectedData.Write(ref pos, (ushort)gumpId);
|
||||
expectedData.Write(ref pos, (ushort)(unknownString.Length + 1));
|
||||
expectedData.WriteAsciiNull(ref pos, unknownString);
|
||||
expectedData.Write(ref pos, (ushort)(caption.Length + 1));
|
||||
expectedData.WriteAsciiNull(ref pos, caption);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestFastGumpPacket()
|
||||
{
|
||||
var ns = new NetState(
|
||||
new AccountPacketTests.TestConnectionContext
|
||||
{
|
||||
RemoteEndPoint = IPEndPoint.Parse("127.0.0.1")
|
||||
}
|
||||
);
|
||||
|
||||
var gump = new ResurrectGump(2);
|
||||
|
||||
var data = gump.Compile(ns).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[0x1000];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData[pos++] = 0xB0; // Packet ID
|
||||
pos += 2; // Length
|
||||
|
||||
expectedData.Write(ref pos, gump.Serial);
|
||||
expectedData.Write(ref pos, gump.TypeID);
|
||||
expectedData.Write(ref pos, gump.X);
|
||||
expectedData.Write(ref pos, gump.Y);
|
||||
pos += 2; // Layout Length
|
||||
|
||||
var layoutLength = 0;
|
||||
|
||||
if (!gump.Draggable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoMoveBuffer);
|
||||
layoutLength += GumpUtilities.NoMove.Length;
|
||||
}
|
||||
|
||||
if (!gump.Closable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoCloseBuffer);
|
||||
layoutLength += GumpUtilities.NoClose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Disposable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoDisposeBuffer);
|
||||
layoutLength += GumpUtilities.NoDispose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Resizable)
|
||||
{
|
||||
expectedData.Write(ref pos, GumpUtilities.NoResizeBuffer);
|
||||
layoutLength += GumpUtilities.NoResize.Length;
|
||||
}
|
||||
|
||||
foreach (var entry in gump.Entries)
|
||||
{
|
||||
var str = entry.Compile(ns);
|
||||
expectedData.WriteAscii(ref pos, str);
|
||||
layoutLength += str.Length; // ASCII so 1:1
|
||||
}
|
||||
|
||||
expectedData.Slice(19, 2).Write((ushort)layoutLength);
|
||||
expectedData.Write(ref pos, (ushort)gump.Strings.Count);
|
||||
|
||||
for (var i = 0; i < gump.Strings.Count; ++i)
|
||||
expectedData.WriteBigUni(ref pos, gump.Strings[i] ?? "");
|
||||
|
||||
expectedData.Slice(1, 2).Write((ushort)pos); // Length
|
||||
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPackedGumpPacket()
|
||||
{
|
||||
var ns = new NetState(
|
||||
new AccountPacketTests.TestConnectionContext
|
||||
{
|
||||
RemoteEndPoint = IPEndPoint.Parse("127.0.0.1")
|
||||
}
|
||||
)
|
||||
{
|
||||
ProtocolChanges = ProtocolChanges.Unpack
|
||||
};
|
||||
|
||||
var gump = new ResurrectGump(2);
|
||||
|
||||
var data = gump.Compile(ns).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[0x1000];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData[pos++] = 0xDD; // Packet ID
|
||||
pos += 2; // Length
|
||||
|
||||
expectedData.Write(ref pos, gump.Serial);
|
||||
expectedData.Write(ref pos, gump.TypeID);
|
||||
expectedData.Write(ref pos, gump.X);
|
||||
expectedData.Write(ref pos, gump.Y);
|
||||
|
||||
var layoutList = new List<string>();
|
||||
var bufferLength = 1; // Null terminated
|
||||
|
||||
if (!gump.Draggable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoMove);
|
||||
bufferLength += GumpUtilities.NoMove.Length;
|
||||
}
|
||||
|
||||
if (!gump.Closable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoClose);
|
||||
bufferLength += GumpUtilities.NoClose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Disposable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoDispose);
|
||||
bufferLength += GumpUtilities.NoDispose.Length;
|
||||
}
|
||||
|
||||
if (!gump.Resizable)
|
||||
{
|
||||
layoutList.Add(GumpUtilities.NoResize);
|
||||
bufferLength += GumpUtilities.NoResize.Length;
|
||||
}
|
||||
|
||||
foreach (var entry in gump.Entries)
|
||||
{
|
||||
var str = entry.Compile(ns);
|
||||
bufferLength += str.Length;
|
||||
layoutList.Add(str);
|
||||
}
|
||||
|
||||
var memOwner = SlabMemoryPool.Shared.Rent(bufferLength);
|
||||
|
||||
var buffer = memOwner.Memory.Span;
|
||||
var bufferPos = 0;
|
||||
|
||||
foreach (var layout in layoutList)
|
||||
buffer.WriteAscii(ref bufferPos, layout);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
buffer.Write(ref bufferPos, (byte)0); // Layout terminator
|
||||
#else
|
||||
bufferPos++;
|
||||
#endif
|
||||
|
||||
expectedData.WritePacked(ref pos, buffer.Slice(0, bufferPos));
|
||||
memOwner.Dispose();
|
||||
|
||||
expectedData.Write(ref pos, gump.Strings.Count);
|
||||
bufferLength = gump.Strings.Sum(str => 2 + str.Length * 2);
|
||||
memOwner = SlabMemoryPool.Shared.Rent(bufferLength);
|
||||
buffer = memOwner.Memory.Span;
|
||||
bufferPos = 0;
|
||||
|
||||
foreach (var str in gump.Strings)
|
||||
buffer.WriteBigUni(ref bufferPos, str);
|
||||
|
||||
expectedData.WritePacked(ref pos, buffer.Slice(0, bufferPos));
|
||||
|
||||
// Length
|
||||
expectedData.Slice(1, 2).Write((ushort)pos);
|
||||
expectedData = expectedData.Slice(0, pos);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
|
||||
public class ResurrectGump : Gump
|
||||
{
|
||||
public ResurrectGump(int msg) : base(100, 0)
|
||||
{
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(0, 0, 400, 350, 2600);
|
||||
|
||||
AddHtmlLocalized(0, 20, 400, 35, 1011022); // <center>Resurrection</center>
|
||||
|
||||
/* It is possible for you to be resurrected here by this healer. Do you wish to try?<br>
|
||||
* CONTINUE - You chose to try to come back to life now.<br>
|
||||
* CANCEL - You prefer to remain a ghost for now.
|
||||
*/
|
||||
AddHtmlLocalized(50, 55, 300, 140, 1011023 + msg, true, true);
|
||||
|
||||
AddButton(200, 227, 4005, 4007, 0);
|
||||
AddHtmlLocalized(235, 230, 110, 35, 1011012); // CANCEL
|
||||
|
||||
AddButton(65, 227, 4005, 4007, 1);
|
||||
AddHtmlLocalized(100, 230, 110, 35, 1011011); // CONTINUE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,42 +1,42 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class LightPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestGlobalLightLevel()
|
||||
{
|
||||
byte lightLevel = 5;
|
||||
Span<byte> data = new GlobalLightLevel(lightLevel).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x4F); // Packet ID
|
||||
expectedData.Write(ref pos, lightLevel);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPersonalLightLevel()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
byte lightLevel = 5;
|
||||
Span<byte> data = new PersonalLightLevel(serial, lightLevel).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x4E); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, lightLevel);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class LightPacketTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestGlobalLightLevel()
|
||||
{
|
||||
byte lightLevel = 5;
|
||||
var data = new GlobalLightLevel(lightLevel).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x4F); // Packet ID
|
||||
expectedData.Write(ref pos, lightLevel);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPersonalLightLevel()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
byte lightLevel = 5;
|
||||
var data = new PersonalLightLevel(serial, lightLevel).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x4E); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, lightLevel);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +1,62 @@
|
|||
using System;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class MapPatchesTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestMapPatches()
|
||||
{
|
||||
Span<byte> data = new MapPatches().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBF, // Packet ID
|
||||
0x00, 0x29, // Length
|
||||
0x00, 0x18, // Sub-packet
|
||||
0x00, 0x00, 0x00, 0x04, // 4 maps
|
||||
0x00, 0x00, 0x00, 0x00, // Felucca
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, // Trammel
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, // Ilshenar
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, // Malas
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInvalidMapEnable()
|
||||
{
|
||||
Span<byte> data = new InvalidMapEnable().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xC6 // Packet ID
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMapChange()
|
||||
{
|
||||
Span<byte> data = new MapChange(Map.Felucca).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBF, // Packet ID
|
||||
0x00, 0x06, // Length
|
||||
0x00, 0x08, // Sub-packet
|
||||
0x00 // Felucca
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class MapPatchesTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestMapPatches()
|
||||
{
|
||||
var data = new MapPatches().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBF, // Packet ID
|
||||
0x00, 0x29, // Length
|
||||
0x00, 0x18, // Sub-packet
|
||||
0x00, 0x00, 0x00, 0x04, // 4 maps
|
||||
0x00, 0x00, 0x00, 0x00, // Felucca
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, // Trammel
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, // Ilshenar
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, // Malas
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInvalidMapEnable()
|
||||
{
|
||||
var data = new InvalidMapEnable().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xC6 // Packet ID
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMapChange()
|
||||
{
|
||||
var data = new MapChange(Map.Felucca).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0xBF, // Packet ID
|
||||
0x00, 0x06, // Length
|
||||
0x00, 0x08, // Sub-packet
|
||||
0x00 // Felucca
|
||||
};
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,240 +1,240 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.ContextMenus;
|
||||
using Server.Menus.ItemLists;
|
||||
using Server.Menus.Questions;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
internal class ContextMenuItem : Item
|
||||
{
|
||||
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
|
||||
{
|
||||
base.GetContextMenuEntries(from, list);
|
||||
|
||||
list.Add(new ContextMenuEntry(500000));
|
||||
list.Add(new ContextMenuEntry(500001));
|
||||
list.Add(new ContextMenuEntry(500002));
|
||||
}
|
||||
|
||||
public ContextMenuItem(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MenuPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayItemListMenu()
|
||||
{
|
||||
var menu = new ItemListMenu(
|
||||
"Which item would you choose?",
|
||||
new[]
|
||||
{
|
||||
new ItemListEntry("Item 1", 0x01),
|
||||
new ItemListEntry("Item 2", 0x100),
|
||||
new ItemListEntry("Item 3", 0x1000, 250)
|
||||
}
|
||||
);
|
||||
|
||||
Span<byte> data = new DisplayItemListMenu(menu).Compile();
|
||||
|
||||
string question = menu.Question;
|
||||
int questionLength = Math.Min(255, question.Length);
|
||||
int entriesCount = 0;
|
||||
int length = 11 + questionLength;
|
||||
|
||||
foreach (var entry in menu.Entries)
|
||||
{
|
||||
length += 5 + entry.Name.Length;
|
||||
if (entriesCount == 255)
|
||||
break;
|
||||
|
||||
entriesCount++;
|
||||
}
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x7C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length);
|
||||
expectedData.Write(ref pos, menu.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x00);
|
||||
expectedData.Write(ref pos, (byte)questionLength);
|
||||
expectedData.WriteAscii(ref pos, question, 255);
|
||||
expectedData.Write(ref pos, (byte)entriesCount);
|
||||
for (int i = 0; i < entriesCount; i++)
|
||||
{
|
||||
var entry = menu.Entries[i];
|
||||
expectedData.Write(ref pos, (ushort)entry.ItemID);
|
||||
expectedData.Write(ref pos, (ushort)entry.Hue);
|
||||
string name = entry.Name?.Trim() ?? "";
|
||||
expectedData.Write(ref pos, (byte)Math.Min(255, name.Length));
|
||||
expectedData.WriteAscii(ref pos, name, 255);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayQuestionMenu()
|
||||
{
|
||||
var menu = new QuestionMenu(
|
||||
"Which option would you choose?",
|
||||
new[]
|
||||
{
|
||||
"Option 1",
|
||||
"Option 2",
|
||||
"Option 3"
|
||||
}
|
||||
);
|
||||
|
||||
Span<byte> data = new DisplayQuestionMenu(menu).Compile();
|
||||
|
||||
string question = menu.Question;
|
||||
int questionLength = Math.Min(255, question.Length);
|
||||
int answersCount = 0;
|
||||
int length = 11 + questionLength;
|
||||
|
||||
foreach (var answer in menu.Answers)
|
||||
{
|
||||
length += 5 + answer.Length;
|
||||
if (answersCount == 255)
|
||||
break;
|
||||
|
||||
answersCount++;
|
||||
}
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x7C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length);
|
||||
expectedData.Write(ref pos, menu.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x00);
|
||||
expectedData.Write(ref pos, (byte)question.Length);
|
||||
expectedData.WriteAscii(ref pos, question, 255);
|
||||
expectedData.Write(ref pos, (byte)answersCount);
|
||||
for (int i = 0; i < answersCount; i++)
|
||||
{
|
||||
var answer = menu.Answers[i];
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (byte)Math.Min(255, answer.Length));
|
||||
expectedData.WriteAscii(ref pos, answer, 255);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayContextMenu()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new ContextMenuItem(Serial.LastItem + 1);
|
||||
var menu = new ContextMenu(m, item);
|
||||
|
||||
Span<byte> data = new DisplayContextMenu(menu).Compile();
|
||||
|
||||
int length = 12 + menu.Entries.Length * 8;
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x14); // Command
|
||||
expectedData.Write(ref pos, (ushort)0x02); // Subcommand
|
||||
expectedData.Write(ref pos, menu.Target.Serial);
|
||||
var entries = menu.Entries;
|
||||
|
||||
expectedData.Write(ref pos, (byte)entries.Length);
|
||||
|
||||
for (int i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
expectedData.Write(ref pos, entry.Number);
|
||||
expectedData.Write(ref pos, (ushort)i);
|
||||
|
||||
var flags = entry.Flags;
|
||||
|
||||
var range = entry.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
|
||||
flags |= CMEFlags.Disabled;
|
||||
|
||||
expectedData.Write(ref pos, (ushort)flags);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayContextMenuOld()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new ContextMenuItem(Serial.LastItem + 1);
|
||||
var menu = new ContextMenu(m, item);
|
||||
|
||||
Span<byte> data = new DisplayContextMenuOld(menu).Compile();
|
||||
|
||||
int length = 12 + menu.Entries.Sum(entry => 6 + ((entry.Color & 0xFFFF) != 0xFFFF ? 2 : 0));
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x14); // Command
|
||||
expectedData.Write(ref pos, (ushort)0x01); // Subcommand
|
||||
expectedData.Write(ref pos, menu.Target.Serial);
|
||||
var entries = menu.Entries;
|
||||
|
||||
expectedData.Write(ref pos, (byte)entries.Length);
|
||||
|
||||
for (int i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
expectedData.Write(ref pos, (ushort)i);
|
||||
expectedData.Write(ref pos, (ushort)(entry.Number - 3000000));
|
||||
|
||||
var flags = entry.Flags;
|
||||
|
||||
var color = entry.Color & 0xFFFF;
|
||||
|
||||
if (color != 0xFFFF)
|
||||
flags |= CMEFlags.Colored;
|
||||
|
||||
var range = entry.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
|
||||
flags |= CMEFlags.Disabled;
|
||||
|
||||
expectedData.Write(ref pos, (ushort)flags);
|
||||
|
||||
if ((flags & CMEFlags.Colored) != 0)
|
||||
expectedData.Write(ref pos, (ushort)color);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.ContextMenus;
|
||||
using Server.Menus.ItemLists;
|
||||
using Server.Menus.Questions;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
internal class ContextMenuItem : Item
|
||||
{
|
||||
public ContextMenuItem(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
|
||||
{
|
||||
base.GetContextMenuEntries(from, list);
|
||||
|
||||
list.Add(new ContextMenuEntry(500000));
|
||||
list.Add(new ContextMenuEntry(500001));
|
||||
list.Add(new ContextMenuEntry(500002));
|
||||
}
|
||||
}
|
||||
|
||||
public class MenuPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestDisplayItemListMenu()
|
||||
{
|
||||
var menu = new ItemListMenu(
|
||||
"Which item would you choose?",
|
||||
new[]
|
||||
{
|
||||
new ItemListEntry("Item 1", 0x01),
|
||||
new ItemListEntry("Item 2", 0x100),
|
||||
new ItemListEntry("Item 3", 0x1000, 250)
|
||||
}
|
||||
);
|
||||
|
||||
var data = new DisplayItemListMenu(menu).Compile();
|
||||
|
||||
var question = menu.Question;
|
||||
var questionLength = Math.Min(255, question.Length);
|
||||
var entriesCount = 0;
|
||||
var length = 11 + questionLength;
|
||||
|
||||
foreach (var entry in menu.Entries)
|
||||
{
|
||||
length += 5 + entry.Name.Length;
|
||||
if (entriesCount == 255)
|
||||
break;
|
||||
|
||||
entriesCount++;
|
||||
}
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x7C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length);
|
||||
expectedData.Write(ref pos, menu.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x00);
|
||||
expectedData.Write(ref pos, (byte)questionLength);
|
||||
expectedData.WriteAscii(ref pos, question, 255);
|
||||
expectedData.Write(ref pos, (byte)entriesCount);
|
||||
for (var i = 0; i < entriesCount; i++)
|
||||
{
|
||||
var entry = menu.Entries[i];
|
||||
expectedData.Write(ref pos, (ushort)entry.ItemID);
|
||||
expectedData.Write(ref pos, (ushort)entry.Hue);
|
||||
var name = entry.Name?.Trim() ?? "";
|
||||
expectedData.Write(ref pos, (byte)Math.Min(255, name.Length));
|
||||
expectedData.WriteAscii(ref pos, name, 255);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayQuestionMenu()
|
||||
{
|
||||
var menu = new QuestionMenu(
|
||||
"Which option would you choose?",
|
||||
new[]
|
||||
{
|
||||
"Option 1",
|
||||
"Option 2",
|
||||
"Option 3"
|
||||
}
|
||||
);
|
||||
|
||||
var data = new DisplayQuestionMenu(menu).Compile();
|
||||
|
||||
var question = menu.Question;
|
||||
var questionLength = Math.Min(255, question.Length);
|
||||
var answersCount = 0;
|
||||
var length = 11 + questionLength;
|
||||
|
||||
foreach (var answer in menu.Answers)
|
||||
{
|
||||
length += 5 + answer.Length;
|
||||
if (answersCount == 255)
|
||||
break;
|
||||
|
||||
answersCount++;
|
||||
}
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x7C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length);
|
||||
expectedData.Write(ref pos, menu.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x00);
|
||||
expectedData.Write(ref pos, (byte)question.Length);
|
||||
expectedData.WriteAscii(ref pos, question, 255);
|
||||
expectedData.Write(ref pos, (byte)answersCount);
|
||||
for (var i = 0; i < answersCount; i++)
|
||||
{
|
||||
var answer = menu.Answers[i];
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (byte)Math.Min(255, answer.Length));
|
||||
expectedData.WriteAscii(ref pos, answer, 255);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayContextMenu()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new ContextMenuItem(Serial.LastItem + 1);
|
||||
var menu = new ContextMenu(m, item);
|
||||
|
||||
var data = new DisplayContextMenu(menu).Compile();
|
||||
|
||||
var length = 12 + menu.Entries.Length * 8;
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x14); // Command
|
||||
expectedData.Write(ref pos, (ushort)0x02); // Subcommand
|
||||
expectedData.Write(ref pos, menu.Target.Serial);
|
||||
var entries = menu.Entries;
|
||||
|
||||
expectedData.Write(ref pos, (byte)entries.Length);
|
||||
|
||||
for (var i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
expectedData.Write(ref pos, entry.Number);
|
||||
expectedData.Write(ref pos, (ushort)i);
|
||||
|
||||
var flags = entry.Flags;
|
||||
|
||||
var range = entry.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
|
||||
flags |= CMEFlags.Disabled;
|
||||
|
||||
expectedData.Write(ref pos, (ushort)flags);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayContextMenuOld()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var item = new ContextMenuItem(Serial.LastItem + 1);
|
||||
var menu = new ContextMenu(m, item);
|
||||
|
||||
var data = new DisplayContextMenuOld(menu).Compile();
|
||||
|
||||
var length = 12 + menu.Entries.Sum(entry => 6 + ((entry.Color & 0xFFFF) != 0xFFFF ? 2 : 0));
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x14); // Command
|
||||
expectedData.Write(ref pos, (ushort)0x01); // Subcommand
|
||||
expectedData.Write(ref pos, menu.Target.Serial);
|
||||
var entries = menu.Entries;
|
||||
|
||||
expectedData.Write(ref pos, (byte)entries.Length);
|
||||
|
||||
for (var i = 0; i < entries.Length; i++)
|
||||
{
|
||||
var entry = entries[i];
|
||||
expectedData.Write(ref pos, (ushort)i);
|
||||
expectedData.Write(ref pos, (ushort)(entry.Number - 3000000));
|
||||
|
||||
var flags = entry.Flags;
|
||||
|
||||
var color = entry.Color & 0xFFFF;
|
||||
|
||||
if (color != 0xFFFF)
|
||||
flags |= CMEFlags.Colored;
|
||||
|
||||
var range = entry.Range;
|
||||
|
||||
if (range == -1)
|
||||
range = 18;
|
||||
|
||||
if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
|
||||
flags |= CMEFlags.Disabled;
|
||||
|
||||
expectedData.Write(ref pos, (ushort)flags);
|
||||
|
||||
if ((flags & CMEFlags.Colored) != 0)
|
||||
expectedData.Write(ref pos, (ushort)color);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,191 +1,191 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Xunit;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class MessageTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestMessageLocalized()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
int graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
int hue = 1024;
|
||||
int font = 3;
|
||||
int number = 150000;
|
||||
string name = "Stuff";
|
||||
string args = "Arguments";
|
||||
|
||||
Span<byte> data = new MessageLocalized(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
number,
|
||||
name,
|
||||
args
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[50 + args.Length * 2];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC1); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.Write(ref pos, number);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteLittleUniNull(ref pos, args);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMessageLocalizedAffix()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
int graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
int hue = 1024;
|
||||
int font = 3;
|
||||
int number = 150000;
|
||||
string name = "Stuff";
|
||||
string args = "Arguments";
|
||||
var affixType = AffixType.System;
|
||||
string affix = "Affix";
|
||||
|
||||
Span<byte> data = new MessageLocalizedAffix(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
number,
|
||||
name,
|
||||
affixType,
|
||||
affix,
|
||||
args
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[52 + affix.Length + args.Length * 2];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xCC); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.Write(ref pos, number);
|
||||
expectedData.Write(ref pos, (byte)affixType);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteAsciiNull(ref pos, affix);
|
||||
expectedData.WriteBigUniNull(ref pos, args);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAsciiMessage()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
int graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
int hue = 1024;
|
||||
int font = 3;
|
||||
string name = "Stuff";
|
||||
string text = "Some Text";
|
||||
|
||||
Span<byte> data = new AsciiMessage(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
name,
|
||||
text
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[45 + text.Length];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0x1C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteAsciiNull(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestUnicodeMessage()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
int graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
int hue = 1024;
|
||||
int font = 3;
|
||||
string lang = "ENU";
|
||||
string name = "Stuff";
|
||||
string text = "Some Text";
|
||||
|
||||
Span<byte> data = new UnicodeMessage(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
lang,
|
||||
name,
|
||||
text
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[50 + text.Length * 2];
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xAE); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.WriteAsciiFixed(ref pos, lang, 4);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteBigUniNull(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestFollowMessage()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
Serial serial2 = 0x2;
|
||||
|
||||
Span<byte> data = new FollowMessage(serial, serial2).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x15); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, serial2);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class MessageTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestMessageLocalized()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
var hue = 1024;
|
||||
var font = 3;
|
||||
var number = 150000;
|
||||
var name = "Stuff";
|
||||
var args = "Arguments";
|
||||
|
||||
var data = new MessageLocalized(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
number,
|
||||
name,
|
||||
args
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[50 + args.Length * 2];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xC1); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.Write(ref pos, number);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteLittleUniNull(ref pos, args);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMessageLocalizedAffix()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
var hue = 1024;
|
||||
var font = 3;
|
||||
var number = 150000;
|
||||
var name = "Stuff";
|
||||
var args = "Arguments";
|
||||
var affixType = AffixType.System;
|
||||
var affix = "Affix";
|
||||
|
||||
var data = new MessageLocalizedAffix(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
number,
|
||||
name,
|
||||
affixType,
|
||||
affix,
|
||||
args
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[52 + affix.Length + args.Length * 2];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xCC); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.Write(ref pos, number);
|
||||
expectedData.Write(ref pos, (byte)affixType);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteAsciiNull(ref pos, affix);
|
||||
expectedData.WriteBigUniNull(ref pos, args);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestAsciiMessage()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
var hue = 1024;
|
||||
var font = 3;
|
||||
var name = "Stuff";
|
||||
var text = "Some Text";
|
||||
|
||||
var data = new AsciiMessage(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
name,
|
||||
text
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[45 + text.Length];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0x1C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteAsciiNull(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestUnicodeMessage()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
var graphic = 0x100;
|
||||
var messageType = MessageType.Label;
|
||||
var hue = 1024;
|
||||
var font = 3;
|
||||
var lang = "ENU";
|
||||
var name = "Stuff";
|
||||
var text = "Some Text";
|
||||
|
||||
var data = new UnicodeMessage(
|
||||
serial,
|
||||
graphic,
|
||||
messageType,
|
||||
hue,
|
||||
font,
|
||||
lang,
|
||||
name,
|
||||
text
|
||||
).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[50 + text.Length * 2];
|
||||
var pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0xAE); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, (ushort)graphic);
|
||||
expectedData.Write(ref pos, (byte)messageType);
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)font);
|
||||
expectedData.WriteAsciiFixed(ref pos, lang, 4);
|
||||
expectedData.WriteAsciiFixed(ref pos, name, 30);
|
||||
expectedData.WriteBigUniNull(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestFollowMessage()
|
||||
{
|
||||
Serial serial = 0x1;
|
||||
Serial serial2 = 0x2;
|
||||
|
||||
var data = new FollowMessage(serial, serial2).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x15); // Packet ID
|
||||
expectedData.Write(ref pos, serial);
|
||||
expectedData.Write(ref pos, serial2);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,112 +1,112 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class MovementPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void TestSpeedControl(byte speedControl)
|
||||
{
|
||||
Span<byte> data = new SpeedControl(speedControl).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)6); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x26); // Command
|
||||
expectedData.Write(ref pos, speedControl);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovePlayer()
|
||||
{
|
||||
const Direction d = Direction.Left;
|
||||
Span<byte> data = new MovePlayer(d).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x97); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)d);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovementRej()
|
||||
{
|
||||
Mobile m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
const byte seq = 100;
|
||||
|
||||
Span<byte> data = new MovementRej(seq, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x21); // Packet ID
|
||||
expectedData.Write(ref pos, seq);
|
||||
expectedData.Write(ref pos, (short)m.X);
|
||||
expectedData.Write(ref pos, (short)m.Y);
|
||||
expectedData.Write(ref pos, (byte)m.Direction);
|
||||
expectedData.Write(ref pos, (byte)m.Z);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovementAck()
|
||||
{
|
||||
Mobile m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
const byte seq = 100;
|
||||
int noto = Notoriety.Compute(m, m);
|
||||
|
||||
Span<byte> data = MovementAck.Instantiate(seq, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[3];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x22); // Packet ID
|
||||
expectedData.Write(ref pos, seq);
|
||||
expectedData.Write(ref pos, (byte)noto);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNullFastwalkStack()
|
||||
{
|
||||
Span<byte> data = new NullFastwalkStack().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[29];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)29); // Length
|
||||
expectedData.Write(ref pos, (short)0x1); // Sub-packet
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0); // Key 1
|
||||
expectedData.Write(ref pos, 0); // Key 2
|
||||
expectedData.Write(ref pos, 0); // Key 3
|
||||
expectedData.Write(ref pos, 0); // Key 4
|
||||
expectedData.Write(ref pos, 0); // Key 5
|
||||
expectedData.Write(ref pos, 0); // Key 6
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class MovementPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void TestSpeedControl(byte speedControl)
|
||||
{
|
||||
var data = new SpeedControl(speedControl).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[6];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)6); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x26); // Command
|
||||
expectedData.Write(ref pos, speedControl);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovePlayer()
|
||||
{
|
||||
const Direction d = Direction.Left;
|
||||
var data = new MovePlayer(d).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x97); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)d);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovementRej()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
const byte seq = 100;
|
||||
|
||||
var data = new MovementRej(seq, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x21); // Packet ID
|
||||
expectedData.Write(ref pos, seq);
|
||||
expectedData.Write(ref pos, (short)m.X);
|
||||
expectedData.Write(ref pos, (short)m.Y);
|
||||
expectedData.Write(ref pos, (byte)m.Direction);
|
||||
expectedData.Write(ref pos, (byte)m.Z);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMovementAck()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
const byte seq = 100;
|
||||
var noto = Notoriety.Compute(m, m);
|
||||
|
||||
var data = MovementAck.Instantiate(seq, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[3];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x22); // Packet ID
|
||||
expectedData.Write(ref pos, seq);
|
||||
expectedData.Write(ref pos, (byte)noto);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestNullFastwalkStack()
|
||||
{
|
||||
var data = new NullFastwalkStack().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[29];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)29); // Length
|
||||
expectedData.Write(ref pos, (short)0x1); // Sub-packet
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0); // Key 1
|
||||
expectedData.Write(ref pos, 0); // Key 2
|
||||
expectedData.Write(ref pos, 0); // Key 3
|
||||
expectedData.Write(ref pos, 0); // Key 4
|
||||
expectedData.Write(ref pos, 0); // Key 5
|
||||
expectedData.Write(ref pos, 0); // Key 6
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class ObjectHelpResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestObjectHelpResponse()
|
||||
{
|
||||
Serial s = 0x100;
|
||||
string text = "This is some testing text";
|
||||
|
||||
Span<byte> data = new ObjectHelpResponse(s, text).Compile();
|
||||
|
||||
int length = 9 + text.Length * 2;
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xB7); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, s);
|
||||
expectedData.WriteBigUniNull(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class ObjectHelpResponseTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestObjectHelpResponse()
|
||||
{
|
||||
Serial s = 0x100;
|
||||
var text = "This is some testing text";
|
||||
|
||||
var data = new ObjectHelpResponse(s, text).Compile();
|
||||
|
||||
var length = 9 + text.Length * 2;
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xB7); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, s);
|
||||
expectedData.WriteBigUniNull(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,171 +1,171 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class SecureTradePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[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);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var firstCont = new Container(Serial.LastItem + 1);
|
||||
var secondCont = new Container(Serial.LastItem + 2);
|
||||
|
||||
Span<byte> data = new DisplaySecureTrade(m, firstCont, secondCont, name).Compile();
|
||||
|
||||
bool hasName = name.Length > 0;
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[17 + (hasName ? 30 : 0)];
|
||||
int 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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCloseSecureTrade()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
Span<byte> data = new CloseSecureTrade(cont).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
int pos = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, false)] // Update first
|
||||
[InlineData(false, true)] // Update second
|
||||
public void TestUpdateSecureTrade(bool first, bool second)
|
||||
{
|
||||
var firstCont = new Container(Serial.LastItem + 1);
|
||||
var secondCont = new Container(Serial.LastItem + 2);
|
||||
|
||||
Container cont = first ? firstCont : secondCont;
|
||||
Span<byte> data = new UpdateSecureTrade(cont, first, second).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
int pos = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(100000, 30, TradeFlag.UpdateGold)]
|
||||
[InlineData(250000, 50000, TradeFlag.UpdateLedger)]
|
||||
public void TestUpdateGoldSecureTrade(int gold, int plat, TradeFlag flag)
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
Span<byte> data = new UpdateSecureTrade(cont, flag, gold, plat).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
int pos = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSecureTradeEquip()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var itemInCont = new Item(Serial.LastItem + 2) { Parent = cont };
|
||||
|
||||
Span<byte> data = new SecureTradeEquip(itemInCont, m).Compile();
|
||||
Span<byte> expectedData = stackalloc byte[20];
|
||||
int pos = 0;
|
||||
|
||||
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);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSecureTradeEquip6017()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var itemInCont = new Item(Serial.LastItem + 2) { Parent = cont };
|
||||
|
||||
Span<byte> data = new SecureTradeEquip6017(itemInCont, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[21];
|
||||
int pos = 0;
|
||||
|
||||
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);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class SecureTradePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[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);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var firstCont = new Container(Serial.LastItem + 1);
|
||||
var secondCont = new Container(Serial.LastItem + 2);
|
||||
|
||||
var data = new DisplaySecureTrade(m, firstCont, secondCont, name).Compile();
|
||||
|
||||
var hasName = name.Length > 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCloseSecureTrade()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var data = new CloseSecureTrade(cont).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
var pos = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, false)] // Update first
|
||||
[InlineData(false, true)] // Update second
|
||||
public void TestUpdateSecureTrade(bool first, bool second)
|
||||
{
|
||||
var firstCont = new Container(Serial.LastItem + 1);
|
||||
var secondCont = new Container(Serial.LastItem + 2);
|
||||
|
||||
var cont = first ? firstCont : secondCont;
|
||||
var data = new UpdateSecureTrade(cont, first, second).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
var pos = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(100000, 30, TradeFlag.UpdateGold)]
|
||||
[InlineData(250000, 50000, TradeFlag.UpdateLedger)]
|
||||
public void TestUpdateGoldSecureTrade(int gold, int plat, TradeFlag flag)
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var data = new UpdateSecureTrade(cont, flag, gold, plat).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
var pos = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSecureTradeEquip()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var itemInCont = new Item(Serial.LastItem + 2) { Parent = cont };
|
||||
|
||||
var data = new SecureTradeEquip(itemInCont, m).Compile();
|
||||
Span<byte> expectedData = stackalloc byte[20];
|
||||
var pos = 0;
|
||||
|
||||
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);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSecureTradeEquip6017()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
var itemInCont = new Item(Serial.LastItem + 2) { Parent = cont };
|
||||
|
||||
var data = new SecureTradeEquip6017(itemInCont, m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[21];
|
||||
var pos = 0;
|
||||
|
||||
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);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,161 +1,161 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
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()
|
||||
{
|
||||
int multiID = 0x1024;
|
||||
Point3D p = new Point3D(1000, 100, 10);
|
||||
MultiTarget t = new TestMultiTarget(multiID, p);
|
||||
|
||||
Span<byte> data = new MultiTargetReqHS(t).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[30];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x99); // Packet ID
|
||||
expectedData.Write(ref pos, t.AllowGround);
|
||||
expectedData.Write(ref pos, t.TargetID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 12;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (short)t.MultiID);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.X);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.Y);
|
||||
expectedData.Write(ref pos, (short)t.Offset.Z);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
// Hue (4 bytes)
|
||||
expectedData.Write(ref pos, 0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMultiTargetReq()
|
||||
{
|
||||
int multiID = 0x1024;
|
||||
Point3D p = new Point3D(1000, 100, 10);
|
||||
MultiTarget t = new TestMultiTarget(multiID, p);
|
||||
|
||||
Span<byte> data = new MultiTargetReq(t).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[26];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x99); // Packet ID
|
||||
expectedData.Write(ref pos, t.AllowGround);
|
||||
expectedData.Write(ref pos, t.TargetID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 12;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (short)t.MultiID);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.X);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.Y);
|
||||
expectedData.Write(ref pos, (short)t.Offset.Z);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCancelTarget()
|
||||
{
|
||||
Span<byte> data = new CancelTarget().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[19];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6C); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (byte)3); // Beneficial / Harmful
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestTargetReq()
|
||||
{
|
||||
var t = new TestTarget(10, true, TargetFlags.Beneficial);
|
||||
Span<byte> data = new TargetReq(t).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[19];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6C); // Packet ID
|
||||
expectedData.Write(ref pos, t.AllowGround);
|
||||
expectedData.Write(ref pos, t.TargetID);
|
||||
expectedData.Write(ref pos, (byte)t.Flags);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
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 data = new MultiTargetReqHS(t).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[30];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x99); // Packet ID
|
||||
expectedData.Write(ref pos, t.AllowGround);
|
||||
expectedData.Write(ref pos, t.TargetID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 12;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (short)t.MultiID);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.X);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.Y);
|
||||
expectedData.Write(ref pos, (short)t.Offset.Z);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
// Hue (4 bytes)
|
||||
expectedData.Write(ref pos, 0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMultiTargetReq()
|
||||
{
|
||||
var multiID = 0x1024;
|
||||
var p = new Point3D(1000, 100, 10);
|
||||
MultiTarget t = new TestMultiTarget(multiID, p);
|
||||
|
||||
var data = new MultiTargetReq(t).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[26];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x99); // Packet ID
|
||||
expectedData.Write(ref pos, t.AllowGround);
|
||||
expectedData.Write(ref pos, t.TargetID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 12;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (short)t.MultiID);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.X);
|
||||
expectedData.Write(ref pos, (ushort)t.Offset.Y);
|
||||
expectedData.Write(ref pos, (short)t.Offset.Z);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCancelTarget()
|
||||
{
|
||||
var data = new CancelTarget().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[19];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6C); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (byte)3); // Beneficial / Harmful
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestTargetReq()
|
||||
{
|
||||
var t = new TestTarget(10, true, TargetFlags.Beneficial);
|
||||
var data = new TargetReq(t).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[19];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6C); // Packet ID
|
||||
expectedData.Write(ref pos, t.AllowGround);
|
||||
expectedData.Write(ref pos, t.TargetID);
|
||||
expectedData.Write(ref pos, (byte)t.Flags);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +1,37 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Server.Prompts;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
internal class TestPrompt : Prompt
|
||||
{
|
||||
}
|
||||
|
||||
public class UnicodePromptTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestUnicodePrompt()
|
||||
{
|
||||
var prompt = new TestPrompt();
|
||||
Span<byte> data = new UnicodePrompt(prompt).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[21];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xC2); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x15); // Length
|
||||
expectedData.Write(ref pos, prompt.Serial);
|
||||
expectedData.Write(ref pos, prompt.Serial);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Server.Prompts;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
internal class TestPrompt : Prompt
|
||||
{
|
||||
}
|
||||
|
||||
public class UnicodePromptTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestUnicodePrompt()
|
||||
{
|
||||
var prompt = new TestPrompt();
|
||||
var data = new UnicodePrompt(prompt).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[21];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xC2); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x15); // Length
|
||||
expectedData.Write(ref pos, prompt.Serial);
|
||||
expectedData.Write(ref pos, prompt.Serial);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,198 +1,198 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class VendorBuyPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestVendorBuyContent()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorBuyContent(buyStates).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + buyStates.Count * 19];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, (ushort)buyStates.Count); // Count
|
||||
|
||||
for (int i = buyStates.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BuyItemState buyState = buyStates[i];
|
||||
|
||||
expectedData.Write(ref pos, buyState.MySerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.ItemID);
|
||||
pos++; // ItemID Offset
|
||||
expectedData.Write(ref pos, (ushort)buyState.Amount);
|
||||
expectedData.Write(ref pos, (ushort)(i + 1)); // X
|
||||
expectedData.Write(ref pos, (ushort)1); // Y
|
||||
expectedData.Write(ref pos, buyState.ContainerSerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.Hue);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVendorBuyContent6017()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorBuyContent6017(buyStates).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + buyStates.Count * 20];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, (ushort)buyStates.Count); // Count
|
||||
|
||||
for (int i = buyStates.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BuyItemState buyState = buyStates[i];
|
||||
|
||||
expectedData.Write(ref pos, buyState.MySerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.ItemID);
|
||||
pos++; // ItemID Offset
|
||||
expectedData.Write(ref pos, (ushort)buyState.Amount);
|
||||
expectedData.Write(ref pos, (ushort)(i + 1)); // X
|
||||
expectedData.Write(ref pos, (ushort)1); // Y
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Grid Location?
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, buyState.ContainerSerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.Hue);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayBuyList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new DisplayBuyList(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x30); // Buy gump
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayBuyListHS()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new DisplayBuyListHS(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x30); // Buy gump
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVendorBuyList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorBuyList(vendor, buyStates).Compile();
|
||||
|
||||
int length = 8 + buyStates.Sum(state => 6 + state.Description.Length);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x74); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, Serial.MinusOne); // Vendor Buy Pack Serial or -1
|
||||
expectedData.Write(ref pos, (byte)buyStates.Count);
|
||||
|
||||
for (int i = 0; i < buyStates.Count; i++)
|
||||
{
|
||||
BuyItemState state = buyStates[i];
|
||||
expectedData.Write(ref pos, state.Price);
|
||||
var description = state.Description ?? "";
|
||||
expectedData.Write(ref pos, (byte)Math.Min(255, description.Length + 1));
|
||||
expectedData.WriteAsciiNull(ref pos, description, 255);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEndVendorBuy()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new EndVendorBuy(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3B); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x8); // Length
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)-);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class VendorBuyPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestVendorBuyContent()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
var data = new VendorBuyContent(buyStates).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + buyStates.Count * 19];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, (ushort)buyStates.Count); // Count
|
||||
|
||||
for (var i = buyStates.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var buyState = buyStates[i];
|
||||
|
||||
expectedData.Write(ref pos, buyState.MySerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.ItemID);
|
||||
pos++; // ItemID Offset
|
||||
expectedData.Write(ref pos, (ushort)buyState.Amount);
|
||||
expectedData.Write(ref pos, (ushort)(i + 1)); // X
|
||||
expectedData.Write(ref pos, (ushort)1); // Y
|
||||
expectedData.Write(ref pos, buyState.ContainerSerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.Hue);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVendorBuyContent6017()
|
||||
{
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
var data = new VendorBuyContent6017(buyStates).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5 + buyStates.Count * 20];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3C); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, (ushort)buyStates.Count); // Count
|
||||
|
||||
for (var i = buyStates.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var buyState = buyStates[i];
|
||||
|
||||
expectedData.Write(ref pos, buyState.MySerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.ItemID);
|
||||
pos++; // ItemID Offset
|
||||
expectedData.Write(ref pos, (ushort)buyState.Amount);
|
||||
expectedData.Write(ref pos, (ushort)(i + 1)); // X
|
||||
expectedData.Write(ref pos, (ushort)1); // Y
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Grid Location?
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, buyState.ContainerSerial);
|
||||
expectedData.Write(ref pos, (ushort)buyState.Hue);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayBuyList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var data = new DisplayBuyList(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x30); // Buy gump
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDisplayBuyListHS()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var data = new DisplayBuyListHS(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[9];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x24); // Packet ID
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
expectedData.Write(ref pos, (ushort)0x30); // Buy gump
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestVendorBuyList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var cont = new Container(Serial.LastItem + 1);
|
||||
|
||||
var buyStates = new List<BuyItemState>
|
||||
{
|
||||
new BuyItemState("First Item", cont.Serial, Serial.NewItem, 10, 1, 0x01, 0),
|
||||
new BuyItemState("Second Item", cont.Serial, Serial.NewItem, 20, 2, 0x0A, 0),
|
||||
new BuyItemState("Third Item", cont.Serial, Serial.NewItem, 30, 10, 0x0F, 0)
|
||||
};
|
||||
|
||||
var data = new VendorBuyList(vendor, buyStates).Compile();
|
||||
|
||||
var length = 8 + buyStates.Sum(state => 6 + state.Description.Length);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x74); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, Serial.MinusOne); // Vendor Buy Pack Serial or -1
|
||||
expectedData.Write(ref pos, (byte)buyStates.Count);
|
||||
|
||||
for (var i = 0; i < buyStates.Count; i++)
|
||||
{
|
||||
var state = buyStates[i];
|
||||
expectedData.Write(ref pos, state.Price);
|
||||
var description = state.Description ?? "";
|
||||
expectedData.Write(ref pos, (byte)Math.Min(255, description.Length + 1));
|
||||
expectedData.WriteAsciiNull(ref pos, description, 255);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEndVendorBuy()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var data = new EndVendorBuy(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3B); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x8); // Length
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)-);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,81 +1,82 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class VendorSellPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestVendorSellList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var item1 = new Item(Serial.LastItem + 1);
|
||||
var item2 = new Item(Serial.LastItem + 2) { Name = "Second Item" };
|
||||
var item3 = new Item(Serial.LastItem + 3);
|
||||
|
||||
var sellStates = new List<SellItemState>
|
||||
{
|
||||
new SellItemState(item1, 100, "Item 1"),
|
||||
new SellItemState(item2, 100000, "Item 2"),
|
||||
new SellItemState(item3, 1, "Item 3")
|
||||
};
|
||||
|
||||
Span<byte> data = new VendorSellList(vendor, sellStates).Compile();
|
||||
|
||||
int length = 9 + 14 * 3 + sellStates.Sum(state =>
|
||||
(string.IsNullOrWhiteSpace(state.Item.Name) ? state.Name ?? "" : state.Item.Name.Trim()).Length
|
||||
);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x9E); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length);
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
expectedData.Write(ref pos, (ushort)sellStates.Count);
|
||||
|
||||
for (int i = 0; i < sellStates.Count; i++)
|
||||
{
|
||||
SellItemState state = sellStates[i];
|
||||
expectedData.Write(ref pos, state.Item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)state.Item.ItemID);
|
||||
expectedData.Write(ref pos, (ushort)state.Item.Hue);
|
||||
expectedData.Write(ref pos, (ushort)state.Item.Amount);
|
||||
expectedData.Write(ref pos, (ushort)state.Price);
|
||||
string name = string.IsNullOrWhiteSpace(state.Item.Name) ? state.Name ?? "" : state.Item.Name.Trim();
|
||||
expectedData.Write(ref pos, (ushort)name.Length);
|
||||
expectedData.WriteAscii(ref pos, name);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEndVendorSell()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
Span<byte> data = new EndVendorBuy(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3B); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x08); // Length
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public class VendorSellPacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Fact]
|
||||
public void TestVendorSellList()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var item1 = new Item(Serial.LastItem + 1);
|
||||
var item2 = new Item(Serial.LastItem + 2) { Name = "Second Item" };
|
||||
var item3 = new Item(Serial.LastItem + 3);
|
||||
|
||||
var sellStates = new List<SellItemState>
|
||||
{
|
||||
new SellItemState(item1, 100, "Item 1"),
|
||||
new SellItemState(item2, 100000, "Item 2"),
|
||||
new SellItemState(item3, 1, "Item 3")
|
||||
};
|
||||
|
||||
var data = new VendorSellList(vendor, sellStates).Compile();
|
||||
|
||||
var length = 9 + 14 * 3 + sellStates.Sum(
|
||||
state =>
|
||||
(string.IsNullOrWhiteSpace(state.Item.Name) ? state.Name ?? "" : state.Item.Name.Trim()).Length
|
||||
);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x9E); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length);
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
expectedData.Write(ref pos, (ushort)sellStates.Count);
|
||||
|
||||
for (var i = 0; i < sellStates.Count; i++)
|
||||
{
|
||||
var state = sellStates[i];
|
||||
expectedData.Write(ref pos, state.Item.Serial);
|
||||
expectedData.Write(ref pos, (ushort)state.Item.ItemID);
|
||||
expectedData.Write(ref pos, (ushort)state.Item.Hue);
|
||||
expectedData.Write(ref pos, (ushort)state.Item.Amount);
|
||||
expectedData.Write(ref pos, (ushort)state.Price);
|
||||
var name = string.IsNullOrWhiteSpace(state.Item.Name) ? state.Name ?? "" : state.Item.Name.Trim();
|
||||
expectedData.Write(ref pos, (ushort)name.Length);
|
||||
expectedData.WriteAscii(ref pos, name);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEndVendorSell()
|
||||
{
|
||||
var vendor = new Mobile(0x1);
|
||||
vendor.DefaultMobileInit();
|
||||
|
||||
var data = new EndVendorBuy(vendor).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[8];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3B); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)0x08); // Length
|
||||
expectedData.Write(ref pos, vendor.Serial);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#endif
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public static class PacketTestUtilities
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Span<byte> Compile(this Packet p) =>
|
||||
p.Compile(false, out int length).AsSpan(0, length);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Tests.Network.Packets
|
||||
{
|
||||
public static class PacketTestUtilities
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Span<byte> Compile(this Packet p) =>
|
||||
p.Compile(false, out var length).AsSpan(0, length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue