Snapshot for release 2026.10.21.1 (internal 32a418d)

This commit is contained in:
Tom Bohar 2026-10-21 09:35:08 -04:00
commit 6fe5630e8c
202 changed files with 43765 additions and 0 deletions

View file

@ -0,0 +1,170 @@
using System;
using System.IO;
using System.Linq;
using RynthCore.Engine.UI.Sections;
using RynthCore.Plugin.RynthAelrynth;
using RynthCore.Plugin.ServerPack;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// RynthAelrynth's own features (Plugins\RynthCore.Plugin.RynthAelrynth\Aelrynth), moved out of
// RynthOracle on 2026-10-20: the /top and /trial reply parser (RynthOracle.Tests' old
// AelrynthReplies), the own-reply hiding, the setting taken over from rynthoracle.json and its page.
internal static class AelrynthTests
{
public static void Register(Runner r)
{
r.Add("aelrynth: the replies of /top, /top me and /trial parse", Replies);
r.Add("aelrynth: replies to RynthAelrynth's own requests are hidden, typed ones show", HideOwnReplies);
r.Add("aelrynth: RynthOracle's reply-hiding choice is taken over once", Migration);
r.Add("aelrynth: its Leaderboards page is an Aelrynth-only view of the Server section", Pages);
r.Add("aelrynth: the difficulty tier (PropertyInt 9051) is published for other plugins, only on Aelrynth", DifficultyTier);
}
private static void Replies()
{
var a = new AelrynthBoards();
long now = 2_000_000;
a.RequestTop("", now);
Check.True(a.OnChatLine("Leaderboards - 37 characters, refreshed 4 min ago. /top <board> for the top ten, /top me for yourself.", now, out bool ours) && ours, "overview header");
a.OnChatLine(" kills Creature kills: Buffy, 1,234,567", now, out _);
a.OnChatLine(" pk PK kills: nobody yet", now, out _);
Check.True(a.Overview.Count == 2 && a.Overview[0].Key == "kills" && a.Overview[0].Leader == "Buffy" && a.Overview[0].Value == "1,234,567"
&& a.Overview[1].Leader == "nobody yet", "overview rows");
a.RequestTop("kills", now);
a.OnChatLine("Creature kills - top 10 of 37:", now, out _);
a.OnChatLine(" 1. Buffy 1,234,567 <- you", now, out _);
a.OnChatLine(" 2. Dargoth 987,654", now, out _);
a.OnChatLine(" 3. Sal 500 12 kills per death", now, out _);
Check.True(a.BoardTitle == "Creature kills" && a.BoardRows.Count == 3 && a.BoardRows[0].IsYou && a.BoardRows[1].Value == "987,654"
&& a.BoardRows[2].Extra == "12 kills per death", "board rows: " + string.Join(" | ", a.BoardRows.Select(r => $"{r.Rank} {r.Name} {r.Value} [{r.Extra}] {r.IsYou}")));
a.RequestTop("me", now);
a.OnChatLine("Buffy on the boards:", now, out _);
a.OnChatLine(" Creature kills #1 of 37, 1,234,567", now, out _);
a.OnChatLine(" PK kills -", now, out _);
Check.True(a.Standings.Count == 2 && a.Standings[0].Rank == 1 && a.Standings[1].Rank == 0, "/top me");
Check.False(a.OnChatLine(" 9. Nobody 12", now + 30_000, out _), "an entry long after its header is ignored");
a.RequestTrial("", now);
a.OnChatLine("Trials - a fresh personal copy of a listed dungeon, entered through its portal, is a timed course: ...", now, out _);
a.OnChatLine(" The Citadel Below - Trial (02F0): tier 0 12:34 by Buffy | you: tier 0 12:34 | this week: Buffy 12:34 (tier 0)", now, out _);
a.OnChatLine(" your next attempt here: in 12 min", now, out _);
a.OnChatLine("Trophy: the week's fastest clear of each dungeon, any tier - a trophy and 1,000 experience, Sunday 20:00 (2026-W40). /trial <name> for the top 10 of one dungeon.", now, out _);
Check.True(a.Trials.Count == 1 && a.Trials[0].Landblock == "02F0" && a.TrialLines.Count == 3, $"/trial overview ({a.Trials.Count} dungeons, {a.TrialLines.Count} lines)");
a.RequestTrial("citadel", now);
a.OnChatLine("The Citadel Below - Trial (02F0) - top 10, best per character, any tier:", now, out _);
a.OnChatLine(" 1. 12:34 Buffy (tier 0, 105 kills, 3 Oct)", now, out _);
a.OnChatLine(" you: tier 0 12:34 (105 kills)", now, out _);
Check.True(a.TrialRows.Count == 1 && a.TrialRows[0].Name == "Buffy" && a.TrialRows[0].Value == "12:34" && a.TrialNotes.Count == 1, "/trial dungeon top 10");
Check.False(a.OnChatLine("Bob tells you, \"hello\"", now, out _), "ordinary chat is never taken");
}
private static void HideOwnReplies()
{
var f = new AelrynthFeature();
long now = 3_000_000;
f.Boards.RequestTop("", now);
Check.True(f.OnChatLine("Leaderboards - 3 characters, refreshed just now. /top <board> ...", 0, now), "a reply to RynthAelrynth's /top is hidden");
Check.True(f.OnChatLine(" kills Creature kills: Buffy, 12", 0, now), "and its rows");
Check.False(f.OnChatLine("Leaderboards - 3 characters, refreshed just now. /top <board> ...", 0, now + 60_000), "a typed /top's reply shows");
Check.False(f.OnChatLine(" kills Creature kills: Ann, 14", 0, now + 60_000), "and its rows");
Check.True(f.Boards.Overview.Count == 1 && f.Boards.Overview[0].Leader == "Ann", "read either way");
f.HideOwnReplies = false;
f.Boards.RequestTrial("", now);
Check.False(f.OnChatLine("Trials - a fresh personal copy of a listed dungeon ...", 0, now), "with hiding off, own replies show too");
Check.False(f.OnChatLine("Bob says, \"hi\"", 0, now), "ordinary chat shows");
f.Reset();
Check.True(f.Boards.Overview.Count == 0 && f.Boards.Trials.Count == 0, "login/logout clears the boards");
}
private static void Migration()
{
string dir = ServerPackHooksTests.TempDir();
try
{
string oracle = Path.Combine(dir, "rynthoracle.json"), mine = Path.Combine(dir, "rynthaelrynth.json");
File.WriteAllText(oracle, "{ \"hideOwnQuestReplies\": false }");
var s = new ServerPackSettings(mine);
s.Load();
Check.True(AelrynthFeature.Migrate(s, oracle), "taken over the first time");
var f = new AelrynthFeature();
f.LoadSettings(s);
Check.False(f.HideOwnReplies, "the player's choice (shown) came over");
Check.False(AelrynthFeature.Migrate(s, oracle), "never twice");
var fresh = new ServerPackSettings(Path.Combine(dir, "fresh.json"));
fresh.Load();
AelrynthFeature.Migrate(fresh, Path.Combine(dir, "none.json"));
var g = new AelrynthFeature();
g.LoadSettings(fresh);
Check.True(g.HideOwnReplies, "default: hidden");
}
finally { try { Directory.Delete(dir, true); } catch { } }
}
private static void Pages()
{
var pages = ServerPackPages.Validate(AelrynthFeature.PageList.Select(p => new ServerPage(p.Id, p.Label, p.Tooltip, () => { })));
Check.Eq(pages.Count, 1, "one page");
ServerPackInfo info = new("aelrynth", "Aelrynth", new[] { "aelrynth.com" }, new[] { "Aelrynth*", "Aeshnidae*" });
SectionManifest m = SectionManifestParser.Parse("RynthAelrynth", ServerPackModel.BuildSectionsJson(info, "RynthAelrynth", pages), out string error);
Check.Eq(error, "", "RynthCore parses the manifest");
SectionContribution view = m.Contributions.Single(c => c.Primary);
Check.True(view.Server == "aelrynth" && view.Label == "Leaderboards" && view.Surface == "section:server-aelrynth.boards",
"Leaderboards, only while Aelrynth is active");
}
/// <summary>
/// AelrynthDifficulty (2026-10-21, RynthAi's AwakenedTier before): the tier the server sends as
/// PropertyInt 9051 goes into the profile's "values" with the 5% a tier, which RynthAi reads (through
/// ServerProfileView.Value) without knowing the server.
/// </summary>
private static void DifficultyTier()
{
Check.Eq(AelrynthDifficulty.TierProperty, 9051u, "PropertyInt 9051");
Check.Eq((RynthCore.Plugin.Shared.RynthServerProfile.ValueDifficultyTier, RynthCore.Plugin.Shared.RynthServerProfile.ValueDifficultyHealthPercent),
("difficultyTier", "difficultyHealthPercent"), "the value names RynthAi reads");
var d = new AelrynthDifficulty();
var values = new ServerProfileValues();
int? property = null;
int reads = 0;
int? Read() { reads++; return property; }
ServerPackInfo info = new("aelrynth", "Aelrynth", new[] { "aelrynth.com" }, new[] { "Aelrynth*", "Aeshnidae*" });
string Json() => ServerPackProfile.BuildJson(info, "RynthAelrynth", "0.2.0", true, "Aelrynth", values.Snapshot(out _));
double Tier() => RynthCore.Plugin.Shared.ServerProfileView.Value(Json(), "difficultyTier", -1);
double Percent() => RynthCore.Plugin.Shared.ServerProfileView.Value(Json(), "difficultyHealthPercent", -1);
long now = 1_000_000;
d.Tick(now, active: true, Read, values);
Check.True(d.Tier == null && values.Snapshot(out _).Length == 0, "the server hasn't sent the tier: nothing published (RynthAi stays at tier 0)");
property = 3;
d.Tick(now + 100, active: true, Read, values);
Check.Eq(reads, 1, "read at most every ReadMs");
d.Tick(now + AelrynthDifficulty.ReadMs, active: true, Read, values);
Check.Eq(d.Tier, (int?)3, "tier 3 seen");
Check.Eq((Tier(), Percent()), (3.0, 5.0), "published: tier 3, +5% health a tier");
property = null;
d.Tick(now + 2 * AelrynthDifficulty.ReadMs, active: true, Read, values);
Check.Eq(Tier(), 3.0, "a failed read keeps the last tier");
property = 0;
d.Tick(now + 3 * AelrynthDifficulty.ReadMs, active: true, Read, values);
Check.Eq((Tier(), Percent()), (0.0, 5.0), "back in real Dereth: tier 0 (still a server with tiers)");
property = -2;
d.Tick(now + 4 * AelrynthDifficulty.ReadMs, active: true, Read, values);
Check.Eq(Tier(), 0.0, "a negative tier reads as 0");
property = 7;
d.Tick(now + 5 * AelrynthDifficulty.ReadMs, active: false, Read, values);
Check.True(d.Tier == null && Tier() == -1 && Percent() == -1, "off Aelrynth (RynthCore's verdict): both values taken out");
d.Tick(now + 6 * AelrynthDifficulty.ReadMs, active: true, Read, values);
Check.Eq(Tier(), 7.0, "and read again once it is Aelrynth");
d.Reset();
Check.True(d.Tier == null && d.Describe().Contains("not sent"), "login and logout forget the tier (logout clears the values)");
}
}

View file

@ -0,0 +1,216 @@
using System;
using System.IO;
using System.Linq;
using RynthCore.Engine.UI.Sections;
using RynthCore.Plugin.RynthConquest;
using RynthCore.Plugin.RynthOracle.Data;
using RynthCore.Plugin.ServerPack;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// RynthConquest's own features (Plugins\RynthCore.Plugin.RynthConquest\Conquest), moved out of
// RynthOracle on 2026-10-20: the reply parser (RynthOracle.Tests' old ConquestReplies), the
// own-reply hiding, the login /augs, the auto-deposit, the settings taken over from rynthoracle.json,
// the Void DoT rule it publishes, the custom quest list and its pages.
internal static class ConquestTests
{
public static void Register(Runner r)
{
r.Add("conquest: the replies of /b, /augs, /enl augs, /bonus, /fship list and /top parse", Replies);
r.Add("conquest: replies to RynthConquest's own requests are hidden, typed ones show", HideOwnReplies);
r.Add("conquest: /augs once after login, then never again", LoginAugs);
r.Add("conquest: the auto-deposit is off unless turned on, then once per ten-minute mark", AutoDeposit);
r.Add("conquest: RynthOracle's settings are taken over once (defaults kept without them)", Migration);
r.Add("conquest: the Void DoT rule for RynthOracle's timers", VoidRule);
r.Add("conquest: the custom quest worklist and its status", CustomQuests);
r.Add("conquest: its pages are Conquest-only views of the Server section", Pages);
}
private static void Replies()
{
var d = new ConquestData();
long now = 1_000_000;
d.RequestBank(now);
Check.True(d.OnChatLine("[BANK] Your balances:", now, out bool ours) && ours, "bank heading (ours)");
d.OnChatLine("[BANK] Pyreals: 1,039,678,533", now, out _);
d.OnChatLine("[BANK] Event Tokens [Dragon Coins] (x): 12", now, out _);
Check.True(d.Bank.Any(b => b.Name == "Pyreals" && b.Value.Contains("4,158 MMDs")), "pyreals with MMDs");
Check.True(d.Bank.Any(b => b.Name == "Dragon Coins (x)"), "event token name");
Check.False(d.OnChatLine("Bob says, \"[BANK] Pyreals: 999\"", now, out _), "a pasted balance is ignored");
d.OnChatLine("[BANK] Pyreals: 5", now + 60_000, out bool late);
Check.False(late, "a reply long after the request isn't ours (shows in chat)");
d.RequestAugs(now);
d.OnChatLine("Creature: 25", now, out _);
d.OnChatLine("Duration: 3", now, out _);
ConquestAug creature = d.Augs.First(a => a.Name == "Creature");
Check.True(creature.Count == 25 && creature.NextLuminanceCost() == 6_229_500, $"Creature 25 next costs 6,229,500 ({creature.NextLuminanceCost()})");
Check.True(d.DurationAugs == 3 && Math.Abs(d.VoidDurationMultiplier(5) - 2.15) < 1e-9, "void duration x(1 + 5*0.2 + 3*0.05)");
d.RequestEnl(now);
d.OnChatLine("Enlightenment Augmentations:", now, out _);
d.OnChatLine("Skill Credits: 2 (10 max)", now, out _);
d.OnChatLine("Damage: 5 (25 max)", now, out _);
Check.True(d.EnlAugs.Count == 2 && d.EnlAugs[0].Name == "Damage", "enlightenment augs in display order");
d.RequestBonus(now);
d.OnChatLine("=== XP Bonuses ===", now, out _);
d.OnChatLine("Quest Bonus: 14.18% (1,418 quests)", now, out _);
d.OnChatLine("Total Bonus (Kills): 0.16%", now, out _);
Check.True(d.Bonuses.First(b => b.Name == "Quest").Value == "14.18% (1,418 quests)" && d.Bonuses.First(b => b.Name == "Total (Kills)").Value == "0.16%", "bonuses");
d.RequestFships(now);
d.OnChatLine("Fellowships looking for members:", now, out _);
d.OnChatLine("- Heroes (Leader: Bob) [3/14] @ Bur", now, out _);
d.OnChatLine("- Quiet (Leader: Ann) [1/14]", now, out _);
Check.True(d.Fellowships.Count == 2 && d.Fellowships[0].Location == "Bur" && d.Fellowships[1].MemberCount == 1, "fellowship list");
ConquestBoard lvl = d.Boards.First(b => b.Key == "level");
d.RequestBoard(lvl, now);
d.OnChatLine("Top 2 Players by Level:", now, out _);
d.OnChatLine("1: 300 - Alpha", now, out _);
d.OnChatLine("2: 299 - Beta", now, out _);
d.OnChatLine("57: 250 - Me (You)", now, out _);
Check.True(lvl.Rows.Count == 2 && lvl.You != null && lvl.You.Rank == 57 && lvl.You.Name == "Me", "Conquest /top board");
Check.Eq(ConquestData.WithdrawCommand(ConquestData.Withdrawable[ConquestData.DefaultWithdraw], "10"), "/bank withdraw n 10", "withdraw MMDs");
Check.Null(ConquestData.WithdrawCommand(ConquestData.Withdrawable[0], "-3"), "withdraw refuses a bad amount");
Check.Eq(ConquestData.TransferCommand(ConquestData.Transferable[2], "4", "Some One"), "/bank transfer p 1000000 \"Some One\"", "transfer MMD notes as pyreals");
Check.Null(ConquestData.TransferCommand(ConquestData.Transferable[2], "1001", "X"), "transfer cap");
}
private static void HideOwnReplies()
{
var f = new ConquestFeature();
f.Login(0);
long now = 100_000;
f.Data.RequestBank(now);
Check.True(f.OnChatLine("[BANK] Pyreals: 1,000", now), "a reply to RynthConquest's /b is hidden");
Check.False(f.OnChatLine("[BANK] Pyreals: 1,000", now + 60_000), "the same reply long after (typed /b) shows");
Check.False(f.OnChatLine("Bob says, \"hello\"", now), "ordinary chat shows");
f.HideOwnReplies = false;
f.Data.RequestBank(now);
Check.False(f.OnChatLine("[BANK] Pyreals: 1,000", now), "with hiding off, own replies show too");
f.HideOwnReplies = true;
// /myquests: only RynthConquest's own request's reply is hidden; the flags are read either way.
Check.True(f.Flags.Request(_ => true, now), "own /myquests sent");
Check.True(f.OnChatLine("assaultonaimaru - 1 solves (1719432000)\"x\" -1 0", now), "its reply is hidden");
f.Flags.Tick(now + 2000);
Check.True(f.Flags.TryGet("assaultonaimaru", out _), "and read");
Check.False(f.OnChatLine("ghostdencompleted - 1 solves (1719432000)\"x\" -1 0", now + 3000), "a reply nobody here asked for shows");
Check.True(f.Data.AutoDeposit(now).Length > 0 && f.OnChatLine("Deposited 12 items.", now), "the auto-deposit's reply is hidden");
}
private static void LoginAugs()
{
var f = new ConquestFeature();
f.Login(1000);
Check.Null(f.LoginAugsDue(1000 + ConquestFeature.AugsReadDelayMs), "not before the delay");
Check.Eq(f.LoginAugsDue(1001 + ConquestFeature.AugsReadDelayMs), "/augs", "/augs after it");
Check.Null(f.LoginAugsDue(5_000_000), "only once");
f.Login(9_000_000);
Check.Eq(f.LoginAugsDue(9_000_001 + ConquestFeature.AugsReadDelayMs), "/augs", "again for the next login");
}
private static void AutoDeposit()
{
var f = new ConquestFeature();
f.Login(0);
var at = new DateTime(2026, 10, 20, 14, 0, 5, DateTimeKind.Local);
Check.False(f.AutoDeposit, "off by default (as it was in RynthOracle)");
Check.Null(f.AutoDepositDue(at, 0), "off: no deposit at :00");
f.AutoDeposit = true;
Check.Eq(f.AutoDepositDue(at, 0), "/bank deposit", "on: /bank deposit at :00");
Check.Null(f.AutoDepositDue(at.AddSeconds(30), 0), "once per mark");
Check.Null(f.AutoDepositDue(at.AddMinutes(5), 0), "not at :05");
Check.Eq(f.AutoDepositDue(at.AddMinutes(10), 0), "/bank deposit", "again at :10");
long block = -1;
Check.True(ConquestFeature.DepositDue(new DateTime(2026, 1, 1, 0, 20, 0), ref block), "the schedule: :20");
Check.False(ConquestFeature.DepositDue(new DateTime(2026, 1, 1, 0, 21, 0), ref block), "the schedule: not :21");
}
private static void Migration()
{
string dir = ServerPackHooksTests.TempDir();
try
{
string oracle = Path.Combine(dir, "rynthoracle.json"), mine = Path.Combine(dir, "rynthconquest.json");
File.WriteAllText(oracle, "{ \"hideOwnQuestReplies\": false, \"conquestAutoDeposit\": true, \"tabName\": \"Conquest\" }");
var s = new ServerPackSettings(mine);
s.Load();
Check.True(ConquestFeature.Migrate(s, oracle), "taken over the first time");
var f = new ConquestFeature();
f.LoadSettings(s);
Check.True(f.AutoDeposit, "auto-deposit came over (on)");
Check.False(f.HideOwnReplies, "hiding came over (off)");
// Turned off here later: a newer rynthoracle.json never turns it back on.
f.AutoDeposit = false;
f.SaveSettings(s);
var again = new ServerPackSettings(mine);
again.Load();
Check.False(ConquestFeature.Migrate(again, oracle), "never taken over twice");
var g = new ConquestFeature();
g.LoadSettings(again);
Check.False(g.AutoDeposit, "the player's choice here stands");
// A new player (no RynthOracle settings): the defaults.
string fresh = Path.Combine(dir, "fresh.json");
var n = new ServerPackSettings(fresh);
n.Load();
Check.True(ConquestFeature.Migrate(n, Path.Combine(dir, "missing.json")), "runs (nothing to take)");
var h = new ConquestFeature();
h.LoadSettings(n);
Check.True(!h.AutoDeposit && h.HideOwnReplies, "defaults: auto-deposit off, own replies hidden");
Check.True(new ServerPackSettings(fresh) is var reread && Reload(reread) && reread.GetBool(ConquestFeature.MigrationMarker, false),
"the marker is saved");
}
finally { try { Directory.Delete(dir, true); } catch { } }
}
private static bool Reload(ServerPackSettings s) { s.Load(); return true; }
private static void VoidRule()
{
var f = new ConquestFeature();
f.Login(0);
Check.Eq(f.VoidScale, 1.0, "no augs, no Archmage's Endurance: x1");
f.ArchmagesEndurance = 5;
f.Data.RequestAugs(0);
f.Data.OnChatLine("Duration: 3", 0, out _);
Check.Near(f.VoidScale, 2.15, 1e-9, "x(1 + 5*0.2 + 3*0.05)");
Check.Eq(ConquestFeature.VoidScaleKey, "voidDotDurationScale", "the profile value RynthOracle reads");
}
private static void CustomQuests()
{
Check.Eq(CustomQuestList.All.Count, 6, "six custom quests (customquests.csv, embedded)");
Check.True(CustomQuestList.All.All(q => q.Server == "Conquest" && q.Flag.Length > 0 && q.Flag == q.Flag.ToLowerInvariant()), "Conquest rows, flags in lower case");
var flags = new QuestFlagStore();
CustomQuest darsh = CustomQuestList.All.First(q => q.Flag == "assaultonaimaru");
DateTime now = DateTime.UtcNow;
Check.False(darsh.IsComplete(flags, now), "not done without the flag");
Check.Eq(darsh.Status(flags, now), "ready", "ready without the flag");
long done = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - 60;
flags.OnChatLine($"assaultonaimaru - 1 solves ({done})\"x\" -1 3600", 0);
flags.Tick(5000);
Check.True(darsh.IsComplete(flags, now), "a repeatable on cooldown counts as done");
Check.True(darsh.Status(flags, now) is not ("ready" or "completed") && darsh.Status(flags, now).Contains('m'), "its status is the time left: " + darsh.Status(flags, now));
}
private static void Pages()
{
var pages = ServerPackPages.Validate(ConquestFeature.PageList.Select(p => new ServerPage(p.Id, p.Label, p.Tooltip, () => { })));
Check.Eq(pages.Count, ConquestFeature.PageList.Length, "every page is valid");
Check.True(pages.Select(p => p.Label).SequenceEqual(new[] { "Conquest", "Leaderboards" }), "the Conquest and Leaderboards pages");
ServerPackInfo info = new("conquest", "Conquest", new[] { "acconquest.ddns.net" }, new[] { "Conquest", "ConquestAC" });
SectionManifest m = SectionManifestParser.Parse("RynthConquest", ServerPackModel.BuildSectionsJson(info, "RynthConquest", pages), out string error);
Check.Eq(error, "", "RynthCore parses the manifest");
SectionContribution[] views = m.Contributions.Where(c => c.Primary).ToArray();
Check.Eq(views.Length, 2, "two pages in the Mini Remote");
Check.True(views.All(c => c.Server == "conquest"), "shown only while Conquest is active");
Check.True(views.Select(c => c.Surface).SequenceEqual(new[] { "section:server-conquest.main", "section:server-conquest.boards" }), "their surfaces");
}
}

View file

@ -0,0 +1,122 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using RynthCore.App;
using RynthCore.PluginSdk.Manifest;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// RynthLevistras (2026-10-21): the Levistras server plugin, and the launcher's server list
// (RynthCore.App\KnownServerCatalog.cs), which names a server plugin for every server it offers.
internal static class LevistrasTests
{
public static void Register(Runner r)
{
r.Add("levistras: the plugin's detection data matches the launcher's Levistras entry", Detection);
r.Add("levistras: its card says bots are forbidden and two accounts", Card);
r.Add("levistras: its quest pack is the 464 Levistras rows RynthOracle had", Pack);
r.Add("launcher catalog: every server names a plugin that claims its host, port and emulator", Catalog);
}
private static string PluginsDir()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
dir = Path.GetDirectoryName(dir);
if (dir == null) throw new DirectoryNotFoundException("RynthSuite\\Plugins not found above " + AppContext.BaseDirectory);
return Path.Combine(dir, "Plugins");
}
private sealed record Plugin(string Dir, string Id, string Name, string[] Hosts, string[] Worlds, string ServerData);
/// <summary>The server plugin project named Rynth&lt;name&gt;, or null.</summary>
private static Plugin? Load(string pluginName)
{
string dir = Path.Combine(PluginsDir(), "RynthCore.Plugin." + pluginName);
string csproj = Path.Combine(dir, "RynthCore.Plugin." + pluginName + ".csproj");
if (!File.Exists(csproj)) return null;
XDocument doc = XDocument.Load(csproj);
string Prop(string name) => doc.Descendants(name).FirstOrDefault()?.Value.Trim() ?? "";
string[] Split(string v) => v.Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
string data = Path.Combine(dir, "ServerData.cs");
return new Plugin(dir, Prop("RynthPluginServerId"), Prop("RynthPluginServerName"), Split(Prop("RynthPluginServerHosts")),
Split(Prop("RynthPluginServerWorldNames")), File.Exists(data) ? File.ReadAllText(data) : "");
}
/// <summary>The port ServerData.cs sets (9000 when it doesn't say).</summary>
private static int PortOf(Plugin p)
{
Match m = Regex.Match(p.ServerData, @"\bPort\s*=\s*(\d+)");
return m.Success ? int.Parse(m.Groups[1].Value) : 9000;
}
private static string EmulatorOf(Plugin p)
{
Match m = Regex.Match(p.ServerData, @"\bEmulator\s*=\s*""([^""]*)""");
return m.Success ? m.Groups[1].Value : "ACE";
}
private static void Detection()
{
Plugin? p = Load("RynthLevistras");
Check.NotNull(p, "RynthLevistras exists");
if (p == null) return;
Check.Eq(p.Id, "levistras", "id");
Check.Eq(p.Name, "Levistras", "name (also its quest pack's tag)");
Check.True(p.Hosts.SequenceEqual(new[] { "levistras.acportalstorm.com" }), "host: " + string.Join("|", p.Hosts));
Check.True(p.Worlds.Contains("Levistras"), "world name Levistras (the name RynthOracle matched before the move)");
KnownServer? k = KnownServerCatalog.FindById("levistras");
Check.NotNull(k, "the launcher lists Levistras");
if (k == null) return;
Check.Eq(k.PluginName, "RynthLevistras", "the launcher's entry names RynthLevistras");
var server = new RynthPluginServer { Id = p.Id, Hosts = p.Hosts.ToList() };
Check.True(server.MatchesHost(k.Host, out _), "the plugin claims the launcher's host " + k.Host);
Check.Eq(PortOf(p), k.Port, "port");
Check.Eq(EmulatorOf(p), "ACE", "emulator");
Check.Eq(k.Emulator, AcEmulatorKind.Ace, "the launcher connects with ACE");
}
private static void Card()
{
Plugin? p = Load("RynthLevistras");
if (p == null) { Check.True(false, "RynthLevistras exists"); return; }
Check.True(p.ServerData.Contains("Botting = BottingPolicy.Forbidden"), "botting forbidden (the server card warns, RynthAi's combat isn't for here)");
Check.True(p.ServerData.Contains("AccountLimit = \"2 accounts\""), "two accounts");
Check.True(p.ServerData.Contains("Ruleset = \"PvE\""), "PvE");
}
private static void Pack()
{
Plugin? p = Load("RynthLevistras");
if (p == null) { Check.True(false, "RynthLevistras exists"); return; }
string file = Path.Combine(p.Dir, "Resources", "quests.levistras.csv");
Check.True(File.Exists(file), "Resources\\quests.levistras.csv (ServerPlugin.props embeds it as the served pack)");
if (!File.Exists(file)) return;
string csv = File.ReadAllText(file);
Check.Eq(RynthCore.Plugin.ServerPack.ServerPackQuestPack.CountRows(csv), 464, "464 quests");
var info = new RynthCore.Plugin.ServerPack.ServerPackInfo(p.Id, p.Name, p.Hosts, p.Worlds);
string json = RynthCore.Plugin.ServerPack.ServerPackQuestPack.BuildInfoJson(info, "RynthLevistras", "0.1.0", csv);
Check.True(json.Contains("\"server\":\"levistras\"") && json.Contains("\"tag\":\"Levistras\"") && json.Contains("\"rows\":464"),
"offered as levistras / Levistras, 464 rows: " + json);
Check.True(File.Exists(Path.Combine(p.Dir, "THIRD_PARTY_NOTICES.md")), "the pack's MIT notice (Advis Eveldan's rows) comes with it");
}
private static void Catalog()
{
foreach (KnownServer k in KnownServerCatalog.All)
{
Plugin? p = Load(k.PluginName);
Check.NotNull(p, $"{k.Id}: the launcher's plugin {k.PluginName} exists");
if (p == null) continue;
Check.Eq(p.Id, k.Id, $"{k.PluginName}: the same server id as the launcher");
var server = new RynthPluginServer { Id = p.Id, Hosts = p.Hosts.ToList() };
Check.True(server.MatchesHost(k.Host, out _), $"{k.PluginName} claims the launcher's host {k.Host}");
Check.Eq(PortOf(p), k.Port, $"{k.PluginName}: port");
Check.Eq(EmulatorOf(p).Equals("GDLE", StringComparison.OrdinalIgnoreCase), k.Emulator == AcEmulatorKind.Gdle, $"{k.PluginName}: emulator");
}
}
}

View file

@ -0,0 +1,24 @@
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// Offline tests for the server plugins: the shared model and every server plugin's detection data.
//
// Run: dotnet run -c Release (all tests)
// dotnet run -c Release -- host (tests whose name contains "host")
internal static class Program
{
private static int Main(string[] args)
{
var runner = new Runner();
ServerPackModelTests.Register(runner);
ServerProjectsTests.Register(runner);
ServerPackHooksTests.Register(runner);
ConquestTests.Register(runner);
AelrynthTests.Register(runner);
VaultTests.Register(runner);
QuestPackTests.Register(runner);
LevistrasTests.Register(runner);
return runner.Run("RynthServerPack tests", args.Length > 0 ? args[0] : null);
}
}

View file

@ -0,0 +1,154 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using RynthCore.Plugin.ServerPack;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// "RynthServer.QuestPack" (Plugins\Shared\ServerPack\ServerPackQuestPack.cs): a server plugin's own quest
// list for RynthOracle. The info JSON says whose pack it is and how big; junk is no pack at all.
internal static class QuestPackTests
{
public static void Register(Runner r)
{
r.Add("quest pack: the info JSON names the server, its tag and the pack's size", InfoJson);
r.Add("quest pack: no pack, junk or a header alone is no pack", NoPack);
r.Add("quest pack: the info JSON is plain ASCII and escaped", InfoAscii);
r.Add("quest pack: the embedded pack is served as it is (RynthConquest's)", Embedded);
r.Add("quest packs: Conquest's, Levistras's and Aelrynth's are their own plugins' (none left in RynthOracle)", Projects);
}
private static string PluginsDir()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
dir = Path.GetDirectoryName(dir);
if (dir == null) throw new DirectoryNotFoundException("RynthSuite\\Plugins not found above " + AppContext.BaseDirectory);
return Path.Combine(dir, "Plugins");
}
/// <summary>RynthSuite's Plugins: the sibling checkout this repo builds against (RynthOracle lives there).</summary>
private static string SuitePluginsDir()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "RynthSuite", "Plugins", "RynthCore.Plugin.RynthOracle")))
dir = Path.GetDirectoryName(dir);
if (dir == null) throw new DirectoryNotFoundException("the sibling RynthSuite\\Plugins not found above " + AppContext.BaseDirectory);
return Path.Combine(dir, "RynthSuite", "Plugins");
}
private static void Embedded()
{
string csv = ServerPackQuestPack.Csv;
Check.Eq(ServerPackQuestPack.CountRows(csv), 546, "RynthConquest's 546 quests are served");
var conquest = new ServerPackInfo("conquest", "Conquest", new[] { "acconquest.ddns.net" }, new[] { "Conquest" });
using JsonDocument doc = JsonDocument.Parse(ServerPackQuestPack.BuildInfoJson(conquest, "RynthConquest", "0.2.0", csv));
Check.Eq(doc.RootElement.GetProperty("rows").GetInt32(), 546, "the info says so");
Check.Eq(doc.RootElement.GetProperty("tag").GetString(), "Conquest", "under the tag the master list uses");
Check.True(ReferenceEquals(csv, ServerPackQuestPack.Csv), "read once");
}
/// <summary>
/// The packs that were RynthOracle's (2026-10-21): each in its server's plugin, as
/// Resources\quests.&lt;server id&gt;.csv (ServerPlugin.props embeds it), naming only that server; the
/// same rows as before; none left in RynthOracle, which keeps only the retail list.
/// </summary>
private static void Projects()
{
string plugins = PluginsDir();
var expected = new Dictionary<string, (string Dir, string Name, int Rows)>
{
["conquest"] = ("RynthCore.Plugin.RynthConquest", "Conquest", 546),
["levistras"] = ("RynthCore.Plugin.RynthLevistras", "Levistras", 464),
["aelrynth"] = ("RynthCore.Plugin.RynthAelrynth", "Aelrynth", 4277),
};
foreach (var kv in expected)
{
string file = Path.Combine(plugins, kv.Value.Dir, "Resources", $"quests.{kv.Key}.csv");
Check.True(File.Exists(file), kv.Value.Dir + " has its pack " + Path.GetFileName(file));
if (!File.Exists(file)) continue;
string csv = File.ReadAllText(file);
Check.True(ServerPackQuestPack.Usable(csv), kv.Key + ": a quest list (QuestFlag header and rows)");
Check.Eq(ServerPackQuestPack.CountRows(csv), kv.Value.Rows, kv.Key + ": the same rows as before the move");
string[] lines = csv.Replace("\r", "").Split('\n', StringSplitOptions.RemoveEmptyEntries);
string[] header = lines[0].Split(',');
int server = Array.FindIndex(header, h => h.Trim().Equals("Server", StringComparison.OrdinalIgnoreCase));
Check.True(server >= 0, kv.Key + ": has a Server column");
int other = lines.Skip(1).Count(l => l.Split(',')[server].Trim() != kv.Value.Name);
Check.Eq(other, 0, $"{kv.Key}: every row's Server is {kv.Value.Name} (the pack's tag, the plugin's server name)");
string csproj = File.ReadAllText(Path.Combine(plugins, kv.Value.Dir, kv.Value.Dir + ".csproj"));
Check.True(csproj.Contains("<RynthPluginServerId>" + kv.Key + "</RynthPluginServerId>")
&& csproj.Contains("<RynthPluginServerName>" + kv.Value.Name + "</RynthPluginServerName>"),
kv.Value.Dir + ": the pack's file name is its server id, the rows' Server its server name");
}
// No other server plugin carries a pack, and none carries another server's.
foreach (string dir in Directory.GetDirectories(plugins, "RynthCore.Plugin.Rynth*"))
{
string res = Path.Combine(dir, "Resources");
if (!Directory.Exists(res)) continue;
foreach (string f in Directory.GetFiles(res, "quests.*.csv"))
{
string id = Path.GetFileNameWithoutExtension(f).Substring("quests.".Length);
Check.True(expected.TryGetValue(id, out var e) && Path.GetFileName(dir) == e.Dir, $"{Path.GetFileName(dir)}/{Path.GetFileName(f)} is in its own server's plugin");
}
}
string oracle = Path.Combine(SuitePluginsDir(), "RynthCore.Plugin.RynthOracle");
string[] left = Directory.GetFiles(Path.Combine(oracle, "Resources"), "quests*.csv").Select(Path.GetFileName).ToArray()!;
Check.True(left.SequenceEqual(new[] { "quests.csv" }), "RynthOracle keeps only the retail list: " + string.Join(",", left));
Check.False(File.ReadAllText(Path.Combine(oracle, "RynthCore.Plugin.RynthOracle.csproj")).Contains("quests.conquest", StringComparison.OrdinalIgnoreCase),
"and embeds no server's pack");
string props = File.ReadAllText(Path.Combine(plugins, "Shared", "ServerPack", "ServerPlugin.props"));
Check.True(props.Contains("quests.$(RynthPluginServerId).csv") && props.Contains("LogicalName=\"" + ServerPackQuestPack.ResourceName + "\""),
"ServerPlugin.props embeds Resources\\quests.<server id>.csv as the served pack");
}
private const string Sample =
"QuestFlag,Server,Quest,Url,Info,Hint,Repeatable\n"
+ "aaaflag,Example,A quest,,,,FALSE\n"
+ "\n"
+ "bbbflag,Example,\"Another, with a comma\",,,,TRUE\n";
private static ServerPackInfo Example() => new("Example", "Example", new[] { "play.example.test" }, new[] { "Example" });
private static void InfoJson()
{
string json = ServerPackQuestPack.BuildInfoJson(Example(), "RynthExample", "0.1.0", Sample);
using JsonDocument doc = JsonDocument.Parse(json);
JsonElement root = doc.RootElement;
Check.Eq(root.GetProperty("schema").GetInt32(), ServerPackQuestPack.Schema, "schema");
Check.Eq(root.GetProperty("server").GetString(), "example", "server: the RynthCore id (lower case)");
Check.Eq(root.GetProperty("tag").GetString(), "Example", "tag: the server's name (the master list's Server column)");
Check.Eq(root.GetProperty("plugin").GetString(), "RynthExample", "plugin");
Check.Eq(root.GetProperty("version").GetString(), "0.1.0", "version");
Check.Eq(root.GetProperty("rows").GetInt32(), 2, "rows: data lines, blank ones skipped");
Check.Eq(root.GetProperty("bytes").GetInt32(), System.Text.Encoding.UTF8.GetByteCount(Sample), "bytes: the CSV's UTF-8 length");
Check.Eq(root.GetProperty("revision").GetInt32(), ServerPackQuestPack.Revision, "revision");
Check.Eq(ServerPackQuestPack.CountRows(Sample), 2, "CountRows");
Check.True(ServerPackQuestPack.Usable("QuestFlag,Server\nx,Example\n"), "a BOM before the header is fine");
Check.True(ServerPackQuestPack.Usable("Flag,Quest\r\nx,y\r\n"), "Flag works as the column name too (CRLF lines)");
}
private static void NoPack()
{
ServerPackInfo info = Example();
Check.Eq(ServerPackQuestPack.BuildInfoJson(info, "RynthExample", "0.1.0", null), "", "null: no pack");
Check.Eq(ServerPackQuestPack.BuildInfoJson(info, "RynthExample", "0.1.0", ""), "", "empty: no pack");
Check.Eq(ServerPackQuestPack.BuildInfoJson(info, "RynthExample", "0.1.0", "QuestFlag,Server\n"), "", "a header alone: no pack");
Check.Eq(ServerPackQuestPack.BuildInfoJson(info, "RynthExample", "0.1.0", "Name,Notes\na,b\n"), "", "no QuestFlag column: no pack");
Check.False(ServerPackQuestPack.Usable("<html>404</html>"), "junk is not usable");
}
private static void InfoAscii()
{
var odd = new ServerPackInfo("odd", "Odd \"Name\" é", new[] { "a" }, Array.Empty<string>());
string json = ServerPackQuestPack.BuildInfoJson(odd, "Rynth\\Odd", "1", Sample);
foreach (char c in json) Check.True(c >= 0x20 && c <= 0x7e, "plain ASCII: " + (int)c);
using JsonDocument doc = JsonDocument.Parse(json);
Check.Eq(doc.RootElement.GetProperty("tag").GetString(), "Odd \"Name\" é", "quotes and accents survive");
Check.Eq(doc.RootElement.GetProperty("plugin").GetString(), "Rynth\\Odd", "backslash survives");
}
}

View file

@ -0,0 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Tests for the server plugins (Plugins\Shared\ServerPack, built into RynthColdeve, RynthAelrynth, ...):
- the shared model (ServerPackModel.cs, ServerPackInfo.cs): RynthCore's "servermenu" verdict,
the world-name fallback, the override commands and the sections manifest;
- every server plugin's csproj, read as XML: unique ids, plugin names and hosts, and no
server's host claimed by another server's list (RynthCore would load the wrong plugin);
- the launcher's known-server catalog (RynthCore.App\KnownServerCatalog.cs): every entry names
a server plugin whose hosts claim the entry's host, with the same port and emulator.
The plugins are NativeAOT x86 libraries, so the pure sources are compiled in here directly.
The SDK's manifest file (BCL only) supplies RynthCore's host matching.
Run: dotnet run -c Release (exit 0 = pass, 1 = fail; an argument filters by test name)
-->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<!-- RynthServerProfileApi.cs declares the interface's (function-pointer) table. -->
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>RynthServerPack.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerPackInfo.cs" Link="Plugin\ServerPackInfo.cs" />
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerPackModel.cs" Link="Plugin\ServerPackModel.cs" />
<!-- The hooks for a server's own features: pages, the settings file, the own-reply window. -->
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerPackPages.cs" Link="Plugin\ServerPackPages.cs" />
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerPackSettings.cs" Link="Plugin\ServerPackSettings.cs" />
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerChatRequest.cs" Link="Plugin\ServerChatRequest.cs" />
<!-- RynthConquest's own features (pure parts) and the RynthOracle sources it links. -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestData.cs" Link="Conquest\ConquestData.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestFeature.cs" Link="Conquest\ConquestFeature.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\CustomQuests.cs" Link="Conquest\CustomQuests.cs" />
<Compile Include="$(RynthSuiteRoot)Plugins\RynthCore.Plugin.RynthOracle\Data\QuestFlags.cs" Link="Oracle\QuestFlags.cs" />
<Compile Include="$(RynthSuiteRoot)Plugins\RynthCore.Plugin.RynthOracle\Data\TimeText.cs" Link="Oracle\TimeText.cs" />
<Compile Include="$(RynthSuiteRoot)Plugins\RynthCore.Plugin.RynthOracle\Data\Csv.cs" Link="Oracle\Csv.cs" />
<EmbeddedResource Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Resources\customquests.csv" LogicalName="RynthConquest.customquests.csv" />
<!-- RynthAelrynth's own features (pure parts). -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAelrynth\Aelrynth\AelrynthBoards.cs" Link="Aelrynth\AelrynthBoards.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAelrynth\Aelrynth\AelrynthFeature.cs" Link="Aelrynth\AelrynthFeature.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAelrynth\Aelrynth\VaultFeed.cs" Link="Aelrynth\VaultFeed.cs" />
<!-- The difficulty tier RynthAelrynth publishes for RynthAi (and the value names, RynthServerProfileApi.cs). -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAelrynth\Aelrynth\AelrynthDifficulty.cs" Link="Aelrynth\AelrynthDifficulty.cs" />
<Compile Include="$(RynthSuiteRoot)Plugins\Shared\RynthServerProfileApi.cs" Link="Shared\RynthServerProfileApi.cs" />
<Compile Include="$(RynthSuiteRoot)Plugins\Shared\ChatSource.cs" Link="Shared\ChatSource.cs" />
<Compile Include="$(RynthSuiteRoot)Plugins\Shared\StorageFeed.cs" Link="Shared\StorageFeed.cs" />
<!-- RynthCore's own sections-manifest parser (pure), so the manifest is checked the way the engine reads it. -->
<Compile Include="..\..\..\RynthCore\src\RynthCore.Engine\UI\Sections\SectionManifest.cs" Link="Engine\SectionManifest.cs" />
<!-- "RynthServer.Profile": the profile JSON, and the shared reader's parser that consumes it. -->
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerPackProfile.cs" Link="Plugin\ServerPackProfile.cs" />
<!-- "RynthServer.QuestPack": a server plugin's own quest list (the info JSON; the pack itself is data). -->
<Compile Include="..\..\Plugins\Shared\ServerPack\ServerPackQuestPack.cs" Link="Plugin\ServerPackQuestPack.cs" />
<!-- RynthConquest's pack, under the logical name ServerPlugin.props gives it, so the served pack is checked as embedded. -->
<EmbeddedResource Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Resources\quests.conquest.csv" LogicalName="ServerPack.quests.csv" />
<Compile Include="$(RynthSuiteRoot)Plugins\Shared\EngineServerState.cs" Link="Shared\EngineServerState.cs" />
<Compile Include="..\..\..\RynthCore\src\RynthCore.PluginSdk\Manifest\RynthPluginManifest.cs" Link="Sdk\RynthPluginManifest.cs" />
<!-- The launcher's known-server picker, checked against the plugins it names. -->
<Compile Include="..\..\..\RynthCore\src\RynthCore.App\LaunchServerProfile.cs" Link="Launcher\LaunchServerProfile.cs" />
<Compile Include="..\..\..\RynthCore\src\RynthCore.App\KnownServerCatalog.cs" Link="Launcher\KnownServerCatalog.cs" />
<!-- The RynthAi test tools' check/runner harness (no plugin code in it). -->
<Compile Include="$(RynthSuiteRoot)Tools\RynthCore.RynthAiTests\Harness\Check.cs" Link="Harness\Check.cs" />
<Compile Include="$(RynthSuiteRoot)Tools\RynthCore.RynthAiTests\Harness\Runner.cs" Link="Harness\Runner.cs" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using RynthCore.Engine.UI.Sections;
using RynthCore.Plugin.ServerPack;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// The shared hooks a server plugin's own features use (2026-10-20, when RynthOracle's and
// RynthInventory's Conquest and Aelrynth features moved into RynthConquest and RynthAelrynth):
// pages beside the server card, the plugin's own settings file (with a one-time migration), live
// numbers in the "RynthServer.Profile" JSON, and the own-reply window.
internal static class ServerPackHooksTests
{
public static void Register(Runner r)
{
r.Add("hooks: page ids, surfaces and the surface a page is drawn under", PageNames);
r.Add("hooks: bad, duplicate and surplus pages are left out", PageValidation);
r.Add("hooks: pages are server-only primary views of the Server section, accepted by RynthCore's parser", PagesInManifest);
r.Add("hooks: settings round-trip and keep values the plugin doesn't know", SettingsRoundTrip);
r.Add("hooks: settings migration runs once, and a broken file means defaults", SettingsMigration);
r.Add("hooks: profile values are published, validated and read back", ProfileValues);
r.Add("hooks: the own-reply window opens, stretches and closes", ReplyWindow);
}
internal static string TempDir()
{
string dir = Path.Combine(Path.GetTempPath(), "RynthServerPack.Tests", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
return dir;
}
private static void PageNames()
{
Check.True(ServerPackPages.IsValidId("bank") && ServerPackPages.IsValidId("top-10"), "plain ids");
Check.False(ServerPackPages.IsValidId("") || ServerPackPages.IsValidId("Bank") || ServerPackPages.IsValidId("a.b")
|| ServerPackPages.IsValidId(new string('a', 17)), "empty, capitals, dots and long ids are refused");
Check.Eq(ServerPackPages.SurfaceFor("conquest", "bank"), "section:server-conquest.bank", "surface");
Check.Eq(ServerPackPages.PageIdOf("section:server-conquest.bank", "conquest"), "bank", "page from its surface");
Check.Eq(ServerPackPages.PageIdOf("section:server-conquest.bank:popout", "conquest"), "bank", "popped out");
Check.Null(ServerPackPages.PageIdOf("section:server-conquest", "conquest"), "the card is not a page");
Check.Null(ServerPackPages.PageIdOf("section:server-aelrynth.top", "conquest"), "another server's page");
Check.Null(ServerPackPages.PageIdOf("section:server-conquest.Bad!", "conquest"), "a malformed page id");
Check.Null(ServerPackPages.PageIdOf(null, "conquest"), "null");
string longest = ServerPackPages.SurfaceFor(new string('a', 32), new string('b', ServerPackPages.MaxIdLength));
Check.True(longest.Length <= SectionManifestParser.MaxSurfaceLength, "the longest surface fits RynthCore's cap: " + longest.Length);
}
private static void PageValidation()
{
Action draw = () => { };
var notes = new List<string>();
var pages = new List<ServerPage>
{
new("one", "One", "", draw), new("one", "Again", "", draw), new("Two", "Two", "", draw),
new("three", " ", "", draw), new("four", "Four", "tip", null!),
};
for (int i = 0; i < 8; i++) pages.Add(new ServerPage("p" + i, "Page " + i, "", draw));
List<ServerPage> kept = ServerPackPages.Validate(pages, notes.Add);
Check.Eq(kept.Count, ServerPackPages.MaxPages, "capped");
Check.Eq(kept[0].Id, "one", "first kept");
Check.Eq(kept.Count(p => p.Id == "one"), 1, "a duplicate id is dropped");
Check.False(kept.Any(p => p.Id is "Two" or "three" or "four"), "bad id, no label, nothing to draw");
Check.True(notes.Count == pages.Count - kept.Count, "every dropped page is reported: " + string.Join(" | ", notes));
Check.Eq(ServerPackPages.Validate(null).Count, 0, "no pages");
string label = new string('x', 60);
Check.Eq(ServerPackPages.Validate(new[] { new ServerPage("x", label, "", draw) })[0].Label.Length, ServerPackPages.MaxLabelLength, "label capped");
}
private static void PagesInManifest()
{
ServerPackInfo info = new("conquest", "Conquest", new[] { "acconquest.ddns.net" }, new[] { "Conquest" });
var pages = ServerPackPages.Validate(new[]
{
new ServerPage("main", "Conquest", "Bank, augs and more", () => { }),
new ServerPage("boards", "Leaderboards", "", () => { }),
});
string json = ServerPackModel.BuildSectionsJson(info, "RynthConquest", pages);
SectionManifest m = SectionManifestParser.Parse("RynthConquest", json, out string error);
Check.Eq(error, "", "RynthCore parses it");
Check.Eq(m.Contributions.Length, 3, "the card and two pages");
SectionContribution card = m.Contributions.Single(c => !c.Primary);
Check.Eq(card.Surface, "section:server-conquest", "the card keeps its surface");
SectionContribution[] views = m.Contributions.Where(c => c.Primary).ToArray();
Check.True(views.All(c => c.Section == ServerPackModel.SectionId && c.Server == "conquest" && c.IsSurface),
"pages: primary views of the Server section, only on Conquest");
Check.Eq(views[0].Surface, "section:server-conquest.main", "page surface");
Check.Eq(views[0].Label, "Conquest", "page label");
Check.Eq(views[0].Tooltip, "Bank, augs and more", "page tooltip");
Check.Eq(views[1].Tooltip, "Leaderboards (RynthConquest)", "a default tooltip");
Check.True(views[0].Order < views[1].Order, "pages keep their order");
Check.True(views[0].Width > 0 && views[0].Height > 0, "pages say their size");
// Without pages the manifest is byte for byte what it was.
Check.Eq(ServerPackModel.BuildSectionsJson(info, "RynthConquest", null), ServerPackModel.BuildSectionsJson(info, "RynthConquest"),
"no pages: the old manifest");
Check.Eq(SectionManifestParser.Parse("x", ServerPackModel.BuildSectionsJson(info, "RynthConquest"), out _).Contributions.Length, 1,
"no pages: only the card");
}
private static void SettingsRoundTrip()
{
string dir = TempDir();
try
{
string path = Path.Combine(dir, "rynthtest.json");
File.WriteAllText(path, "{ \"future\": {\"a\":[1,2]}, \"flag\": false, \"name\": \"x\" }");
var s = new ServerPackSettings(path);
s.Load();
Check.Eq(s.LastError, "", "read");
Check.False(s.GetBool("flag", true), "a stored false");
Check.True(s.GetBool("missing", true), "a missing value falls back");
Check.True(s.GetBool("name", true), "a value of another type falls back");
Check.Eq(s.GetString("name", "?"), "x", "text");
Check.True(s.SetBool("flag", true), "a change says so");
Check.False(s.SetBool("flag", true), "the same value is no change");
s.SetString("quote", "a \"b\" \\ c");
Check.True(s.Save(), "saved");
var again = new ServerPackSettings(path);
again.Load();
Check.True(again.GetBool("flag", false), "the change was kept");
Check.Eq(again.GetString("quote", ""), "a \"b\" \\ c", "text escaped and read back");
using JsonDocument doc = JsonDocument.Parse(File.ReadAllText(path));
Check.Eq(doc.RootElement.GetProperty("future").GetProperty("a").GetArrayLength(), 2, "an unknown value is written back as it was");
Check.False(File.Exists(path + ".tmp"), "no temporary file left");
Check.True(ServerPackSettings.DefaultPath("RynthConquest").EndsWith(Path.Combine("RynthCore", "rynthconquest.json"), StringComparison.Ordinal),
"%APPDATA%\\RynthCore\\<plugin>.json");
}
finally { try { Directory.Delete(dir, true); } catch { } }
}
private static void SettingsMigration()
{
string dir = TempDir();
try
{
string old = Path.Combine(dir, "old.json"), mine = Path.Combine(dir, "mine.json");
File.WriteAllText(old, "{ \"moved\": true, \"text\": \"t\" }");
Check.Eq(ServerPackSettings.ReadBoolFrom(old, "moved"), (bool?)true, "the old home's value");
Check.Null(ServerPackSettings.ReadBoolFrom(old, "text"), "not a true/false value");
Check.Null(ServerPackSettings.ReadBoolFrom(old, "absent"), "missing value");
Check.Null(ServerPackSettings.ReadBoolFrom(Path.Combine(dir, "nope.json"), "moved"), "missing file");
var s = new ServerPackSettings(mine);
s.Load();
int runs = 0;
Action<ServerPackSettings> migrate = t => { runs++; if (ServerPackSettings.ReadBoolFrom(old, "moved") is bool b) t.SetBool("moved", b); };
Check.True(s.MigrateOnce("migratedFromOld", migrate), "runs the first time");
Check.True(s.GetBool("moved", false), "imported");
File.WriteAllText(old, "{ \"moved\": false }");
var later = new ServerPackSettings(mine);
later.Load();
Check.False(later.MigrateOnce("migratedFromOld", migrate), "never again (the marker was saved)");
Check.True(later.GetBool("moved", false), "later changes to the old home don't come over");
Check.Eq(runs, 1, "ran once");
File.WriteAllText(mine, "{ not json");
var broken = new ServerPackSettings(mine);
broken.Load();
Check.True(broken.LastError.Length > 0 && broken.GetBool("moved", true), "a broken file reads as defaults");
}
finally { try { Directory.Delete(dir, true); } catch { } }
}
private static void ProfileValues()
{
var v = new ServerProfileValues();
int r0 = v.Revision;
Check.True(v.Set("voidDotDurationScale", 1.35), "set");
Check.True(v.Revision > r0, "a change bumps the revision");
int r1 = v.Revision;
Check.True(v.Set("voidDotDurationScale", 1.35) && v.Revision == r1, "the same value is no change");
Check.False(v.Set("bad key", 1) || v.Set("", 1) || v.Set("x", double.NaN) || v.Set("y", double.PositiveInfinity), "bad keys and numbers");
ServerPackInfo info = new("conquest", "Conquest", new[] { "h" }, new[] { "Conquest" });
string json = ServerPackProfile.BuildJson(info, "RynthConquest", "0.2.0", true, "Conquest", v.Snapshot(out int rev));
Check.Eq(rev, v.Revision, "the snapshot's revision");
Check.Near(RynthCore.Plugin.Shared.ServerProfileView.Value(json, "voidDotDurationScale", 1), 1.35, 1e-12, "a reader gets the value");
Check.Eq(RynthCore.Plugin.Shared.ServerProfileView.Value(json, "other", 7), 7.0, "a missing value falls back");
Check.Eq(RynthCore.Plugin.Shared.ServerProfileView.Value("", "voidDotDurationScale", 1), 1.0, "no profile falls back");
Check.Eq(RynthCore.Plugin.Shared.ServerProfileView.Value("{\"values\":{\"k\":\"2\"}}", "k", 1), 1.0, "text is not a number");
Check.Eq(RynthCore.Plugin.Shared.ServerProfileView.Value("{broken", "k", 3), 3.0, "broken JSON falls back");
using (JsonDocument doc = JsonDocument.Parse(ServerPackProfile.BuildJson(info, "RynthConquest", "0.2.0", true, "Conquest")))
Check.Eq(doc.RootElement.GetProperty("values").EnumerateObject().Count(), 0, "no values: an empty object");
Check.True(v.Remove("voidDotDurationScale") && !v.Remove("voidDotDurationScale"), "remove");
v.Set("a", 1);
int r2 = v.Revision;
v.Clear();
Check.True(v.Revision > r2 && v.Snapshot(out _).Length == 0, "clear (logout)");
}
private static void ReplyWindow()
{
var req = new ServerChatRequest();
Check.False(req.Awaiting(0), "nothing asked");
req.Sent(1000);
Check.True(req.Awaiting(1000 + ServerChatRequest.WindowMs - 1), "inside the window");
Check.False(req.Awaiting(1000 + ServerChatRequest.WindowMs), "the window closes");
req.Sent(1000);
req.Extend(5500);
Check.True(req.Awaiting(7000), "a reply line stretches it");
req.Clear();
Check.False(req.Awaiting(1001), "cleared");
}
}

View file

@ -0,0 +1,243 @@
using System;
using System.Linq;
using System.Text.Json;
using RynthCore.Plugin.ServerPack;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// The shared server-plugin model (Plugins\Shared\ServerPack\ServerPackModel.cs): RynthCore's
// "servermenu" verdict for the plugin's own server, the world-name fallback before one arrives,
// the override commands the card sends, and the sections manifest RynthCore reads.
internal static class ServerPackModelTests
{
public static void Register(Runner r)
{
r.Add("server pack: RynthCore's push gives this server's verdict, override and reason", EnginePush);
r.Add("server pack: a push without this server, or not a push, changes nothing", ForeignPush);
r.Add("server pack: before any push the world name decides", WorldFallback);
r.Add("server pack: override commands are checked before sending", ForceCommands);
r.Add("server pack: the sections manifest declares the server and a server-only card", SectionsJson);
r.Add("server pack: logout clears the verdict", ClearOnLogout);
r.Add("server pack: the card's botting line and address", InfoText);
r.Add("server pack: the RynthServer.Profile JSON carries the server's settings", ProfileJson);
r.Add("server pack: the profile JSON is plain ASCII and escaped", ProfileJsonAscii);
}
private static void ProfileJson()
{
ServerPackInfo info = new("Coldeve", "Coldeve", new[] { "play.coldeve.ac" }, new[] { "Coldeve" })
{
Port = 9050, Ruleset = "PvP", Status = "Stable", Botting = BottingPolicy.Restricted, BottingNote = "attended only",
AccountLimit = "3 accounts", Facts = new[] { "fact one" }, Commands = new[] { new ServerCommand("/x", "does x") },
Discord = "https://discord.gg/x",
};
string json = ServerPackProfile.BuildJson(info, "RynthColdeve", "0.1.2", true, "Coldeve");
using JsonDocument doc = JsonDocument.Parse(json);
JsonElement root = doc.RootElement;
Check.Eq(root.GetProperty("schema").GetInt32(), ServerPackProfile.Schema, "schema");
Check.Eq(root.GetProperty("id").GetString(), "coldeve", "id (lower-cased)");
Check.Eq(root.GetProperty("plugin").GetString(), "RynthColdeve", "plugin");
Check.Eq(root.GetProperty("version").GetString(), "0.1.2", "version");
Check.True(root.GetProperty("active").GetBoolean(), "active");
Check.Eq(root.GetProperty("world").GetString(), "Coldeve", "world");
Check.Eq(root.GetProperty("hosts")[0].GetString(), "play.coldeve.ac", "hosts");
Check.Eq(root.GetProperty("port").GetInt32(), 9050, "port");
Check.Eq(root.GetProperty("ruleset").GetString(), "PvP", "ruleset");
Check.Eq(root.GetProperty("botting").GetString(), "restricted", "botting");
Check.Eq(root.GetProperty("bottingNote").GetString(), "attended only", "botting note");
Check.Eq(root.GetProperty("facts")[0].GetString(), "fact one", "facts");
Check.Eq(root.GetProperty("commands")[0].GetProperty("what").GetString(), "does x", "commands");
Check.Eq(root.GetProperty("discord").GetString(), "https://discord.gg/x", "links");
// What a reader (RynthOracle, RynthAi's /ra server) makes of it.
var view = RynthCore.Plugin.Shared.ServerProfileView.Parse(json);
Check.True(view != null, "the shared reader parses it");
Check.Eq(view!.Summary(), "PvP, ACE; botting restricted - attended only; accounts: 3 accounts", "the reader's summary");
// No salvage defined: an empty list, which the Crafting tab reads as "none defined".
Check.Eq(root.GetProperty("salvage").GetArrayLength(), 0, "no salvage: empty list");
Check.Eq(RynthCore.Plugin.Shared.ServerSalvageView.ParseList(json).Count, 0, "the reader sees none");
// Salvage defined: each row round-trips through the shared reader.
ServerPackInfo withSalvage = new("x", "X", new[] { "x.example" }, new[] { "X" })
{
Salvage = new[]
{
new ServerSalvage("melee", 52, "+1 tink past the cap", "once", UsesTinkSlot: false),
new ServerSalvage("Armor", 64, "+30 armor level"),
new ServerSalvage("", 64, "no bench: skipped"),
},
};
var salvage = RynthCore.Plugin.Shared.ServerSalvageView.ParseList(
ServerPackProfile.BuildJson(withSalvage, "RynthX", "1", true, "X"));
Check.Eq(salvage.Count, 2, "rows without a bench are skipped");
Check.Eq(salvage[0].Bench, "melee", "bench");
Check.Eq(salvage[0].Material, 52, "material id");
Check.Eq(salvage[0].Kind, "once", "kind");
Check.False(salvage[0].UsesTinkSlot, "no tink slot");
Check.Eq(salvage[1].Bench, "armor", "bench lower-cased");
Check.Eq(salvage[1].Kind, "tink", "default kind");
Check.True(salvage[1].UsesTinkSlot, "slot by default");
Check.Eq(RynthCore.Plugin.Shared.ServerSalvageView.ParseList("{\"id\":\"x\"}").Count, 0, "a profile without the list (older plugins)");
// The optional row fields: absent = off / the default, and the writer leaves them out then.
Check.True(salvage.All(v => v.AppliedInt == 0 && !v.Prepared && v.Order == 0 && !v.AfterCap
&& v.StackGroup.Length == 0 && v.StackCap == 0), "optional fields default when absent");
string plain = ServerPackProfile.BuildJson(withSalvage, "RynthX", "1", true, "X");
Check.True(!plain.Contains("\"applied\"") && !plain.Contains("\"prepared\"") && !plain.Contains("\"order\"")
&& !plain.Contains("\"afterCap\"") && !plain.Contains("\"stackGroup\""), "unset fields are not written");
ServerPackInfo withRules = new("x", "X", new[] { "x.example" }, new[] { "X" })
{
Salvage = new[]
{
new ServerSalvage("melee", 52, "post-cap", "once", UsesTinkSlot: false, Order: 995, AfterCap: true),
new ServerSalvage("jewelry", 71, "stack", UsesTinkSlot: false, Order: 50, StackGroup: "jewelry-stack", StackCap: 10),
new ServerSalvage("trinkets", 20, "tier", "once", UsesTinkSlot: false, AppliedInt: 384, Prepared: true, Order: 10),
},
};
var rules = RynthCore.Plugin.Shared.ServerSalvageView.ParseList(
ServerPackProfile.BuildJson(withRules, "RynthX", "1", true, "X"));
Check.Eq(rules.Count, 3, "rows with rules");
Check.True(rules[0].AfterCap && rules[0].Order == 995 && !rules[0].Prepared && rules[0].StackGroup.Length == 0, "after cap + order");
Check.Eq(rules[1].StackGroup, "jewelry-stack", "stack group");
Check.Eq(rules[1].StackCap, 10, "stack cap");
Check.True(rules[2].Prepared && rules[2].AppliedInt == 384 && rules[2].Order == 10 && !rules[2].AfterCap, "prepared + applied + order");
Check.Eq(RynthCore.Plugin.Shared.ServerSalvageView.ParseList(
"{\"salvage\":[{\"bench\":\"jewelry\",\"material\":64,\"stackGroup\":\"g\"},{\"bench\":\"jewelry\",\"material\":71,\"stackGroup\":\"g\",\"stackCap\":0}]}")
.Count(v => v.StackGroup.Length > 0), 0, "a stack group without a positive cap is no group");
var odd = RynthCore.Plugin.Shared.ServerSalvageView.ParseList(
"{\"salvage\":[{\"bench\":\"melee\",\"material\":52,\"applied\":\"x\",\"prepared\":1,\"order\":null,\"afterCap\":\"yes\"}]}");
Check.True(odd.Count == 1 && odd[0].AppliedInt == 0 && !odd[0].Prepared && odd[0].Order == 0 && !odd[0].AfterCap,
"fields of the wrong type read as absent");
string idle = ServerPackProfile.BuildJson(info, "RynthColdeve", "0.1.2", false, null);
using JsonDocument idleDoc = JsonDocument.Parse(idle);
Check.False(idleDoc.RootElement.GetProperty("active").GetBoolean(), "not active");
Check.Eq(idleDoc.RootElement.GetProperty("world").GetString(), "", "no world before login");
Check.Eq(ServerPackProfile.BottingName(BottingPolicy.Unknown), "unknown", "unknown botting");
}
private static void ProfileJsonAscii()
{
ServerPackInfo info = new("x", "Caf\u00e9 \"Q\"\n", Array.Empty<string>(), Array.Empty<string>()) { Summary = "a\\b\tc \u2014 d" };
string json = ServerPackProfile.BuildJson(info, "RynthX", "1", false, "");
bool ascii = true;
foreach (char c in json) if (c > 0x7e || c < 0x20) ascii = false;
Check.True(ascii, "only printable ASCII: " + json);
using JsonDocument doc = JsonDocument.Parse(json);
Check.Eq(doc.RootElement.GetProperty("name").GetString(), "Caf\u00e9 \"Q\"", "name round-trips (trimmed)");
Check.Eq(doc.RootElement.GetProperty("summary").GetString(), "a\\b\tc \u2014 d", "summary round-trips");
}
private static ServerPackInfo Coldeve() =>
new("Coldeve", "Coldeve", new[] { "play.coldeve.ac" }, new[] { "Coldeve" }) { Discord = "https://discord.gg/x" };
private const string Push =
"V\tcoldeve\tColdeve\t1\ton\t0\tforced on for this character\n" +
"V\tilt\tInfinite Leaftide\t0\tauto\t0\tnot Infinite Leaftide\n" +
"X\tchar\tChar\n" +
"S\tcoldeve\tColdeve\t1\t/rc server coldeve on\n" +
"I\tColdeve server (RynthColdeve)\t/rc miniremote section char\tWhat is known.\tsection:char\n";
private static void EnginePush()
{
var model = new ServerPackModel(Coldeve());
Check.True(model.ApplyEngine(Push, 1234), "taken");
ServerVerdictView? v = model.Engine;
Check.True(v != null, "this server's verdict");
Check.True(v!.Active, "active");
Check.Eq(v.Force, "on", "override");
Check.False(v.Detected, "forced, not detected");
Check.Eq(v.Reason, "forced on for this character", "reason");
Check.Eq(model.EngineAtMs, 1234L, "when");
Check.True(model.IsActive("SomewhereElse"), "RynthCore's verdict beats the world name");
}
private static void ForeignPush()
{
var model = new ServerPackModel(Coldeve());
Check.False(model.ApplyEngine("X\tchar\tChar\n", 1), "no server lines: not a push");
Check.False(model.ApplyEngine(null, 1), "null");
Check.False(model.ApplyEngine(new string('V', ServerPackModel.MaxPayload + 1), 1), "too long");
Check.True(model.Engine == null, "nothing published");
// A push that lists other servers but not this one yet (RynthCore hasn't read the manifest).
Check.True(model.ApplyEngine("V\tilt\tInfinite Leaftide\t1\tauto\t1\thost matches\n", 2), "a push");
Check.True(model.Engine == null, "no verdict for this server");
ServerPackModel.ParseEngine("V\tCOLDEVE\tColdeve\t0\tweird\t1\n", "coldeve", out bool listed);
Check.True(listed, "listed");
Check.Eq(ServerPackModel.ParseEngine("V\tCOLDEVE\tColdeve\t0\tweird\t1\n", "coldeve", out _)!.Force, "auto",
"id case ignored; an unknown override reads as auto; no reason field is fine");
}
private static void WorldFallback()
{
var model = new ServerPackModel(Coldeve());
Check.True(model.IsActive("Coldeve"), "exact world name");
Check.True(model.IsActive(" coldeve "), "case and spaces");
Check.False(model.IsActive("ColdeveTwo"), "no partial match without '*'");
Check.False(model.IsActive(null), "unknown world");
Check.True(ServerPackModel.WorldMatches("Aeshnidae Live", new[] { "Aelrynth*", "Aeshnidae*" }), "wildcard");
Check.False(ServerPackModel.WorldMatches("LeafDawn", new[] { "Leafdawning" }), "LeafDawn is not Leafdawning");
Check.True(ServerPackModel.WorldMatches("Infinite Leaftide", new[] { "*Leaftide*" }), "both ends");
}
private static void ForceCommands()
{
Check.Eq(ServerPackModel.ForceCommand("coldeve", "On"), "/rc server coldeve on", "on");
Check.Eq(ServerPackModel.ForceCommand("coldeve", "auto"), "/rc server coldeve auto", "auto");
Check.Eq(ServerPackModel.ForceCommand("coldeve", "maybe"), "", "unknown mode");
Check.Eq(ServerPackModel.ForceCommand("cold eve", "on"), "", "an id with a space");
Check.Eq(ServerPackModel.ForceCommand("coldeve; /quit", "on"), "", "no command injection through the id");
Check.False(ServerPackModel.IsSafeId(new string('a', 33)), "too long");
}
private static void SectionsJson()
{
string json = ServerPackModel.BuildSectionsJson(Coldeve(), "RynthColdeve");
using JsonDocument doc = JsonDocument.Parse(json);
JsonElement root = doc.RootElement;
Check.Eq(root.GetProperty("version").GetInt32(), 1, "schema 1");
JsonElement server = root.GetProperty("servers")[0];
Check.Eq(server.GetProperty("id").GetString(), "coldeve", "server id lower-cased");
Check.Eq(server.GetProperty("hosts")[0].GetString(), "play.coldeve.ac", "hosts");
Check.Eq(server.GetProperty("worldNames")[0].GetString(), "Coldeve", "world names");
JsonElement card = root.GetProperty("contributions")[0];
Check.Eq(card.GetProperty("section").GetString(), "server", "in the Server section (not Session Stats)");
JsonElement section = root.GetProperty("sections")[0];
Check.Eq(section.GetProperty("id").GetString(), "server", "the Server section is declared");
Check.Eq(section.GetProperty("label").GetString(), "Server", "its label");
Check.Eq(section.GetProperty("order").GetInt32(), 50, "after Session Stats, before Map");
Check.Eq(card.GetProperty("server").GetString(), "coldeve", "only while Coldeve is active");
Check.Eq(card.GetProperty("surface").GetString(), "section:server-coldeve", "the card's surface");
var quoted = new ServerPackInfo("odd", "Odd \"Name\"\n", new[] { "a\\b" }, Array.Empty<string>());
using JsonDocument odd = JsonDocument.Parse(ServerPackModel.BuildSectionsJson(quoted, "RynthOdd"));
Check.Eq(odd.RootElement.GetProperty("servers")[0].GetProperty("hosts")[0].GetString(), "a\\b", "escaped");
}
private static void ClearOnLogout()
{
var model = new ServerPackModel(Coldeve());
model.ApplyEngine(Push, 5);
model.Clear();
Check.True(model.Engine == null, "verdict cleared");
Check.Eq(model.EngineAtMs, 0L, "time cleared");
Check.False(model.IsActive("Elsewhere"), "back to the world name");
}
private static void InfoText()
{
ServerPackInfo c = Coldeve();
Check.Eq(c.Address, "play.coldeve.ac:9000", "address");
Check.True(c.BottingText.StartsWith("Not published"), "unknown policy says so");
Check.True(c.BottingText.Contains("Discord"), "and points at the Discord");
var lev = new ServerPackInfo("example", "Example", new[] { "play.example.test" }, new[] { "Example" })
{ Botting = BottingPolicy.Forbidden, BottingNote = "no automation" };
Check.Eq(lev.BottingText, "Forbidden - no automation", "forbidden");
Check.Eq(new ServerPackInfo("x", "", Array.Empty<string>(), Array.Empty<string>()).Address, "", "no host, no address");
Check.True(ServerPackModel.LauncherSteps(c)[0].Contains("play.coldeve.ac:9000"), "setup names the address");
}
}

View file

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using RynthCore.PluginSdk.Manifest;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// Every server plugin's csproj (Plugins\RynthCore.Plugin.Rynth*\ with RynthPluginServerId), read as
// XML: the detection data RynthCore's loader and sections use must be unique and must not overlap,
// or a client would load (or show) the wrong server's plugin.
internal static class ServerProjectsTests
{
public static void Register(Runner r)
{
r.Add("server projects: every listed server has a plugin", AllServersPresent);
r.Add("server projects: ids, plugin names and hosts are unique", Unique);
r.Add("server projects: no server's host is claimed by another server's list", NoHostOverlap);
r.Add("server projects: each new server plugin has ServerData.cs and imports the shared props", Layout);
}
// The shared plugins' own check (they name no server, send no server's commands) is RynthSuite's
// (Tools/RynthSuite.BoundaryTests) since the server plugins moved to RynthServers (2026-10-21).
private sealed record Project(string Dir, string PluginName, string Id, string Name, string[] Hosts, string[] Worlds, bool Shared);
/// <summary>The servers in the request (the server list's busiest, plus Aelrynth) and their plugins.</summary>
private static readonly string[] Expected =
{
"coldeve", "ilt", "frostace", "reefcull", "conquest", "dreamweave", "portalstorm", "sundering",
"achard", "leafdawn", "derptide", "frostcull", "thistlecrown", "eversong", "leafdawning", "aelrynth",
// Added 2026-10-21 with its quest pack (it was RynthOracle's).
"levistras",
};
private static string PluginsDir()
{
string? dir = AppContext.BaseDirectory;
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
dir = Path.GetDirectoryName(dir);
if (dir == null) throw new DirectoryNotFoundException("RynthSuite\\Plugins not found above " + AppContext.BaseDirectory);
return Path.Combine(dir, "Plugins");
}
private static List<Project> Load()
{
var list = new List<Project>();
foreach (string dir in Directory.GetDirectories(PluginsDir(), "RynthCore.Plugin.Rynth*"))
{
string csproj = Path.Combine(dir, Path.GetFileName(dir) + ".csproj");
if (!File.Exists(csproj)) continue;
XDocument doc = XDocument.Load(csproj);
string Prop(string name) => doc.Descendants(name).FirstOrDefault()?.Value.Trim() ?? "";
string id = Prop("RynthPluginServerId");
if (id.Length == 0) continue;
string[] Split(string v) => v.Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
bool shared = doc.Descendants("Import").Any(i => (i.Attribute("Project")?.Value ?? "").EndsWith("ServerPlugin.props"));
string asm = Prop("AssemblyName");
list.Add(new Project(dir, asm.Replace("RynthCore.Plugin.", ""), id, Prop("RynthPluginServerName"),
Split(Prop("RynthPluginServerHosts")), Split(Prop("RynthPluginServerWorldNames")), shared));
}
return list;
}
private static void AllServersPresent()
{
List<Project> projects = Load();
foreach (string id in Expected)
Check.True(projects.Any(p => p.Id == id), "a server plugin for " + id);
Check.Eq(projects.Count, Expected.Length, "no unexpected server plugins");
}
private static void Unique()
{
List<Project> projects = Load();
Check.Eq(projects.Select(p => p.Id).Distinct().Count(), projects.Count, "ids unique");
Check.Eq(projects.Select(p => p.PluginName.ToLowerInvariant()).Distinct().Count(), projects.Count, "plugin names unique");
var hosts = projects.SelectMany(p => p.Hosts).Select(h => h.ToLowerInvariant()).ToList();
Check.Eq(hosts.Distinct().Count(), hosts.Count, "hosts unique");
foreach (Project p in projects)
{
Check.True(p.Hosts.Length > 0, p.PluginName + " lists a host (the loader picks plugins by host)");
Check.True(p.Worlds.Length > 0, p.PluginName + " lists a world name");
Check.True(p.Name.Length > 0, p.PluginName + " has a display name");
}
}
private static void NoHostOverlap()
{
List<Project> projects = Load();
foreach (Project owner in projects)
foreach (string host in owner.Hosts.Where(h => !h.Contains('*')))
foreach (Project other in projects.Where(o => o != owner))
{
var server = new RynthPluginServer { Id = other.Id, Hosts = other.Hosts.ToList() };
Check.False(server.MatchesHost(host, out string hit),
$"{owner.PluginName}'s host {host} is not claimed by {other.PluginName} ({hit})");
}
}
private static void Layout()
{
foreach (Project p in Load().Where(p => p.Id != "ilt"))
{
Check.True(p.Shared, p.PluginName + " imports Shared\\ServerPack\\ServerPlugin.props");
Check.True(File.Exists(Path.Combine(p.Dir, "ServerData.cs")), p.PluginName + " has ServerData.cs");
}
}
}

View file

@ -0,0 +1,229 @@
using System.Collections.Generic;
using RynthCore.Plugin.RynthAelrynth;
using RynthCore.Plugin.Shared;
using RynthCore.RynthAiTests.Harness;
namespace RynthServerPack.Tests;
// The Aelrynth account vault: /mule-data answers, one "~ael1" line a page (Aeshnidae.Mule MuleData.cs).
// Moved with the feed from RynthInventory.Tests on 2026-10-20: RynthAelrynth reads the vault now and
// hands it to RynthInventory through the storage feed (Plugins/Shared/StorageFeed.cs).
internal static class VaultTests
{
public static void Register(Runner r)
{
r.Add("vault: pages are asked one after the other and filed as one record", Pages);
r.Add("vault: other plugins' lines and players' imitations are left alone", Imitations);
r.Add("vault: a server without the command is asked once", Unsupported);
r.Add("vault: loading, changed and silent vaults are never filed half or empty", Retries);
r.Add("vault: RynthAelrynth asks after login, every ten minutes and on /rserver vault", Schedule);
r.Add("vault: the record reaches RynthInventory's format intact (plain ASCII)", HandOff);
}
private const string A = "{\"o\":2147483649,\"w\":100,\"n\":\"Acid Assagai\",\"i\":100667000,\"u\":100667001,\"v\":100667002,\"s\":3,\"m\":100,\"y\":1,\"e\":1}";
private const string B = "{\"o\":2147483650,\"w\":101,\"n\":\"Pyreal\",\"i\":100667003,\"y\":8192}";
private static string VaultPage(int page, int pages, int count, string items, bool ready = true, string why = "") =>
ready
? "~ael1 {\"t\":\"mule\",\"ready\":true,\"page\":" + page + ",\"pages\":" + pages + ",\"count\":" + count + ",\"max\":1000,\"items\":[" + items + "]}"
: "~ael1 {\"t\":\"mule\",\"ready\":false,\"why\":\"" + why + "\"}";
private static (VaultFeed Feed, List<string> Sent) NewVault()
{
var sent = new List<string>();
return (new VaultFeed(t => { sent.Add(t); return true; }), sent);
}
private static void Pages()
{
(VaultFeed v, List<string> sent) = NewVault();
Check.True(v.Ask(1000), "ask starts");
Check.Eq(sent.Count == 1 ? sent[0] : "?", "/mule-data", "page 1 asked first");
Check.True(v.ShouldEat(VaultPage(1, 2, 2, A)), "page 1 is eaten");
v.Tick(1100, "Tom");
Check.Eq(sent.Count == 2 ? sent[1] : "?", "/mule-data 2", "page 2 asked when page 1 came");
Check.Null(v.Record, "nothing filed before the last page");
Check.True(v.ShouldEat(VaultPage(2, 2, 2, B)), "page 2 is eaten");
v.Tick(1200, "Tom");
StorageFeedRecord? r = v.Record;
Check.True(r != null && v.TakeChanged() && !v.TakeChanged(), "filed once");
Check.Eq(r?.Items.Count ?? -1, 2, "both pages' items");
Check.Eq(r?.Id ?? 0, VaultFeed.VaultId("tom"), "id follows the account, case-blind");
Check.True(StorageFeed.IsStandInId(r?.Id ?? 0), "id is a stand-in, far from real objects");
Check.Eq(r?.Label ?? "", "Account vault", "label");
Check.Eq(r?.Name ?? "", "Aelrynth vault", "name");
StorageFeedItem a = r!.Items[0];
Check.Eq(a.Name, "Acid Assagai", "name"); Check.Eq(a.Icon, 100667000u, "icon"); Check.Eq(a.Underlay, 100667001u, "underlay");
Check.Eq(a.Overlay, 100667002u, "overlay"); Check.Eq(a.Stack, 3, "stack"); Check.Eq(a.MaxStack, 100, "max stack");
Check.Eq(a.ItemType, 1u, "item type");
Check.Eq(r.Items[1].Stack, 1, "no stack field is a stack of 1");
Check.Eq(v.Status, VaultFeed.State.Idle, "idle again");
Check.Eq(VaultFeed.VaultId("Tom"), 0xFF000000u | (FnvOf("tom") & 0x00FFFFFFu), "the id RynthInventory used before the move (no second vault)");
}
private static uint FnvOf(string s)
{
uint h = 2166136261u;
foreach (char c in s) { h ^= c; h *= 16777619u; }
return h;
}
private static void Imitations()
{
{
(VaultFeed v, _) = NewVault();
v.Ask(0);
Check.False(v.ShouldEat("~ael1 {\"t\":\"inspect\",\"ok\":true}"), "the Companion's line stays visible");
Check.False(v.ShouldEat("Welcome to Aelrynth"), "ordinary chat stays visible");
Check.False(v.ShouldEat(null), "null is fine");
}
{
(VaultFeed v, _) = NewVault();
v.Ask(0);
Check.False(v.ShouldEat("Bob says, \"" + VaultPage(1, 1, 1, A) + "\"", 2), "spoken data line is not ours");
Check.False(v.ShouldEat("Bob " + VaultPage(1, 1, 1, A), 12), "an emoted data line is not ours");
Check.False(v.ShouldEat("Bob " + VaultPage(1, 1, 1, A)), "a data line not at the start is not ours, type unknown");
Check.False(v.ShouldEat(VaultPage(1, 1, 1, A), 3), "a data line in a tell is not ours");
Check.False(v.ShouldEat("Bob tells you, \"Unknown command: mule-data\"", 3), "a told unknown-command line is not ours");
Check.False(v.ShouldEat("Unknown command: mule-data", 2), "unknown-command in speech is not ours");
Check.False(v.ShouldEat("Unknown command: mule-data-ish"), "another command's refusal is not ours");
Check.True(v.ShouldEat("Unknown command: mule-data", 15), "ACE's real reply (Help) is ours");
}
{
(VaultFeed v, _) = NewVault();
v.Ask(0);
Check.True(v.ShouldEat(" " + VaultPage(1, 1, 1, A), 0), "the server's line (Broadcast), leading space allowed");
}
{
(VaultFeed v, _) = NewVault();
Check.True(v.ShouldEat(VaultPage(1, 1, 1, A)), "a line typed by hand while we are not asking is eaten");
v.Tick(0, "tom");
Check.Null(v.Record, "but ignored when we did not ask");
}
}
private static void Unsupported()
{
{
(VaultFeed v, List<string> sent) = NewVault();
v.Ask(0);
Check.True(v.ShouldEat("Unknown command: /mule-data"), "the unknown-command reply is eaten while we wait");
v.Tick(100, "tom");
Check.Eq(v.Status, VaultFeed.State.Unsupported, "unsupported");
Check.False(v.Ask(200), "not asked again");
Check.Eq(sent.Count, 1, "one probe, no more");
Check.True(v.Ask(300, force: true), "/rserver vault asks anyway");
}
{
(VaultFeed v, _) = NewVault();
Check.False(v.ShouldEat("Unknown command: /mule-data"), "an unknown-command line we did not provoke is left alone");
}
}
private static void Retries()
{
// A vault the server is still loading is asked again, and never recorded as empty.
{
(VaultFeed v, List<string> sent) = NewVault();
v.Ask(0);
v.ShouldEat(VaultPage(1, 1, 0, "", ready: false, why: "loading"));
v.Tick(10, "tom");
Check.Eq(v.Status, VaultFeed.State.Waiting, "waiting");
v.Tick(2000, "tom");
Check.Eq(sent.Count, 1, "not before the retry delay");
v.Tick(3500, "tom");
Check.Eq(sent.Count, 2, "asked again after it");
Check.Null(v.Record, "never recorded");
for (int i = 0; i < 10; i++)
{
v.ShouldEat(VaultPage(1, 1, 0, "", ready: false, why: "loading"));
v.Tick(4000 + i * 4000, "tom");
}
Check.True(v.Status != VaultFeed.State.Asking || sent.Count < 12, "it gives up after a few tries");
Check.Null(v.Record, "still never recorded");
}
// A vault that changed between pages is read again, not filed half and half.
{
(VaultFeed v, _) = NewVault();
v.Ask(0);
v.ShouldEat(VaultPage(1, 2, 3, A));
v.Tick(10, "tom");
v.ShouldEat(VaultPage(2, 2, 3, B)); // 2 read, the server says 3
v.Tick(20, "tom");
Check.Null(v.Record, "a mismatched read is not filed");
Check.Eq(v.Status, VaultFeed.State.Waiting, "and is retried");
}
// Silence is an idle feed, not a stuck one.
{
(VaultFeed v, _) = NewVault();
v.Ask(0);
v.Tick(20_000, "tom");
Check.Eq(v.Status, VaultFeed.State.Idle, "no answer in time");
Check.True(v.Ask(21_000), "can ask again");
}
// Garbage inside a mule line does not throw.
{
(VaultFeed v, _) = NewVault();
v.Ask(0);
v.ShouldEat("~ael1 {\"t\":\"mule\",\"ready\":tru");
v.Tick(5, "tom");
Check.True(v.Record == null && v.Status == VaultFeed.State.Idle, "bad JSON drops the read");
}
}
private static void Schedule()
{
var sent = new List<string>();
var f = new AelrynthFeature { SendCommand = t => { sent.Add(t); return true; } };
f.Reset();
long login = 50_000;
Check.Null(f.VaultTick(login, "tom"), "nothing at login");
Check.Eq(sent.Count, 0, "not asked at once");
f.VaultTick(login + VaultFeed.FirstAskMs - 1, "tom");
Check.Eq(sent.Count, 0, "not before the first delay");
f.VaultTick(login + VaultFeed.FirstAskMs, "tom");
Check.Eq(sent.Count == 1 ? sent[0] : "?", "/mule-data", "asked after the first delay");
Check.True(f.OnChatLine(VaultPage(1, 1, 1, A), 0, login + VaultFeed.FirstAskMs + 10), "its reply is always hidden");
StorageFeedRecord? read = f.VaultTick(login + VaultFeed.FirstAskMs + 20, "tom");
Check.True(read != null && read.Items.Count == 1, "the finished read is handed back once");
Check.Null(f.VaultTick(login + VaultFeed.FirstAskMs + 30, "tom"), "and only once");
f.VaultTick(login + VaultFeed.FirstAskMs + VaultFeed.RefreshMs, "tom");
Check.Eq(sent.Count, 2, "read again ten minutes later");
f.OnChatLine(VaultPage(1, 1, 1, A), 0, login + VaultFeed.FirstAskMs + VaultFeed.RefreshMs + 1);
f.VaultTick(login + VaultFeed.FirstAskMs + VaultFeed.RefreshMs + 2, "tom");
Check.True(f.VaultAskNow(login + 700_000) && sent.Count == 3, "/rserver vault reads it now");
// A server without the command: one probe per login, then quiet.
var g = new AelrynthFeature { SendCommand = t => { sent.Add(t); return true; } };
g.Reset();
int before = sent.Count;
g.VaultTick(0, "tom");
g.VaultTick(VaultFeed.FirstAskMs, "tom");
g.OnChatLine("Unknown command: mule-data", 0, VaultFeed.FirstAskMs + 1);
g.VaultTick(VaultFeed.FirstAskMs + 2, "tom");
g.VaultTick(VaultFeed.FirstAskMs + 3 * VaultFeed.RefreshMs, "tom");
Check.Eq(sent.Count - before, 1, "no vault on the server: asked once, then never on a timer");
g.Reset();
Check.Eq(g.Vault.Status, VaultFeed.State.Idle, "the next login asks again");
}
private static void HandOff()
{
var items = new List<StorageFeedItem>
{
new(2147483649u, 100, "Acid \"Assagai\" \\ é", 100667000, 100667001, 100667002, 3, 100, 1),
new(2147483650u, 101, "Pyreal", 100667003, 0, 0, 1, 0, 8192),
};
var rec = new StorageFeedRecord(VaultFeed.VaultId("tom"), VaultFeed.VaultName, VaultFeed.Label, items);
string json = StorageFeed.ToJson(rec);
bool ascii = true;
foreach (char c in json) if (c > 0x7e || c < 0x20) ascii = false;
Check.True(ascii, "plain ASCII (the broker carries ANSI)");
StorageFeedRecord? back = StorageFeed.Parse(json, out string error);
Check.Eq(error, "", "parsed");
Check.True(back != null && back.Id == rec.Id && back.Name == rec.Name && back.Label == rec.Label && back.Items.Count == 2, "the record");
Check.Eq(back!.Items[0], items[0], "an item, name escapes included");
Check.Eq(back.Items[1], items[1], "another");
Check.Eq(StorageFeed.TargetPlugin + "/" + StorageFeed.Action, "RynthInventory/storage", "sent to RynthInventory's \"storage\" command");
}
}