fix(core): Converts remaining player packets (#374)
- [X] Converts the remainder of the player packets
This commit is contained in:
parent
1e2242bb1a
commit
540a879d63
17 changed files with 836 additions and 666 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.HuePickers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -127,87 +128,60 @@ namespace Server.Tests.Network
|
|||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestServerChange()
|
||||
[Theory]
|
||||
[InlineData(100, 1000, 1, 0)]
|
||||
public void TestServerChange(int x, int y, int z, int mapID)
|
||||
{
|
||||
var p = new Point3D(100, 1000, 1);
|
||||
var map = Map.Felucca;
|
||||
var data = new ServerChange(p, map).Compile();
|
||||
var p = new Point3D(x, y, z);
|
||||
var map = Map.Maps[mapID];
|
||||
var expected = new ServerChange(p, map).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[16];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendServerChange(p, map);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x76); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)p.X);
|
||||
expectedData.Write(ref pos, (ushort)p.Y);
|
||||
expectedData.Write(ref pos, (short)p.Z);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0); // Unknown
|
||||
expectedData.Write(ref pos, 0); // Server X, Server Y
|
||||
#else
|
||||
pos += 5;
|
||||
#endif
|
||||
expectedData.Write(ref pos, (ushort)map.Width); // Server Width
|
||||
expectedData.Write(ref pos, (ushort)map.Height); // Server Height
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSkillUpdate()
|
||||
public void TestSkillsUpdate()
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
var skills = m.Skills;
|
||||
m.Skills[SkillName.Alchemy].BaseFixedPoint = 1000; // GM Alchemy
|
||||
m.Skills[Utility.RandomSkill()].BaseFixedPoint = 1000;
|
||||
|
||||
var data = new SkillUpdate(skills).Compile();
|
||||
var expected = new SkillUpdate(skills).Compile();
|
||||
|
||||
var length = 6 + skills.Length * 9;
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSkillsUpdate(skills);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3A); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (byte)0x02); // type: absolute, capped
|
||||
|
||||
for (var i = 0; i < skills.Length; i++)
|
||||
{
|
||||
var s = skills[i];
|
||||
|
||||
var v = s.NonRacialValue;
|
||||
var uv = Math.Clamp((int)(v * 10), 0, 0xFFFF);
|
||||
|
||||
expectedData.Write(ref pos, (ushort)(s.Info.SkillID + 1));
|
||||
expectedData.Write(ref pos, (ushort)uv);
|
||||
expectedData.Write(ref pos, (ushort)s.BaseFixedPoint);
|
||||
expectedData.Write(ref pos, (byte)s.Lock);
|
||||
expectedData.Write(ref pos, (ushort)s.CapFixedPoint);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(0), InlineData(10), InlineData(255)]
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10)]
|
||||
[InlineData(255)]
|
||||
public void TestSequence(byte num)
|
||||
{
|
||||
var data = new Sequence(num).Compile();
|
||||
var expected = new Sequence(num).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSequence(num);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x7B); // Packet ID
|
||||
expectedData.Write(ref pos, num);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(SkillName.Alchemy, 0, 1), InlineData(SkillName.Archery, 10, 1000),
|
||||
InlineData(SkillName.Begging, 100000, 1000)]
|
||||
[Theory]
|
||||
[InlineData(SkillName.Alchemy, 0, 1)]
|
||||
[InlineData(SkillName.Archery, 10, 1000)]
|
||||
[InlineData(SkillName.Begging, 100000, 1000)]
|
||||
public void TestSkillChange(SkillName skillName, int baseFixedPoint, int capFixedPoint)
|
||||
{
|
||||
// TODO: Eliminate all of this and just create a Skill directly
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
|
||||
|
|
@ -215,217 +189,181 @@ namespace Server.Tests.Network
|
|||
skill.BaseFixedPoint = baseFixedPoint;
|
||||
skill.CapFixedPoint = capFixedPoint;
|
||||
|
||||
var data = new SkillChange(skill).Compile();
|
||||
var expected = new SkillChange(skill).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[13];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSkillChange(skill);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x3A); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)13); // Length
|
||||
expectedData.Write(ref pos, (byte)0xDF); // type: delta, capped
|
||||
|
||||
var v = skill.NonRacialValue;
|
||||
var uv = Math.Clamp((int)(v * 10), 0, 0xFFFF);
|
||||
|
||||
expectedData.Write(ref pos, (ushort)skill.Info.SkillID);
|
||||
expectedData.Write(ref pos, (ushort)uv);
|
||||
expectedData.Write(ref pos, (ushort)skill.BaseFixedPoint);
|
||||
expectedData.Write(ref pos, (byte)skill.Lock);
|
||||
expectedData.Write(ref pos, (ushort)skill.CapFixedPoint);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(null), InlineData(""), InlineData("This is a URL, I promise")]
|
||||
public void TestLaunchBrowser(string url)
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData("This is a URL, I promise")]
|
||||
[InlineData("https://www.modernuo.com")]
|
||||
public void TestLaunchBrowser(string uri)
|
||||
{
|
||||
var data = new LaunchBrowser(url).Compile();
|
||||
var expected = new LaunchBrowser(uri).Compile();
|
||||
|
||||
url ??= "";
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendLaunchBrowser(uri);
|
||||
|
||||
var length = 4 + url.Length;
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xA5); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.WriteAsciiNull(ref pos, url); // Note: use punycode for unicode URLs
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDragEffect()
|
||||
[Theory]
|
||||
[InlineData(0x1000u, 1000, 100, 10, 0x2000u, 1125, 125, 5, 0x384, 1024, 25)]
|
||||
public void TestDragEffect(
|
||||
uint srcSerial, int srcX, int srcY, int srcZ,
|
||||
uint trgSerial, int trgX, int trgY, int trgZ,
|
||||
int itemId, int hue, int amount
|
||||
)
|
||||
{
|
||||
var src = new Entity(0x1, new Point3D(1000, 100, 10), Map.Felucca);
|
||||
var targ = new Entity(0x2, new Point3D(1125, 125, 5), Map.Felucca);
|
||||
var itemID = 0x384;
|
||||
var hue = 1024;
|
||||
var amount = 25;
|
||||
var src = new Entity(srcSerial, new Point3D(srcX, srcY, srcZ), null);
|
||||
var targ = new Entity(trgSerial, new Point3D(trgX, trgY, trgZ), null);
|
||||
|
||||
var data = new DragEffect(src, targ, itemID, hue, amount).Compile();
|
||||
var expected = new DragEffect(src, targ, itemId, hue, amount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[26];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDragEffect(
|
||||
src.Serial, src.Location,
|
||||
targ.Serial, targ.Location,
|
||||
itemId, hue, amount
|
||||
);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x23); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)itemID);
|
||||
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (ushort)hue);
|
||||
expectedData.Write(ref pos, (ushort)amount);
|
||||
expectedData.Write(ref pos, src.Serial);
|
||||
expectedData.Write(ref pos, src.Location);
|
||||
expectedData.Write(ref pos, targ.Serial);
|
||||
expectedData.Write(ref pos, targ.Location);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(1, false), InlineData(2, true)]
|
||||
[Theory]
|
||||
[InlineData(1, false)]
|
||||
[InlineData(2, true)]
|
||||
public void TestSeasonChange(int season, bool playSound)
|
||||
{
|
||||
var data = new SeasonChange(season, playSound).Compile();
|
||||
var expected = new SeasonChange(season, playSound).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[3];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendSeasonChange((byte)season, playSound);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBC); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)season);
|
||||
expectedData.Write(ref pos, playSound);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(0x1024, "Test Title", true, true), InlineData(0x1024, "Test Title", false, true),
|
||||
InlineData(0x1024, "Test Title", true, false)]
|
||||
[Theory]
|
||||
[InlineData(0x1024u, "Test Title", true, true)]
|
||||
[InlineData(0x1024u, "Test Title", false, true)]
|
||||
[InlineData(0x1024u, "Test Title", true, false)]
|
||||
public void TestDisplayPaperdoll(uint m, string title, bool warmode, bool canLift)
|
||||
{
|
||||
var data = new DisplayPaperdoll(m, title, warmode, canLift).Compile();
|
||||
var expected = new DisplayPaperdoll(m, title, warmode, canLift).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[66];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplayPaperdoll(m, title, warmode, canLift);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x88); // Packet ID
|
||||
expectedData.Write(ref pos, m);
|
||||
expectedData.WriteAsciiFixed(ref pos, title, 60);
|
||||
byte flags = 0x00;
|
||||
if (warmode)
|
||||
{
|
||||
flags |= 0x01;
|
||||
}
|
||||
|
||||
if (canLift)
|
||||
{
|
||||
flags |= 0x02;
|
||||
}
|
||||
|
||||
expectedData.Write(ref pos, flags);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(MusicName.Approach), InlineData(MusicName.Combat1), InlineData(MusicName.ValoriaShips)]
|
||||
[Theory]
|
||||
[InlineData(MusicName.Approach)]
|
||||
[InlineData(MusicName.Combat1)]
|
||||
[InlineData(MusicName.ValoriaShips)]
|
||||
public void TestPlayMusic(MusicName music)
|
||||
{
|
||||
var data = new PlayMusic(music).Compile();
|
||||
var expected = new PlayMusic(music).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[3];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendPlayMusic(music);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x6D); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)music); // Flags
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(10, 1, "Some text"), InlineData(100, 10, "Some more text")]
|
||||
[Theory]
|
||||
[InlineData(10, 1, "Some text")]
|
||||
[InlineData(100, 10, "Some more text")]
|
||||
public void TestScrollMessage(int type, int tip, string text)
|
||||
{
|
||||
var data = new ScrollMessage(type, tip, text).Compile();
|
||||
var expected = new ScrollMessage(type, tip, text).Compile();
|
||||
|
||||
text ??= "";
|
||||
var length = 10 + text.Length;
|
||||
Span<byte> expectedData = stackalloc byte[length];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendScrollMessage(type, tip ,text);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xA6); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)length); // Length
|
||||
expectedData.Write(ref pos, (byte)type);
|
||||
expectedData.Write(ref pos, tip);
|
||||
expectedData.Write(ref pos, (ushort)text.Length);
|
||||
expectedData.WriteAscii(ref pos, text);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCurrentTime()
|
||||
[Theory]
|
||||
[InlineData(14, 10, 05)]
|
||||
public void TestCurrentTime(int hour, int minute, int second)
|
||||
{
|
||||
var date = DateTime.Parse("2020-01-01 14:10:05");
|
||||
var date = new DateTime(2020, 1, 1, hour, minute, second);
|
||||
var expected = new CurrentTime(date).Compile();
|
||||
|
||||
var data = new CurrentTime(date).Compile();
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendCurrentTime(date);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[4];
|
||||
var pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x5B); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)date.Hour);
|
||||
expectedData.Write(ref pos, (byte)date.Minute);
|
||||
expectedData.Write(ref pos, (byte)date.Second);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPathfindMessage()
|
||||
[Theory]
|
||||
[InlineData(1000, 10, 1)]
|
||||
public void TestPathfindMessage(int x, int y, int z)
|
||||
{
|
||||
var p = new Point3D(1000, 10, 1);
|
||||
var data = new PathfindMessage(p).Compile();
|
||||
var p = new Point3D(x, y, z);
|
||||
var expected = new PathfindMessage(p).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendPathfindMessage(p);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x38); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)p.X);
|
||||
expectedData.Write(ref pos, (ushort)p.Y);
|
||||
expectedData.Write(ref pos, (short)p.Z);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory, InlineData(0), InlineData(10), InlineData(100)]
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10)]
|
||||
[InlineData(100)]
|
||||
public void TestPingAck(byte ping)
|
||||
{
|
||||
var data = new PingAck(ping).Compile();
|
||||
var expected = new PingAck(ping).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendPingAck(ping);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x73); // Packet ID
|
||||
expectedData.Write(ref pos, ping);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestClearAbility()
|
||||
{
|
||||
var data = new ClearWeaponAbility().Compile();
|
||||
var expected = new ClearWeaponAbility().Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[5];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendClearWeaponAbility();
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)5); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x21); // Sub-packet
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
[Theory]
|
||||
[InlineData(0xFF01)]
|
||||
public void TestDisplayHuePicker(int itemID)
|
||||
{
|
||||
var huePicker = new HuePicker(itemID);
|
||||
|
||||
var expected = new DisplayHuePicker(huePicker).Compile();
|
||||
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDisplayHuePicker(huePicker.Serial, huePicker.ItemID);
|
||||
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue