Streamlines packet tests (#175)
This commit is contained in:
parent
6a727c3401
commit
7d20cf7642
29 changed files with 1782 additions and 1684 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipelines;
|
||||
using System.Linq;
|
||||
|
|
@ -114,22 +115,30 @@ namespace Server.Tests.Network.Packets
|
|||
Span<byte> expectedData = stackalloc byte[5 + account.Length * 60];
|
||||
int pos = 0;
|
||||
|
||||
((byte)0x81).CopyTo(ref pos, expectedData); // Packet ID
|
||||
((ushort)expectedData.Length).CopyTo(ref pos, expectedData); // Length
|
||||
((byte)1).CopyTo(ref pos, expectedData); // Count of non-null characters
|
||||
((byte)0).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)0x81); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
expectedData.Write(ref pos, (byte)1); // Count of non-null characters
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
|
||||
for (var i = 0; i < account.Length; ++i)
|
||||
{
|
||||
Mobile m = account[i];
|
||||
if (m == null)
|
||||
{
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Clear(ref pos, 60);
|
||||
#else
|
||||
pos += 60;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
m.Name.CopyASCIIFixedTo(ref pos, 30, expectedData);
|
||||
expectedData.WriteAsciiFixed(ref pos, m.Name, 30);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Clear(ref pos, 30); // Password (empty)
|
||||
#else
|
||||
pos += 30;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -155,11 +164,11 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new DeleteResult(DeleteResultType.BadRequest).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x85, // Packet ID
|
||||
(byte)DeleteResultType.BadRequest
|
||||
};
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x85); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)DeleteResultType.BadRequest);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -169,11 +178,11 @@ namespace Server.Tests.Network.Packets
|
|||
{
|
||||
Span<byte> data = new PopupMessage(PMMessage.IdleWarning).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x53, // Packet ID
|
||||
(byte)PMMessage.IdleWarning
|
||||
};
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x53); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)PMMessage.IdleWarning);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -201,7 +210,9 @@ namespace Server.Tests.Network.Packets
|
|||
Span<byte> data = new SupportedFeatures(ns).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[ns.ExtendedSupportedFeatures ? 5 : 3];
|
||||
expectedData[0] = 0xB9; // Packet ID
|
||||
int pos = 0;
|
||||
|
||||
expectedData[pos++] = 0xB9; // Packet ID
|
||||
|
||||
var flags = ExpansionInfo.GetFeatures(Expansion.EJ);
|
||||
|
||||
|
|
@ -217,9 +228,9 @@ namespace Server.Tests.Network.Packets
|
|||
}
|
||||
|
||||
if (ns.ExtendedSupportedFeatures)
|
||||
((uint)flags).CopyTo(expectedData.Slice(1, 4));
|
||||
expectedData.Write(ref pos, (uint)flags);
|
||||
else
|
||||
((ushort)flags).CopyTo(expectedData.Slice(1, 2));
|
||||
expectedData.Write(ref pos, (ushort)flags);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -238,41 +249,40 @@ namespace Server.Tests.Network.Packets
|
|||
|
||||
Span<byte> data = new LoginConfirm(m).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x1B, // Packet ID
|
||||
0x00, 0x00, 0x00, 0x00, // Serial
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, // Body
|
||||
0x00, 0x00, // X
|
||||
0x00, 0x00, // Y
|
||||
0x00, 0x00, // Z
|
||||
0x00, // Direction
|
||||
0x00,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, // Map Width
|
||||
0x00, 0x00, // Map Height
|
||||
0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
Span<byte> expectedData = stackalloc byte[37];
|
||||
|
||||
int pos = 1;
|
||||
m.Serial.CopyTo(ref pos, expectedData);
|
||||
int pos = 0;
|
||||
expectedData.Write(ref pos, (byte)0x1B); // Packet ID
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
((ushort)m.Body).CopyTo(ref pos, expectedData);
|
||||
((ushort)m.X).CopyTo(ref pos, expectedData);
|
||||
((ushort)m.Y).CopyTo(ref pos, expectedData);
|
||||
((ushort)m.Z).CopyTo(ref pos, expectedData);
|
||||
((byte)m.Direction).CopyTo(ref pos, expectedData);
|
||||
pos += 9;
|
||||
#endif
|
||||
|
||||
expectedData.Write(ref pos, (ushort)m.Body);
|
||||
expectedData.Write(ref pos, (ushort)m.X);
|
||||
expectedData.Write(ref pos, (ushort)m.Y);
|
||||
expectedData.Write(ref pos, (ushort)m.Z);
|
||||
expectedData.Write(ref pos, (byte)m.Direction);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (byte)0);
|
||||
#else
|
||||
pos++;
|
||||
#endif
|
||||
expectedData.Write(ref pos, 0xFFFFFFFF);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
var map = m.Map;
|
||||
|
||||
if (map == null || map == Map.Internal)
|
||||
map = m.LogoutMap;
|
||||
|
||||
((ushort)(map?.Width ?? Map.Felucca.Width)).CopyTo(ref pos, expectedData);
|
||||
((ushort)(map?.Height ?? Map.Felucca.Height)).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (ushort)(map?.Width ?? Map.Felucca.Width));
|
||||
expectedData.Write(ref pos, (ushort)(map?.Height ?? Map.Felucca.Height));
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -304,8 +314,8 @@ namespace Server.Tests.Network.Packets
|
|||
Span<byte> expectedData = stackalloc byte[4 + account.Length * 60];
|
||||
|
||||
int pos = 0;
|
||||
((byte)0x86).CopyTo(ref pos, expectedData); // Packet ID
|
||||
((ushort)expectedData.Length).CopyTo(ref pos, expectedData); // Length
|
||||
expectedData.Write(ref pos, (byte)0x86); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
int highSlot = -1;
|
||||
for (int i = account.Length - 1; i >= 0; i--)
|
||||
|
|
@ -316,19 +326,39 @@ namespace Server.Tests.Network.Packets
|
|||
}
|
||||
|
||||
int count = Math.Max(Math.Max(highSlot + 1, account.Limit), 5);
|
||||
((byte)count).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var m = account[i];
|
||||
|
||||
if (m != null)
|
||||
{
|
||||
m.Name.CopyASCIIFixedTo(ref pos, 30, expectedData);
|
||||
expectedData.Clear(ref pos, 30);
|
||||
expectedData.WriteAsciiFixed(ref pos, m.Name, 30);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 30;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedData.Clear(ref pos, 60);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 60;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -351,10 +381,10 @@ namespace Server.Tests.Network.Packets
|
|||
Span<byte> data = new CharacterList(account, info).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[11 + account.Length * 60 + info.Length * 89];
|
||||
|
||||
int pos = 0;
|
||||
((byte)0xA9).CopyTo(ref pos, expectedData); // Packet ID
|
||||
((ushort)expectedData.Length).CopyTo(ref pos, expectedData); // Length
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xA9); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
int highSlot = -1;
|
||||
for (int i = account.Length - 1; i >= 0; i--)
|
||||
|
|
@ -365,36 +395,59 @@ namespace Server.Tests.Network.Packets
|
|||
}
|
||||
|
||||
int count = Math.Max(Math.Max(highSlot + 1, account.Limit), 5);
|
||||
((byte)count).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var m = account[i];
|
||||
if (m != null)
|
||||
{
|
||||
m.Name.CopyASCIIFixedTo(ref pos, 30, expectedData);
|
||||
expectedData.Clear(ref pos, 30);
|
||||
expectedData.WriteAsciiFixed(ref pos, m.Name, 30);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 30;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedData.Clear(ref pos, 60);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 60;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
((byte)info.Length).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)info.Length);
|
||||
|
||||
for (int i = 0; i < info.Length; i++)
|
||||
{
|
||||
var ci = info[i];
|
||||
((byte)i).CopyTo(ref pos, expectedData);
|
||||
ci.City.CopyASCIIFixedTo(ref pos, 32, expectedData);
|
||||
ci.Building.CopyASCIIFixedTo(ref pos, 32, expectedData);
|
||||
ci.X.CopyTo(ref pos, expectedData);
|
||||
ci.Y.CopyTo(ref pos, expectedData);
|
||||
ci.Z.CopyTo(ref pos, expectedData);
|
||||
ci.Map.MapID.CopyTo(ref pos, expectedData);
|
||||
ci.Description.CopyTo(ref pos, expectedData);
|
||||
expectedData.Clear(ref pos, 4);
|
||||
expectedData.Write(ref pos, (byte)i);
|
||||
expectedData.WriteAsciiFixed(ref pos, ci.City, 32);
|
||||
expectedData.WriteAsciiFixed(ref pos, ci.Building, 32);
|
||||
expectedData.Write(ref pos, ci.X);
|
||||
expectedData.Write(ref pos, ci.Y);
|
||||
expectedData.Write(ref pos, ci.Z);
|
||||
expectedData.Write(ref pos, ci.Map.MapID);
|
||||
expectedData.Write(ref pos, ci.Description);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 4;
|
||||
#endif
|
||||
}
|
||||
|
||||
var flags = ExpansionInfo.GetInfo(Expansion.EJ).CharacterListFlags;
|
||||
|
|
@ -407,8 +460,8 @@ namespace Server.Tests.Network.Packets
|
|||
flags |= CharacterListFlags.SlotLimit &
|
||||
CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character
|
||||
|
||||
((int)flags).CopyTo(ref pos, expectedData);
|
||||
((short)-1).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (int)flags);
|
||||
expectedData.Write(ref pos, (short)-1);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -431,8 +484,8 @@ namespace Server.Tests.Network.Packets
|
|||
Span<byte> expectedData = stackalloc byte[9 + account.Length * 60 + info.Length * 63];
|
||||
|
||||
int pos = 0;
|
||||
((byte)0xA9).CopyTo(ref pos, expectedData); // Packet ID
|
||||
((ushort)expectedData.Length).CopyTo(ref pos, expectedData); // Length
|
||||
expectedData.Write(ref pos, (byte)0xA9); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length); // Length
|
||||
|
||||
int highSlot = -1;
|
||||
for (int i = account.Length - 1; i >= 0; i--)
|
||||
|
|
@ -443,30 +496,49 @@ namespace Server.Tests.Network.Packets
|
|||
}
|
||||
|
||||
int count = Math.Max(Math.Max(highSlot + 1, account.Limit), 5);
|
||||
((byte)count).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var m = account[i];
|
||||
if (m != null)
|
||||
{
|
||||
m.Name.CopyASCIIFixedTo(ref pos, 30, expectedData);
|
||||
expectedData.Clear(ref pos, 30);
|
||||
expectedData.WriteAsciiFixed(ref pos, m.Name, 30);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
expectedData.Write(ref pos, (ushort)0);
|
||||
#else
|
||||
pos += 30;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
expectedData.Clear(ref pos, 60);
|
||||
#if NO_LOCAL_INIT
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, (ulong)0);
|
||||
expectedData.Write(ref pos, 0);
|
||||
#else
|
||||
pos += 60;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
((byte)info.Length).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)info.Length);
|
||||
|
||||
for (int i = 0; i < info.Length; i++)
|
||||
{
|
||||
var ci = info[i];
|
||||
((byte)i).CopyTo(ref pos, expectedData);
|
||||
ci.City.CopyASCIIFixedTo(ref pos, 31, expectedData);
|
||||
ci.Building.CopyASCIIFixedTo(ref pos, 31, expectedData);
|
||||
expectedData.Write(ref pos, (byte)i);
|
||||
expectedData.WriteAsciiFixed(ref pos, ci.City, 31);
|
||||
expectedData.WriteAsciiFixed(ref pos, ci.Building, 31);
|
||||
}
|
||||
|
||||
var flags = ExpansionInfo.GetInfo(Expansion.EJ).CharacterListFlags;
|
||||
|
|
@ -479,7 +551,7 @@ namespace Server.Tests.Network.Packets
|
|||
flags |= CharacterListFlags.SlotLimit &
|
||||
CharacterListFlags.OneCharacterSlot; // Limit Characters & One Character
|
||||
|
||||
((int)flags).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (int)flags);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -490,11 +562,11 @@ namespace Server.Tests.Network.Packets
|
|||
var reason = ALRReason.BadComm;
|
||||
Span<byte> data = new AccountLoginRej(reason).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x82, // Packet ID
|
||||
(byte)reason
|
||||
};
|
||||
Span<byte> expectedData = stackalloc byte[2];
|
||||
int pos = 0;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x82); // Packet ID
|
||||
expectedData.Write(ref pos, (byte)reason);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
@ -512,19 +584,19 @@ namespace Server.Tests.Network.Packets
|
|||
Span<byte> expectedData = stackalloc byte[6 + info.Length * 40];
|
||||
|
||||
int pos = 0;
|
||||
((byte)0xA8).CopyTo(ref pos, expectedData); // Packet ID
|
||||
((ushort)expectedData.Length).CopyTo(ref pos, expectedData);
|
||||
((byte)0x5D).CopyTo(ref pos, expectedData); // Unknown
|
||||
((ushort)info.Length).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (byte)0xA8); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)expectedData.Length);
|
||||
expectedData.Write(ref pos, (byte)0x5D); // Unknown
|
||||
expectedData.Write(ref pos, (ushort)info.Length);
|
||||
|
||||
for (int i = 0; i < info.Length; i++)
|
||||
{
|
||||
var si = info[i];
|
||||
((ushort)i).CopyTo(ref pos, expectedData);
|
||||
si.Name.CopyASCIIFixedTo(ref pos, 32, expectedData);
|
||||
((byte)si.FullPercent).CopyTo(ref pos, expectedData);
|
||||
((byte)si.TimeZone).CopyTo(ref pos, expectedData);
|
||||
Utility.GetAddressValue(si.Address.Address).CopyTo(ref pos, expectedData);
|
||||
expectedData.Write(ref pos, (ushort)i);
|
||||
expectedData.WriteAsciiFixed(ref pos, si.Name, 32);
|
||||
expectedData.Write(ref pos, (byte)si.FullPercent);
|
||||
expectedData.Write(ref pos, (byte)si.TimeZone);
|
||||
expectedData.Write(ref pos, Utility.GetAddressValue(si.Address.Address));
|
||||
}
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
|
|
@ -539,19 +611,13 @@ namespace Server.Tests.Network.Packets
|
|||
|
||||
var addr = Utility.GetAddressValue(si.Address.Address);
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[]
|
||||
{
|
||||
0x8C, // Packet ID
|
||||
(byte)addr, // IP Address in LE
|
||||
(byte)(addr >> 8),
|
||||
(byte)(addr >> 16),
|
||||
(byte)(addr >> 24),
|
||||
0x00, 0x00, // Port
|
||||
0x00, 0x00, 0x00, 0x00 // Auth ID
|
||||
};
|
||||
Span<byte> expectedData = stackalloc byte[11];
|
||||
int pos = 0;
|
||||
|
||||
((ushort)si.Address.Port).CopyTo(expectedData.Slice(5, 2));
|
||||
(-1).CopyTo(expectedData.Slice(7, 4)); // Auth ID
|
||||
expectedData.Write(ref pos,(byte)0x8C); // Packet ID
|
||||
expectedData.WriteLE(ref pos, addr);
|
||||
expectedData.Write(ref pos, (ushort)si.Address.Port);
|
||||
expectedData.Write(ref pos, -1); // Auth ID
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue