RynthServers/Plugins/Shared/ServerPack/ServerPackInfo.cs
Daniel Wallace ac555572c7 DreamWeave: declare the Dereth Network chat tab
ServerPackInfo gains ChatTabs (ServerChatTab / ServerChatRule records);
BuildSectionsJson writes "chatTabs" after "windows" only when non-empty.
DreamWeave declares the pinned Network tab: tells from name@world
speakers (in and out) plus the discovered Global room. Needs the RynthCore
chatTabs manifest parser (branch chat/server-tabs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:28:04 -08:00

128 lines
8.1 KiB
C#

// ServerPackInfo.cs - What a server plugin knows about its game server (shared by every server plugin).
//
// Identity (id, name, hosts, world names) comes from the plugin's csproj through RynthPluginInfo, the
// same values the engine reads from the embedded manifest, so detection has one source. The rest is
// what is publicly known about the server (ServerData.cs in each project): connection, rule set,
// summary, links, account limits and the botting policy. Unknown stays empty; nothing is guessed.
// Pure: RynthServerPack.Tests compiles it.
using System;
namespace RynthCore.Plugin.ServerPack;
/// <summary>What the server's rules say about bots (RynthAi automation).</summary>
internal enum BottingPolicy
{
/// <summary>Not published here: check the server's own rules.</summary>
Unknown,
Allowed,
/// <summary>Allowed with limits (attended only, a client cap, ...): see <see cref="ServerPackInfo.BottingNote"/>.</summary>
Restricted,
/// <summary>The server forbids bots.</summary>
Forbidden,
}
/// <summary>A chat command the server adds, and what it does.</summary>
internal sealed record ServerCommand(string Command, string What);
/// <summary>
/// A salvage the server's own recipes apply (beyond retail tinkering), shown on the Mini Remote's
/// Crafting tab under "Server tinkering".
/// </summary>
/// <param name="Bench">The Crafting tab: "armor", "melee", "missile", "caster", "jewelry", "items" or "trinkets".</param>
/// <param name="Material">The bag's MaterialType (131), e.g. 64 = Steel.</param>
/// <param name="Effect">What it does, one short line.</param>
/// <param name="Kind">"tink" (repeatable), "imbue" (one per item) or "once" (one application).</param>
/// <param name="UsesTinkSlot">Counts toward the item's 10 tinks.</param>
/// <param name="NameMatch">The bag's name must contain this (bags that share a material id); "" = any.</param>
/// <param name="AppliedInt">An int property of the item that reads 2 once this salvage is on it (0 = none).</param>
/// <param name="Prepared">The bag must first be prepared on the chosen tier's Ammunition (its name then carries the tier).</param>
/// <param name="Order">Apply order on the tab (lower first); 0 = by kind (imbues, then tinks, then one-application rows).</param>
/// <param name="AfterCap">Applied last, and only once the item's tink slots are full.</param>
/// <param name="StackGroup">Rows with the same group share one cap per item (<paramref name="StackCap"/>); "" = none.</param>
/// <param name="StackCap">The group's combined cap per item (with <paramref name="StackGroup"/>).</param>
internal sealed record ServerSalvage(string Bench, int Material, string Effect, string Kind = "tink",
bool UsesTinkSlot = true, string NameMatch = "", int AppliedInt = 0,
bool Prepared = false, int Order = 0, bool AfterCap = false,
string StackGroup = "", int StackCap = 0);
/// <summary>
/// One rule of a default chat tab the server declares (RynthChat reads it from the sections manifest's
/// "chatTabs"). <paramref name="Pattern"/> is regex text when <paramref name="Mode"/> is empty.
/// </summary>
/// <param name="Action">"copy" (the line also stays in Chat) or "move".</param>
/// <param name="When">The engine's When condition ("type:3" = a tell to you, "type:4" = a tell you sent); "" = any line.</param>
/// <param name="Mode">"" = regex; "startswith" and the engine's other literal modes.</param>
/// <param name="Pattern">The text or regex; "" for a Global room rule (the engine fills it in).</param>
/// <param name="GlobalRoom">The engine discovers which Global room is live and writes its prefix as the pattern.</param>
internal sealed record ServerChatRule(string Action, string When, string Mode, string Pattern, bool GlobalRoom = false);
/// <summary>A default chat tab the server declares: a named tab with its rules, optionally pinned.</summary>
/// <param name="Id">Stable id within this server (lowercase letters, digits, dashes); owns the tab's rules.</param>
/// <param name="GlobalRoomFallback">The Global room used until one is discovered: "General", "Trade", "LFG" or "Roleplay".</param>
internal sealed record ServerChatTab(string Id, string Name, bool Pinned, string GlobalRoomFallback, ServerChatRule[] Rules);
internal sealed class ServerPackInfo
{
public ServerPackInfo(string id, string name, string[] hosts, string[] worldNames)
{
Id = (id ?? string.Empty).Trim().ToLowerInvariant();
Name = string.IsNullOrWhiteSpace(name) ? Id : name.Trim();
Hosts = hosts ?? Array.Empty<string>();
WorldNames = worldNames ?? Array.Empty<string>();
}
/// <summary>The engine's id for the server ("coldeve"); a built-in one ("ilt", "aelrynth") keeps the engine's own detection.</summary>
public string Id { get; }
public string Name { get; }
/// <summary>Connect hosts (the first is the one players are given).</summary>
public string[] Hosts { get; }
/// <summary>World names the server announces at login.</summary>
public string[] WorldNames { get; }
public int Port { get; init; } = 9000;
/// <summary>"ACE" or "GDLE" (the launcher's emulator setting).</summary>
public string Emulator { get; init; } = "ACE";
/// <summary>"PvE" or "PvP".</summary>
public string Ruleset { get; init; } = "PvE";
/// <summary>"Stable", "Development", ... as the server list says.</summary>
public string Status { get; init; } = string.Empty;
/// <summary>The server's own one-paragraph description.</summary>
public string Summary { get; init; } = string.Empty;
/// <summary>Notable rules and features, one line each.</summary>
public string[] Facts { get; init; } = Array.Empty<string>();
/// <summary>Chat commands the server adds (only ones known to exist).</summary>
public ServerCommand[] Commands { get; init; } = Array.Empty<ServerCommand>();
/// <summary>The server's own tinkering salvage (only recipes known to exist); empty = none defined.</summary>
public ServerSalvage[] Salvage { get; init; } = Array.Empty<ServerSalvage>();
/// <summary>Default chat tabs for RynthChat (sections manifest "chatTabs"); empty = none, and no key is written.</summary>
public ServerChatTab[] ChatTabs { get; init; } = Array.Empty<ServerChatTab>();
/// <summary>
/// Jewelry that is a trinket on this server (the Crafting tab's Trinkets bench, not Jewelry): name
/// words, case-insensitive, and words that rule a name out again ("top" but not "topaz"). Empty:
/// the server has no trinkets (retail: every jewelry piece is Jewelry).
/// </summary>
public string[] TrinketNames { get; init; } = Array.Empty<string>();
public string[] TrinketExcept { get; init; } = Array.Empty<string>();
/// <summary>"3 accounts", "3 active characters", ...; empty when not published.</summary>
public string AccountLimit { get; init; } = string.Empty;
public BottingPolicy Botting { get; init; } = BottingPolicy.Unknown;
/// <summary>The rule in the server's words, when there is one.</summary>
public string BottingNote { get; init; } = string.Empty;
public string Discord { get; init; } = string.Empty;
public string Website { get; init; } = string.Empty;
public string Wiki { get; init; } = string.Empty;
/// <summary>Where the facts come from, and when they were checked.</summary>
public string Source { get; init; } = string.Empty;
/// <summary>"play.coldeve.ac:9000" (the first host), or "" with none.</summary>
public string Address => Hosts.Length == 0 ? string.Empty : Hosts[0] + ":" + Port;
/// <summary>The botting line for the card.</summary>
public string BottingText => Botting switch
{
BottingPolicy.Allowed => "Allowed" + (BottingNote.Length > 0 ? " - " + BottingNote : string.Empty),
BottingPolicy.Restricted => "Restricted" + (BottingNote.Length > 0 ? " - " + BottingNote : string.Empty),
BottingPolicy.Forbidden => "Forbidden" + (BottingNote.Length > 0 ? " - " + BottingNote : string.Empty),
_ => "Not published here - check the server's rules" + (Discord.Length > 0 ? " (Discord)" : string.Empty),
};
}