Snapshot for release 2026.10.9.3 (internal 3bc5f9f)
This commit is contained in:
parent
c94fa9deec
commit
194ea479a0
28 changed files with 1902 additions and 127 deletions
|
|
@ -318,10 +318,12 @@ internal static class Program
|
|||
private static uint OldChannelArgb(string chan) => chan switch
|
||||
{
|
||||
"Chat" => 0xFFE0E0E0, "Channels" => 0xFF7AB8F5, "System" => 0xFF8CA6BF,
|
||||
"Combat" => 0xFFD93333, "Rynth" => 0xFFE6B450, _ => 0xFFAAAAAA,
|
||||
"Combat" => 0xFFD93333, "Rynth" => 0xFFE6B450,
|
||||
"Items" => 0xFF9FD8C8, // the Items tab, new 2026-10-09 (item info used to be in Rynth)
|
||||
_ => 0xFFAAAAAA,
|
||||
};
|
||||
|
||||
private static readonly string[] AllTabsAndOdd = { "Chat", "Channels", "System", "Combat", "Rynth", "Other", "Junk", "" };
|
||||
private static readonly string[] AllTabsAndOdd = { "Chat", "Channels", "System", "Combat", "Rynth", "Items", "Other", "Junk", "" };
|
||||
|
||||
private static void LineColorDefaultsUnchanged()
|
||||
{
|
||||
|
|
|
|||
138
tools/NetMessageTests/InventoryOrderTests.cs
Normal file
138
tools/NetMessageTests/InventoryOrderTests.cs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
namespace NetMessageTests;
|
||||
using System.Buffers.Binary;
|
||||
using RynthCore.Engine.Net;
|
||||
|
||||
// Net/InventoryOrder: the server's item order, read from PlayerDescription, ViewContents and
|
||||
// InventoryPutObjInContainer. Messages are built the way ACE writes them
|
||||
// (GameEventPlayerDescription / GameEventViewContents / GameEventItemServerSaysContainId).
|
||||
internal static unsafe partial class Program
|
||||
{
|
||||
private const uint Player = 0x50000001;
|
||||
|
||||
private static byte[] GameEvent(uint ev, params uint[] payload)
|
||||
{
|
||||
var b = new byte[16 + payload.Length * 4];
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(b, 0xF7B0);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), Player);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(8), 1);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(12), ev);
|
||||
for (int i = 0; i < payload.Length; i++) BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(16 + i * 4), payload[i]);
|
||||
return b;
|
||||
}
|
||||
|
||||
// junkWords of noise (options, tables, spells...), then the inventory list, then the worn list.
|
||||
private static byte[] PlayerDescriptionMsg(int junkWords, uint[] inventory, uint[] types, int worn)
|
||||
{
|
||||
var w = new List<uint>();
|
||||
var rnd = new Random(junkWords + 1);
|
||||
for (int i = 0; i < junkWords; i++) w.Add((uint)rnd.Next());
|
||||
w.Add((uint)inventory.Length);
|
||||
for (int i = 0; i < inventory.Length; i++) { w.Add(inventory[i]); w.Add(types[i]); }
|
||||
w.Add((uint)worn);
|
||||
for (int i = 0; i < worn; i++) { w.Add(0x80001000u + (uint)i); w.Add(0x200u); w.Add(3); }
|
||||
return GameEvent(0x0013, w.ToArray());
|
||||
}
|
||||
|
||||
private static string Order(uint container, bool slots) =>
|
||||
InventoryOrder.TryGetOrder(container, slots, out uint[] ids)
|
||||
? string.Join(",", ids.Select(i => (i & 0xFFFF).ToString("X")))
|
||||
: "unknown";
|
||||
|
||||
private static byte[] MessageWithGuid(uint opcode, uint guid)
|
||||
{
|
||||
var b = new byte[8];
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(b, opcode);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), guid);
|
||||
return b;
|
||||
}
|
||||
|
||||
private static void InventoryOrderTests()
|
||||
{
|
||||
Case("inventory order: PlayerDescription gives the main pack, items then pack-slot things");
|
||||
InventoryOrder.Reset();
|
||||
uint[] ids = { 0x80000001, 0x80000002, 0x80000003, 0x80000004, 0x80000005 };
|
||||
uint[] types = { 0, 0, 0, 1, 2 };
|
||||
InventoryOrder.Observe(PlayerDescriptionMsg(137, ids, types, 4));
|
||||
Eq(Order(Player, false), "1,2,3", "ordinary items in server order");
|
||||
Eq(Order(Player, true), "4,5", "side pack and focus, in their own list");
|
||||
|
||||
Case("inventory order: the tail is found whatever noise comes before it");
|
||||
for (int junk = 0; junk < 300; junk += 7)
|
||||
{
|
||||
InventoryOrder.Reset();
|
||||
InventoryOrder.Observe(PlayerDescriptionMsg(junk, ids, types, junk % 9));
|
||||
Eq(Order(Player, false), "1,2,3", $"junk {junk}");
|
||||
}
|
||||
InventoryOrder.Reset();
|
||||
InventoryOrder.Observe(PlayerDescriptionMsg(20, Array.Empty<uint>(), Array.Empty<uint>(), 0));
|
||||
Eq(Order(Player, false), "", "an empty pack is a known, empty list");
|
||||
|
||||
Case("inventory order: a move puts the item at its placement, the others shift");
|
||||
InventoryOrder.Reset();
|
||||
InventoryOrder.Observe(PlayerDescriptionMsg(50, new uint[] { 0x80000001, 0x80000002, 0x80000003, 0x80000004 }, new uint[] { 0, 0, 0, 0 }, 2));
|
||||
InventoryOrder.Observe(GameEvent(0x0022, 0x80000001, Player, 2, 0));
|
||||
Eq(Order(Player, false), "2,3,1,4", "first item dropped on the third cell lands there");
|
||||
InventoryOrder.Observe(GameEvent(0x0022, 0x80000004, Player, 0, 0));
|
||||
Eq(Order(Player, false), "4,2,3,1", "last item to the front");
|
||||
InventoryOrder.Observe(GameEvent(0x0022, 0x80000002, Player, 99, 0));
|
||||
Eq(Order(Player, false), "4,3,1,2", "a placement past the end is the end");
|
||||
|
||||
Case("inventory order: between containers; an unseen container is not guessed");
|
||||
uint pack = 0x80000100;
|
||||
InventoryOrder.Observe(GameEvent(0x0196, pack, 2, 0x80000200, 0, 0x80000201, 0));
|
||||
Eq(Order(pack, false), "200,201", "ViewContents gives the open pack");
|
||||
InventoryOrder.Observe(GameEvent(0x0022, 0x80000004, pack, 1, 0));
|
||||
Eq(Order(pack, false), "200,4,201", "moved into the pack at 1");
|
||||
Eq(Order(Player, false), "3,1,2", "and gone from the main pack");
|
||||
InventoryOrder.Observe(GameEvent(0x0022, 0x80000003, 0x80000999, 0, 0));
|
||||
Eq(Order(Player, false), "1,2", "moved to a container never seen: only the removal is applied");
|
||||
Eq(Order(0x80000999, false), "unknown", "and that container stays unknown");
|
||||
|
||||
Case("inventory order: removal and deletion");
|
||||
InventoryOrder.Observe(MessageWithGuid(0x0024, 0x80000001));
|
||||
Eq(Order(Player, false), "2", "InventoryRemoveObject");
|
||||
InventoryOrder.Observe(MessageWithGuid(0xF747, 0x80000002));
|
||||
Eq(Order(Player, false), "", "DeleteObject");
|
||||
|
||||
Case("inventory order: opened containers are bounded, the player's own is never dropped");
|
||||
InventoryOrder.Reset();
|
||||
InventoryOrder.Observe(PlayerDescriptionMsg(30, new uint[] { 0x80000001, 0x80000002 }, new uint[] { 0, 0 }, 0));
|
||||
for (uint c = 0; c < 200; c++)
|
||||
InventoryOrder.Observe(GameEvent(0x0196, 0x90000000 + c, 1, 0xA0000000 + c, 0));
|
||||
Eq(Order(Player, false), "1,2", "the player's list survives 200 corpses");
|
||||
Eq(Order(0x90000000 + 199, false), "C7", "the newest container is kept");
|
||||
Eq(Order(0x90000000, false), "unknown", "the oldest was dropped");
|
||||
Check(InventoryOrder.Serialize().Length < 4000, "so the saved file stays small");
|
||||
|
||||
Case("inventory order: saved and restored (it survives an engine reload)");
|
||||
InventoryOrder.Reset();
|
||||
InventoryOrder.Observe(PlayerDescriptionMsg(60, new uint[] { 0x80000001, 0x80000002, 0x80000003, 0x80000004 }, new uint[] { 0, 0, 0, 1 }, 1));
|
||||
InventoryOrder.Observe(GameEvent(0x0022, 0x80000003, Player, 0, 0));
|
||||
byte[] saved = InventoryOrder.Serialize();
|
||||
string before = Order(Player, false) + "|" + Order(Player, true);
|
||||
InventoryOrder.Reset();
|
||||
Eq(Order(Player, false), "unknown", "a fresh engine knows nothing");
|
||||
Check(InventoryOrder.Restore(saved), "the saved data is accepted");
|
||||
Eq(Order(Player, false) + "|" + Order(Player, true), before, "same lists back");
|
||||
Check(!InventoryOrder.Restore(new byte[] { 1, 2, 3 }), "garbage is refused");
|
||||
Check(!InventoryOrder.Restore(saved.AsSpan(0, saved.Length - 3)), "a truncated file is refused");
|
||||
Eq(Order(Player, false) + "|" + Order(Player, true), before, "and a refused file changes nothing");
|
||||
|
||||
Case("inventory order: junk never throws and never invents a list");
|
||||
InventoryOrder.Reset();
|
||||
var rng = new Random(5);
|
||||
uint[] events = { 0x13, 0x22, 0x196 };
|
||||
for (int i = 0; i < 2000; i++)
|
||||
{
|
||||
var junk = new byte[rng.Next(0, 80)];
|
||||
rng.NextBytes(junk);
|
||||
if (junk.Length >= 16 && i % 2 == 0)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(junk, 0xF7B0);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(junk.AsSpan(12), events[i % 3]);
|
||||
}
|
||||
InventoryOrder.Observe(junk);
|
||||
}
|
||||
Check(true, "2000 random messages survived");
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,8 @@
|
|||
<Compile Include="..\..\src\RynthCore.Engine\Net\PacketRing.cs" Link="Engine\PacketRing.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Net\FragmentReassembler.cs" Link="Engine\FragmentReassembler.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Net\ServerMessageInterest.cs" Link="Engine\ServerMessageInterest.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Net\InventoryOrder.cs" Link="Engine\InventoryOrder.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\Net\AelrynthVaultWire.cs" Link="Engine\AelrynthVaultWire.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ internal sealed unsafe class CountOnly : IServerMessageSink
|
|||
}
|
||||
}
|
||||
|
||||
internal static unsafe class Program
|
||||
internal static unsafe partial class Program
|
||||
{
|
||||
private static int _checks, _failed;
|
||||
private static string _case = "";
|
||||
|
|
@ -68,6 +68,8 @@ internal static unsafe class Program
|
|||
SystemTextAndConfirmation();
|
||||
TruncationNeverThrows();
|
||||
EndToEndGameEvents();
|
||||
InventoryOrderTests();
|
||||
VaultWireTests();
|
||||
|
||||
// Captures given on the command line
|
||||
foreach (string path in args)
|
||||
|
|
|
|||
44
tools/NetMessageTests/VaultWireTests.cs
Normal file
44
tools/NetMessageTests/VaultWireTests.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
namespace NetMessageTests;
|
||||
|
||||
using RynthCore.Engine.Net;
|
||||
|
||||
// Net/AelrynthVaultWire: the vault's "~ael1" mule lines (Aeshnidae.Mule's /mule-data).
|
||||
internal static unsafe partial class Program
|
||||
{
|
||||
private static void VaultWireTests()
|
||||
{
|
||||
const string A = "{\"o\":2147483649,\"w\":100,\"n\":\"Acid Assagai\",\"i\":100667000,\"u\":100667001,\"v\":100667002,\"s\":3,\"m\":100,\"y\":1,\"e\":1}";
|
||||
const string B = "{\"o\":2147483650,\"w\":101,\"n\":\"Pyreal\",\"i\":100667003,\"y\":8192,\"future\":\"ignored\"}";
|
||||
string page = "~ael1 {\"t\":\"mule\",\"ready\":true,\"page\":2,\"pages\":3,\"count\":57,\"max\":1000,\"items\":[" + A + "," + B + "]}";
|
||||
|
||||
Case("vault wire: a page");
|
||||
Check(AelrynthVaultWire.IsMuleLine(page), "recognised as a mule line");
|
||||
Check(AelrynthVaultWire.TryParse(page, out VaultPage p), "parses");
|
||||
Check(p.Ready, "ready");
|
||||
Eq(p.Page, 2, "page"); Eq(p.Pages, 3, "pages"); Eq(p.Count, 57, "count"); Eq(p.Max, 1000, "max"); Eq(p.Items.Count, 2, "items");
|
||||
VaultItem a = p.Items[0];
|
||||
Eq(a.Id, 2147483649u, "id"); Eq(a.Name, "Acid Assagai", "name"); Eq(a.Icon, 100667000u, "icon"); Eq(a.Underlay, 100667001u, "underlay");
|
||||
Eq(a.Overlay, 100667002u, "overlay"); Eq(a.Stack, 3, "stack"); Eq(a.MaxStack, 100, "max stack"); Eq(a.ItemType, 1u, "item type"); Eq(a.Effects, 1u, "effects");
|
||||
Eq(p.Items[1].Stack, 1, "no stack field is a stack of one");
|
||||
Eq(p.Items[1].Underlay, 0u, "no underlay is none");
|
||||
|
||||
Case("vault wire: not ready is not empty");
|
||||
Check(AelrynthVaultWire.TryParse("~ael1 {\"t\":\"mule\",\"ready\":false,\"why\":\"loading\"}", out VaultPage n), "parses");
|
||||
Check(!n.Ready && n.Why == "loading" && n.Items.Count == 0, "not ready, and says why");
|
||||
|
||||
Case("vault wire: other lines");
|
||||
Check(!AelrynthVaultWire.IsMuleLine("~ael1 {\"t\":\"inspect\",\"ok\":true}"), "the Companion's line is not ours");
|
||||
Check(!AelrynthVaultWire.IsMuleLine("Welcome to Aelrynth"), "chat is not ours");
|
||||
Check(!AelrynthVaultWire.IsMuleLine(null), "null");
|
||||
Check(!AelrynthVaultWire.TryParse("~ael1 {\"t\":\"mule\",\"ready\":tru", out _), "damaged JSON is refused");
|
||||
Check(AelrynthVaultWire.IsUnknownCommand("Unknown command: mule-data"), "ACE's reply for a missing command");
|
||||
Check(!AelrynthVaultWire.IsUnknownCommand("Unknown command: mastery-data"), "another command's reply is not ours");
|
||||
Eq(AelrynthVaultWire.PageCommand(1), "@mule-data", "first page is the bare command");
|
||||
Eq(AelrynthVaultWire.PageCommand(3), "@mule-data 3", "later pages say which");
|
||||
|
||||
Case("vault wire: absurd sizes are bounded");
|
||||
string many = "~ael1 {\"t\":\"mule\",\"ready\":true,\"page\":1,\"pages\":99999,\"count\":1,\"max\":1,\"items\":[" + string.Join(",", System.Linq.Enumerable.Repeat(B, 500)) + "]}";
|
||||
Check(AelrynthVaultWire.TryParse(many, out VaultPage big), "parses");
|
||||
Check(big.Items.Count <= 200 && big.Pages <= 80, "items and pages are capped");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue