Attribute raiser (IltHub/IltAttributeRaiser, drawn by the engine's Skills panel > Progression): for servers where attributes and vitals go past the retail cap. Like UB's Leaftide XP Calculator it asks the server: "/xp all" for each stat's next-level cost, "/attr <abbr> 1" to raise, waiting for the "[ATTR] ... raised" reply and re-reading the costs before the next raise. Raise now / auto-raise (every N minutes) spend only on the ticked stats, never below the reserve, in the set order and mode (priority, round robin, cheapest first), up to 200 raises a run. +1 / +10 send "/attr <abbr> N" directly. Safety: a run decides only from the costs it just read, ignores a reply about another stat, stops if the world leaves Server Features or /xp goes off, never runs alongside the spend-before-/enl loop (either way round), and ends itself after 45 s with no reply. Chat: /ra hub attr run|stop|costs|status|auto on|off|every|raise. Saved per character in ilt-hub.json. Server Features (Settings > Misc, both the engine panel and the legacy ImGui window): a list of world-name patterns (* wildcard, case-insensitive; default "InfiniteLeaftide, *Leaftide*") plus a manual override now decide whether the ILT Hub, Mini Remote, Progression planners and the raiser run, replacing the hard-coded name check in IltServerOptions.IsIltLikeWorld. The per-character "Treat this world as ILT" override still counts. Features still follow the server's own report. Saved in the RynthAi profile and carried by the settings bridge (FeatureServerNames, ForceServerFeatures, ServerFeaturesStatus). Tests: RynthAiHostTests AttributeRaiserTests (patterns, list/override, pick modes, limits, order repair, server line parsing, a full run on the fake host, gating, and the safety cases). Host suite: 369 tests, only the 2 failures the untouched base also has when run off Windows (Windows paths). Pairs with the engine half in rynth/RynthCore PR #2 (Progression tab section, Settings text row). Co-authored-by: Cursor <cursoragent@cursor.com>
129 lines
5.7 KiB
C#
129 lines
5.7 KiB
C#
// ServerFeatureGate.cs — Which worlds get the ILT / infinite-attribute features.
|
|
//
|
|
// One gate for everything ILT-shaped: the ILT Hub and Mini Remote, the Skills panel's
|
|
// Progression planners and the attribute raiser. A world is "on" when:
|
|
// * its name matches one of the server patterns in Settings > Misc (FeatureServerNames,
|
|
// '*' wildcard, case-insensitive; defaults cover InfiniteLeaftide), or
|
|
// * the manual override is ticked (Settings > Misc ForceServerFeatures, or the older
|
|
// per-character ILT Hub "Treat this world as ILT" / "/ra hub force on").
|
|
// The gate only decides whether RynthAi ASKS the server; each feature still follows the
|
|
// server's own report (IltServerOptions bits), so a shard with /xp off keeps the raiser off.
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using RynthCore.Plugin.RynthAi.LegacyUi;
|
|
|
|
namespace RynthCore.Plugin.RynthAi.IltHub;
|
|
|
|
internal static class ServerFeatureGate
|
|
{
|
|
/// <summary>Patterns a fresh profile starts with (the names the old hard-coded check accepted).</summary>
|
|
public static readonly string[] DefaultServerNames = { "InfiniteLeaftide", "*Leaftide*" };
|
|
|
|
/// <summary>World name of the current session; set by RynthAiPlugin (empty before login).</summary>
|
|
public static Func<string>? WorldNameProvider;
|
|
|
|
/// <summary>The per-character ILT Hub override (ilt-hub.json); set by the Hub while it exists.</summary>
|
|
public static Func<bool>? HubForceProvider;
|
|
|
|
public static string CurrentWorld
|
|
{
|
|
get
|
|
{
|
|
try { return (WorldNameProvider?.Invoke() ?? string.Empty).Trim(); }
|
|
catch { return string.Empty; }
|
|
}
|
|
}
|
|
|
|
/// <summary>The patterns in force: the profile's list, or the defaults when there is no profile yet.</summary>
|
|
public static IReadOnlyList<string> Patterns(LegacyUiSettings? settings)
|
|
=> settings?.FeatureServerNames ?? (IReadOnlyList<string>)DefaultServerNames;
|
|
|
|
/// <summary>True when <paramref name="world"/> matches one of <paramref name="patterns"/>.</summary>
|
|
public static bool NameMatches(string world, IEnumerable<string>? patterns, out string matched)
|
|
{
|
|
matched = string.Empty;
|
|
if (string.IsNullOrWhiteSpace(world) || patterns == null) return false;
|
|
foreach (string p in patterns)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(p)) continue;
|
|
if (!Matches(world.Trim(), p.Trim())) continue;
|
|
matched = p.Trim();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// <summary>Case-insensitive match where '*' stands for any run of characters (anywhere in the pattern).</summary>
|
|
public static bool Matches(string text, string pattern)
|
|
{
|
|
if (pattern.Length == 0) return false;
|
|
if (!pattern.Contains('*')) return text.Equals(pattern, StringComparison.OrdinalIgnoreCase);
|
|
|
|
string[] parts = pattern.Split('*');
|
|
int pos = 0;
|
|
for (int i = 0; i < parts.Length; i++)
|
|
{
|
|
string part = parts[i];
|
|
if (part.Length == 0) continue;
|
|
if (i == 0)
|
|
{
|
|
if (!text.StartsWith(part, StringComparison.OrdinalIgnoreCase)) return false;
|
|
pos = part.Length;
|
|
continue;
|
|
}
|
|
if (i == parts.Length - 1)
|
|
return text.Length - pos >= part.Length && text.EndsWith(part, StringComparison.OrdinalIgnoreCase);
|
|
int at = text.IndexOf(part, pos, StringComparison.OrdinalIgnoreCase);
|
|
if (at < 0) return false;
|
|
pos = at + part.Length;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Is the override on (Settings > Misc, or the per-character Hub checkbox)?</summary>
|
|
public static bool ForceOn(LegacyUiSettings? settings)
|
|
{
|
|
if (settings?.ForceServerFeatures == true) return true;
|
|
try { return HubForceProvider?.Invoke() == true; }
|
|
catch { return false; }
|
|
}
|
|
|
|
/// <summary>The gate itself.</summary>
|
|
public static bool IsEnabled(string world, LegacyUiSettings? settings)
|
|
=> ForceOn(settings) || NameMatches(world, Patterns(settings), out _);
|
|
|
|
/// <summary>"InfiniteLeaftide, *Leaftide*" → trimmed, de-duplicated list (case-insensitive).</summary>
|
|
public static List<string> ParseList(string? text)
|
|
{
|
|
var list = new List<string>();
|
|
if (string.IsNullOrWhiteSpace(text)) return list;
|
|
foreach (string raw in text.Split(new[] { ',', ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
string p = raw.Trim();
|
|
if (p.Length > 0 && !list.Contains(p, StringComparer.OrdinalIgnoreCase)) list.Add(p);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static string FormatList(IEnumerable<string>? patterns)
|
|
=> patterns == null ? string.Empty : string.Join(", ", patterns.Where(p => !string.IsNullOrWhiteSpace(p)));
|
|
|
|
/// <summary>One status line for Settings > Misc: the world, whether the features are on, and why.</summary>
|
|
public static string Describe(LegacyUiSettings? settings)
|
|
{
|
|
string world = CurrentWorld;
|
|
string shown = world.Length > 0 ? $"'{world}'" : "(not logged in)";
|
|
if (settings?.ForceServerFeatures == true)
|
|
return $"This world {shown}: ON - manual override.";
|
|
if (NameMatches(world, Patterns(settings), out string matched))
|
|
return $"This world {shown}: ON - matches '{matched}'.";
|
|
bool hubForce;
|
|
try { hubForce = HubForceProvider?.Invoke() == true; } catch { hubForce = false; }
|
|
if (hubForce)
|
|
return $"This world {shown}: ON - the ILT Hub's \"Treat this world as ILT\" override.";
|
|
return world.Length > 0
|
|
? $"This world {shown}: OFF - not in the list. Add it, or tick the override."
|
|
: "This world: not logged in yet.";
|
|
}
|
|
}
|