Snapshot for release 2026.10.20.1 (internal 7116fab)
This commit is contained in:
parent
2a20c7acd6
commit
bfcd48950d
215 changed files with 16200 additions and 2838 deletions
23
Plugins/Shared/ServerPack/ServerChatRequest.cs
Normal file
23
Plugins/Shared/ServerPack/ServerChatRequest.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// ServerChatRequest.cs - "the server plugin just sent this command": a short time window in which the
|
||||
// command's reply counts as the plugin's own, so the server's code (ServerPackPlugin.ServerChatText)
|
||||
// can hide replies to its own requests and still show the same command typed by hand. A time window,
|
||||
// as RynthOracle has always done it (ported from Oracle of Dereth by Advis Eveldan, MIT): these replies
|
||||
// carry nothing tying them to the request. Each reply line extends it, so a long reply stays ours to its end.
|
||||
// Pure: RynthServerPack.Tests covers it.
|
||||
namespace RynthCore.Plugin.ServerPack;
|
||||
|
||||
internal sealed class ServerChatRequest
|
||||
{
|
||||
public const long WindowMs = 5000;
|
||||
private long _untilMs;
|
||||
|
||||
public void Sent(long nowMs) => _untilMs = nowMs + WindowMs;
|
||||
public void Clear() => _untilMs = 0;
|
||||
public bool Awaiting(long nowMs) => nowMs < _untilMs;
|
||||
|
||||
/// <summary>A reply line arrived: keep the window open a little longer.</summary>
|
||||
public void Extend(long nowMs)
|
||||
{
|
||||
if (Awaiting(nowMs)) _untilMs = nowMs + 2000 > _untilMs ? nowMs + 2000 : _untilMs;
|
||||
}
|
||||
}
|
||||
|
|
@ -67,6 +67,10 @@ public static unsafe class ServerPackExports
|
|||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatBarEnter", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnChatBarEnter(IntPtr textUtf16, IntPtr eatFlag) => Runtime.OnChatBarEnter(textUtf16, eatFlag);
|
||||
|
||||
// Incoming chat, for the server's own code (ServerPackPlugin.ServerChatText). Pump thread.
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatWindowText", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void OnChatWindowText(IntPtr textUtf16, int chatType, IntPtr eatFlag) => Runtime.OnChatWindowText(textUtf16, chatType, eatFlag);
|
||||
|
||||
/// <summary>The standalone server card ("/rserver"). Render thread.</summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginRender", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static void Render()
|
||||
|
|
@ -95,8 +99,8 @@ public static unsafe class ServerPackExports
|
|||
|
||||
/// <summary>
|
||||
/// RynthCore's Mini Remote sections: "section:server-<id>" (":popout" added in a popped-out
|
||||
/// window) draws the server card into the engine's current window. 1 = drawn, 0 = not ready or
|
||||
/// not ours.
|
||||
/// window) draws the server card into the engine's current window, "section:server-<id>.<page>"
|
||||
/// one of the server's own pages (ServerPackPages). 1 = drawn, 0 = not ready or not ours.
|
||||
/// </summary>
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginRenderEmbed", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static int RenderEmbed(byte* surface, float width, float height, float* wantWidth, float* wantHeight)
|
||||
|
|
@ -106,9 +110,18 @@ public static unsafe class ServerPackExports
|
|||
if (surface == null) return 0;
|
||||
string name = Marshal.PtrToStringUTF8((IntPtr)surface) ?? string.Empty;
|
||||
if (name.EndsWith(":popout", StringComparison.Ordinal)) name = name[..^":popout".Length];
|
||||
if (!name.Equals(ServerPackPlugin.SettingsSurface, StringComparison.Ordinal)) return 0;
|
||||
var plugin = Runtime.Plugin;
|
||||
if (plugin == null || !plugin.RenderEmbeddedCard(out float wantH)) return 0;
|
||||
if (plugin == null) return 0;
|
||||
float wantH;
|
||||
if (name.Equals(ServerPackPlugin.SettingsSurface, StringComparison.Ordinal))
|
||||
{
|
||||
if (!plugin.RenderEmbeddedCard(out wantH)) return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
string? page = ServerPackPages.PageIdOf(name, RynthPluginInfo.ServerId);
|
||||
if (page == null || !plugin.RenderEmbeddedPage(page, out wantH)) return 0;
|
||||
}
|
||||
if (wantWidth != null) *wantWidth = width;
|
||||
if (wantHeight != null) *wantHeight = wantH;
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,13 @@ internal sealed class ServerPackInfo
|
|||
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>
|
||||
/// 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;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
// unloaded); after Release() it reports Version 0 and GetProfileJson answers 0. Before the plugin is
|
||||
// up, or between characters, the profile still describes the server (active false, no world).
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
|
@ -20,7 +21,7 @@ internal static unsafe class ServerPackInterface
|
|||
private static volatile bool _released;
|
||||
|
||||
/// <summary>The last JSON handed out, and what it was built for (rebuilt only when that changes).</summary>
|
||||
private sealed record Snapshot(bool Active, string World, string Json);
|
||||
private sealed record Snapshot(bool Active, string World, int ValuesRevision, string Json);
|
||||
private static Snapshot? _last;
|
||||
|
||||
/// <summary>The table for (<paramref name="iface"/>, <paramref name="version"/>), or 0 when it isn't ours.</summary>
|
||||
|
|
@ -52,10 +53,14 @@ internal static unsafe class ServerPackInterface
|
|||
ServerPackInfo info = plugin?.Info ?? ServerPackPlugin.StaticInfo;
|
||||
bool active = plugin?.Active ?? false;
|
||||
string world = plugin?.World ?? string.Empty;
|
||||
int valuesRevision = plugin?.ProfileValues.Revision ?? -1;
|
||||
Snapshot? last = Volatile.Read(ref _last);
|
||||
if (last != null && last.Active == active && last.World == world) return last.Json;
|
||||
string json = ServerPackProfile.BuildJson(info, RynthPluginInfo.Name, RynthPluginInfo.Version, active, world);
|
||||
Volatile.Write(ref _last, new Snapshot(active, world, json));
|
||||
if (last != null && last.Active == active && last.World == world && last.ValuesRevision == valuesRevision) return last.Json;
|
||||
KeyValuePair<string, double>[] values = plugin != null
|
||||
? plugin.ProfileValues.Snapshot(out valuesRevision)
|
||||
: Array.Empty<KeyValuePair<string, double>>();
|
||||
string json = ServerPackProfile.BuildJson(info, RynthPluginInfo.Name, RynthPluginInfo.Version, active, world, values);
|
||||
Volatile.Write(ref _last, new Snapshot(active, world, valuesRevision, json));
|
||||
return json;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// with a single reference write, so the render thread always reads a whole one.
|
||||
// Pure (no host calls): RynthServerPack.Tests covers it.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
|
|
@ -163,8 +164,10 @@ internal sealed class ServerPackModel
|
|||
/// card in the shared "Server" section, shown only while that server is active (detected or
|
||||
/// forced in RynthCore Options > Diagnostics). The card left the Char section on 2026-10-13: that
|
||||
/// section is Session Stats now, session stats only.
|
||||
/// <paramref name="pages"/> (ServerPackPages, already validated) are the server's own views:
|
||||
/// primary views of the same section, so each gets a sub-tab there, also only on that server.
|
||||
/// </summary>
|
||||
public static string BuildSectionsJson(ServerPackInfo info, string pluginName)
|
||||
public static string BuildSectionsJson(ServerPackInfo info, string pluginName, IReadOnlyList<ServerPage>? pages = null)
|
||||
{
|
||||
var sb = new StringBuilder(512);
|
||||
sb.Append("{\"version\":1,\"servers\":[{\"id\":").Append(Q(info.Id)).Append(",\"name\":").Append(Q(info.Name));
|
||||
|
|
@ -180,7 +183,22 @@ internal sealed class ServerPackModel
|
|||
sb.Append(",\"primary\":false,\"height\":320,\"enabled\":true,\"tooltip\":");
|
||||
sb.Append(Q("What is known about " + info.Name + ": rules, account limits, botting policy, links and setup ("
|
||||
+ pluginName + "; also /rserver)."));
|
||||
sb.Append(",\"order\":130}]}");
|
||||
sb.Append(",\"order\":130}");
|
||||
if (pages != null)
|
||||
{
|
||||
for (int i = 0; i < pages.Count; i++)
|
||||
{
|
||||
ServerPage p = pages[i];
|
||||
sb.Append(",{\"section\":").Append(Q(SectionId));
|
||||
sb.Append(",\"server\":").Append(Q(info.Id));
|
||||
sb.Append(",\"label\":").Append(Q(p.Label));
|
||||
sb.Append(",\"surface\":").Append(Q(ServerPackPages.SurfaceFor(info.Id, p.Id)));
|
||||
sb.Append(",\"primary\":true,\"width\":").Append(ServerPackPages.Width).Append(",\"height\":").Append(ServerPackPages.Height);
|
||||
sb.Append(",\"enabled\":true,\"tooltip\":").Append(Q(p.Tooltip.Length > 0 ? p.Tooltip : p.Label + " (" + pluginName + ")"));
|
||||
sb.Append(",\"order\":").Append(100 + i).Append('}');
|
||||
}
|
||||
}
|
||||
sb.Append("]}");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
|
|
|||
86
Plugins/Shared/ServerPack/ServerPackPages.cs
Normal file
86
Plugins/Shared/ServerPack/ServerPackPages.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
// ServerPackPages.cs - Pages a server plugin adds beside its server card (RynthConquest's Conquest and
|
||||
// Leaderboards pages, RynthAelrynth's Leaderboards, ...).
|
||||
//
|
||||
// A server's own features need somewhere to show. The ServerPackPlugin.ServerPages hook lists them
|
||||
// once, at construction; the shared code then
|
||||
// * declares each one in the sections manifest as a primary view of the shared "Server" section,
|
||||
// shown only while this plugin's server is active (contribution "server": <id>), so RynthCore's
|
||||
// Mini Remote gives it a sub-tab next to the server card;
|
||||
// * draws it through RynthPluginRenderEmbed under the surface "section:server-<id>.<page>"
|
||||
// (":popout" added in a popped-out window), into the engine's current window and context;
|
||||
// * shows the same pages as tabs of the standalone "/rserver" window, after the card.
|
||||
// Draw runs on the render thread: a page reads its state under its own lock and queues anything it
|
||||
// sends for the plugin tick (ServerPackPlugin.RunOnTick).
|
||||
// Pure (no ImGui, no host calls): RynthServerPack.Tests covers it.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.Plugin.ServerPack;
|
||||
|
||||
/// <summary>
|
||||
/// One page a server plugin adds. <paramref name="Id"/> is 1-16 of a-z, 0-9 and '-' (part of the
|
||||
/// surface name); <paramref name="Draw"/> draws the body into the current ImGui window (render thread).
|
||||
/// </summary>
|
||||
internal sealed record ServerPage(string Id, string Label, string Tooltip, Action Draw);
|
||||
|
||||
internal static class ServerPackPages
|
||||
{
|
||||
/// <summary>At most this many pages per plugin (the Mini Remote shows them as one row of tabs).</summary>
|
||||
public const int MaxPages = 6;
|
||||
/// <summary>The longest page id (keeps "section:server-<32-char id>.<page>" under the engine's 64).</summary>
|
||||
public const int MaxIdLength = 16;
|
||||
/// <summary>The engine caps contribution labels at 48 characters.</summary>
|
||||
public const int MaxLabelLength = 48;
|
||||
/// <summary>Page views open at this size in the Mini Remote (it fits the window to the view).</summary>
|
||||
public const int Width = 540, Height = 520;
|
||||
|
||||
/// <summary>True for a page id: 1-16 of a-z, 0-9 and '-'.</summary>
|
||||
public static bool IsValidId(string? id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || id.Length > MaxIdLength) return false;
|
||||
foreach (char c in id)
|
||||
if (!(c is >= 'a' and <= 'z' || c is >= '0' and <= '9' || c == '-')) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>"section:server-conquest.bank": the page's surface.</summary>
|
||||
public static string SurfaceFor(string serverId, string pageId) => ServerPackModel.SurfaceFor(serverId) + "." + pageId;
|
||||
|
||||
/// <summary>
|
||||
/// The page id a surface names for this server ("section:server-conquest.bank" -> "bank"), or
|
||||
/// null for the card, another server's surface or anything else. ":popout" is ignored.
|
||||
/// </summary>
|
||||
public static string? PageIdOf(string? surface, string serverId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(surface)) return null;
|
||||
string name = surface.EndsWith(":popout", StringComparison.Ordinal) ? surface[..^":popout".Length] : surface;
|
||||
string prefix = ServerPackModel.SurfaceFor(serverId) + ".";
|
||||
if (!name.StartsWith(prefix, StringComparison.Ordinal)) return null;
|
||||
string id = name[prefix.Length..];
|
||||
return IsValidId(id) ? id : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The pages kept from what a plugin listed: valid, unique ids, a label, at most
|
||||
/// <see cref="MaxPages"/>; each one dropped is reported to <paramref name="log"/>.
|
||||
/// </summary>
|
||||
public static List<ServerPage> Validate(IEnumerable<ServerPage>? pages, Action<string>? log = null)
|
||||
{
|
||||
var kept = new List<ServerPage>();
|
||||
if (pages == null) return kept;
|
||||
foreach (ServerPage p in pages)
|
||||
{
|
||||
if (p == null) continue;
|
||||
string why = !IsValidId(p.Id) ? "its id isn't 1-16 of a-z, 0-9 and '-'"
|
||||
: string.IsNullOrWhiteSpace(p.Label) ? "it has no label"
|
||||
: p.Draw == null ? "it has nothing to draw"
|
||||
: kept.Exists(k => k.Id == p.Id) ? "another page has its id"
|
||||
: kept.Count >= MaxPages ? $"a plugin has at most {MaxPages} pages"
|
||||
: string.Empty;
|
||||
if (why.Length > 0) { log?.Invoke($"Page '{p.Id}' left out: {why}."); continue; }
|
||||
string label = p.Label.Trim();
|
||||
kept.Add(p with { Label = label.Length <= MaxLabelLength ? label : label[..MaxLabelLength], Tooltip = p.Tooltip ?? string.Empty });
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,11 +14,33 @@
|
|||
// Server-specific features: add files to the server's project implementing the partial hooks below
|
||||
// (ServerLoginComplete, ServerTick, ServerChatCommand, ...). Unimplemented hooks compile away.
|
||||
//
|
||||
// Threads: OnTick, login/logout and the engine's export calls run on the plugin pump. OnChatBarEnter
|
||||
// runs on AC's main thread, so it only queues. The card draws on the render thread (OnRender,
|
||||
// RynthPluginRenderEmbed) and queues its commands for the tick.
|
||||
// What the shared code gives a server's own features (added 2026-10-20, when RynthOracle's and
|
||||
// RynthInventory's Conquest and Aelrynth features moved into RynthConquest and RynthAelrynth, so a
|
||||
// shared plugin carries nothing for one server):
|
||||
// ServerPages(list) pages of its own (ServerPackPages.cs): sub-tabs of the Mini Remote's
|
||||
// Server section, only while its server is active, and tabs of the
|
||||
// /rserver window. Draw runs on the render thread.
|
||||
// ServerChatText(...) every incoming chat line (pump thread), to read the server's replies
|
||||
// and hide the ones answering the plugin's own requests (eat).
|
||||
// ServerChatBar(text) every line sent through the chat bar (AC's thread: note it only),
|
||||
// to tell the player's typed command from the plugin's own.
|
||||
// Settings the plugin's own settings file (ServerPackSettings.cs), loaded before
|
||||
// ServerInitialize; MigrateOnce imports a setting from its old home.
|
||||
// SetProfileValue(key, n) a live number in its "RynthServer.Profile" ("values"), for other
|
||||
// plugins that apply a server rule without knowing the server.
|
||||
// ServerCommandVerbs(list) its own "/rserver <verb>" words, handled in ServerChatCommand.
|
||||
// RunOnTick(action) work for the next tick (a page's button, on the render thread).
|
||||
// Send(command) a chat command as if typed (pump thread, logged in only);
|
||||
// LogTagged(text) the engine log, "[RynthConquest] ..."; ChatLine(text) the chat window.
|
||||
// The tick, chat and command hooks only run while a character is logged in; each
|
||||
// should check Active itself, since the plugin can be loaded for a world that isn't its server.
|
||||
//
|
||||
// Threads: OnTick, login/logout, chat lines and the engine's export calls run on the plugin pump.
|
||||
// OnChatBarEnter runs on AC's main thread, so it only queues. The card and the pages draw on the
|
||||
// render thread (OnRender, RynthPluginRenderEmbed) and queue their commands for the tick.
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using ImGuiNET;
|
||||
using RynthCore.PluginCore;
|
||||
|
|
@ -40,10 +62,19 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
private readonly ServerPackModel _model;
|
||||
private readonly ServerPackUi _ui;
|
||||
private readonly string _sectionsJson;
|
||||
// The server's own pages (ServerPages), validated; what was left out is logged at Initialize.
|
||||
private readonly List<ServerPage> _pages;
|
||||
private readonly List<string> _pageNotes = new();
|
||||
private readonly ServerPackSettings _settings = new(ServerPackSettings.DefaultPath(RynthPluginInfo.Name));
|
||||
private readonly ServerProfileValues _profileValues = new();
|
||||
// RynthCore commands from the card (render thread), run on the next tick.
|
||||
private readonly ConcurrentQueue<string> _engineCommands = new();
|
||||
// "/rserver ..." lines from OnChatBarEnter, run on the next tick.
|
||||
private readonly ConcurrentQueue<string[]> _commands = new();
|
||||
// The server code's work for the tick (RunOnTick: its pages' buttons).
|
||||
private readonly ConcurrentQueue<Action> _tickActions = new();
|
||||
// The server's own "/rserver" verbs (ServerCommandVerbs).
|
||||
private readonly HashSet<string> _serverVerbs = new(StringComparer.OrdinalIgnoreCase);
|
||||
private volatile bool _loginComplete;
|
||||
private volatile string? _world;
|
||||
private bool _wasActive;
|
||||
|
|
@ -52,8 +83,14 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
{
|
||||
ServerPackInfo info = ServerData.Create();
|
||||
_model = new ServerPackModel(info);
|
||||
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world);
|
||||
_sectionsJson = ServerPackModel.BuildSectionsJson(info, RynthPluginInfo.Name);
|
||||
var pages = new List<ServerPage>();
|
||||
ServerPages(pages);
|
||||
_pages = ServerPackPages.Validate(pages, _pageNotes.Add);
|
||||
var verbs = new List<string>();
|
||||
ServerCommandVerbs(verbs);
|
||||
foreach (string v in verbs) if (!string.IsNullOrWhiteSpace(v)) _serverVerbs.Add(v.Trim());
|
||||
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages);
|
||||
_sectionsJson = ServerPackModel.BuildSectionsJson(info, RynthPluginInfo.Name, _pages);
|
||||
}
|
||||
|
||||
internal ServerPackInfo Info => _model.Info;
|
||||
|
|
@ -79,8 +116,52 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
partial void ServerTick(bool active);
|
||||
/// <summary>"/rserver <verb> ..." verbs the shared code doesn't know; set handled to stop the help text.</summary>
|
||||
partial void ServerChatCommand(string[] parts, ref bool handled);
|
||||
/// <summary>
|
||||
/// The server's own "/rserver" verbs (lower case), so "/rserver vault" reaches ServerChatCommand
|
||||
/// instead of being read as another server's id. Called once, from the constructor.
|
||||
/// </summary>
|
||||
partial void ServerCommandVerbs(List<string> verbs);
|
||||
/// <summary>Extra lines for "/rserver info".</summary>
|
||||
partial void ServerInfoLines(Action<string> line);
|
||||
/// <summary>The server's own pages (ServerPackPages.cs). Called once, from the constructor (no Host yet).</summary>
|
||||
partial void ServerPages(List<ServerPage> pages);
|
||||
/// <summary>
|
||||
/// An incoming chat line (pump thread, logged in only): set <paramref name="eat"/> to keep it out of
|
||||
/// the chat window (it comes in true when an earlier plugin already ate it).
|
||||
/// </summary>
|
||||
partial void ServerChatText(string text, int chatType, ref bool eat);
|
||||
/// <summary>
|
||||
/// A line sent through the chat bar, typed or another plugin's command (trimmed), before
|
||||
/// "/rserver" is looked at. AC's main thread: only note it (interlocked state or a queue).
|
||||
/// </summary>
|
||||
partial void ServerChatBar(string text);
|
||||
|
||||
// ── What the server's own code uses ──────────────────────────────────
|
||||
|
||||
/// <summary>The plugin's settings file (loaded before ServerInitialize). Pump thread.</summary>
|
||||
internal ServerPackSettings Settings => _settings;
|
||||
|
||||
/// <summary>The live numbers of the profile ("values"). Any thread.</summary>
|
||||
internal ServerProfileValues ProfileValues => _profileValues;
|
||||
|
||||
/// <summary>The pages this plugin draws.</summary>
|
||||
internal IReadOnlyList<ServerPage> Pages => _pages;
|
||||
|
||||
/// <summary>Publishes a live number in the "RynthServer.Profile" JSON ("values"). Any thread.</summary>
|
||||
internal void SetProfileValue(string key, double value) => _profileValues.Set(key, value);
|
||||
|
||||
/// <summary>Runs <paramref name="action"/> on the next tick while logged in (dropped at logout). Any thread.</summary>
|
||||
internal void RunOnTick(Action action)
|
||||
{
|
||||
if (action != null) _tickActions.Enqueue(action);
|
||||
}
|
||||
|
||||
/// <summary>Sends a chat command as if typed; false when nothing went out. Pump thread.</summary>
|
||||
internal bool Send(string command)
|
||||
=> _loginComplete && !string.IsNullOrWhiteSpace(command) && Host.HasInvokeChatParser && Host.InvokeChatParser(command);
|
||||
|
||||
/// <summary>The plugin's log, tagged with its name.</summary>
|
||||
internal void LogTagged(string message) => Host.Log($"[{RynthPluginInfo.Name}] {message}");
|
||||
|
||||
public override int Initialize()
|
||||
{
|
||||
|
|
@ -89,6 +170,9 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
// Mini Remote's included), never a second copy of ImGui (ImGuiNativeBinding.cs). Found and fixed
|
||||
// by SilentKelpie (rynth PR #12); re-implemented here.
|
||||
RynthCore.Plugin.Shared.ImGuiNativeBinding.Ensure(msg => Host.Log($"[{RynthPluginInfo.Name}] {msg}"));
|
||||
foreach (string note in _pageNotes) LogTagged(note);
|
||||
_settings.Load();
|
||||
if (_settings.LastError.Length > 0) LogTagged($"Settings ({_settings.FilePath}) not read: {_settings.LastError}; using defaults.");
|
||||
ServerInitialize();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -108,7 +192,9 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
_world = null;
|
||||
while (_commands.TryDequeue(out _)) { }
|
||||
while (_engineCommands.TryDequeue(out _)) { }
|
||||
while (_tickActions.TryDequeue(out _)) { }
|
||||
_model.Clear();
|
||||
_profileValues.Clear();
|
||||
ServerLogout();
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +210,11 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
if (!Host.HasInvokeChatParser || !Host.InvokeChatParser(command))
|
||||
ChatLine($"[{RynthPluginInfo.Name}] RynthCore didn't take: " + command);
|
||||
}
|
||||
while (_tickActions.TryDequeue(out Action? action))
|
||||
{
|
||||
try { action(); }
|
||||
catch (Exception ex) { LogTagged($"A queued action failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
|
||||
bool active = Active;
|
||||
if (active && !_wasActive && Info.Botting == BottingPolicy.Forbidden)
|
||||
|
|
@ -173,7 +264,20 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
/// into the engine's current window and context (popped-out windows have their own).
|
||||
/// <paramref name="wantHeight"/> is the height it used. False until login. Render thread.
|
||||
/// </summary>
|
||||
internal bool RenderEmbeddedCard(out float wantHeight)
|
||||
internal bool RenderEmbeddedCard(out float wantHeight) => RenderEmbedded(_ui.RenderBody, "Server card", out wantHeight);
|
||||
|
||||
/// <summary>
|
||||
/// RynthPluginRenderEmbed "section:server-<id>.<page>": one of the server's pages
|
||||
/// (ServerPages) in RynthCore's Mini Remote. False for a page this plugin doesn't have, or before login.
|
||||
/// </summary>
|
||||
internal bool RenderEmbeddedPage(string pageId, out float wantHeight)
|
||||
{
|
||||
wantHeight = 0;
|
||||
ServerPage? page = _pages.Find(p => p.Id == pageId);
|
||||
return page != null && RenderEmbedded(page.Draw, "Page " + page.Label, out wantHeight);
|
||||
}
|
||||
|
||||
private bool RenderEmbedded(Action draw, string what, out float wantHeight)
|
||||
{
|
||||
wantHeight = 0;
|
||||
if (!_loginComplete) return false;
|
||||
|
|
@ -184,24 +288,36 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
try
|
||||
{
|
||||
float startY = ImGui.GetCursorPosY();
|
||||
_ui.RenderBody();
|
||||
draw();
|
||||
wantHeight = MathF.Max(40f, ImGui.GetCursorPosY() - startY + 4f);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Host.Log($"[{RynthPluginInfo.Name}] Server card failed: {ex.Message}");
|
||||
Host.Log($"[{RynthPluginInfo.Name}] {what} failed: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
finally { ImGui.SetCurrentContext(previous); }
|
||||
}
|
||||
|
||||
// ── Chat ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Incoming chat (pump thread): the server's own code reads it (ServerChatText).</summary>
|
||||
public override void OnChatWindowText(string? text, int chatType, ref int eat)
|
||||
{
|
||||
if (!_loginComplete || string.IsNullOrEmpty(text)) return;
|
||||
bool eaten = eat != 0;
|
||||
ServerChatText(text, chatType, ref eaten);
|
||||
if (eaten) eat = 1;
|
||||
}
|
||||
|
||||
// ── Commands ─────────────────────────────────────────────────────────
|
||||
|
||||
public override void OnChatBarEnter(string? text, ref int eat)
|
||||
{
|
||||
if (!_loginComplete || string.IsNullOrEmpty(text)) return;
|
||||
string trimmed = text.Trim();
|
||||
ServerChatBar(trimmed);
|
||||
if (!trimmed.Equals(ChatCommand, StringComparison.OrdinalIgnoreCase)
|
||||
&& !trimmed.StartsWith(ChatCommand + " ", StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
|
|
@ -216,8 +332,9 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
|||
_commands.Enqueue(parts);
|
||||
}
|
||||
|
||||
private static bool IsVerb(string word) =>
|
||||
word.ToLowerInvariant() is "show" or "hide" or "toggle" or "info" or "help" or "on" or "off" or "auto";
|
||||
private bool IsVerb(string word) =>
|
||||
word.ToLowerInvariant() is "show" or "hide" or "toggle" or "info" or "help" or "on" or "off" or "auto"
|
||||
|| _serverVerbs.Contains(word);
|
||||
|
||||
/// <summary>Drops the server id: "/rserver coldeve info" -> "/rserver info".</summary>
|
||||
private static string[] Shift(string[] parts)
|
||||
|
|
|
|||
|
|
@ -9,10 +9,90 @@
|
|||
// The JSON is plain ASCII (anything else is \u-escaped), so a reader can show it in the AC client.
|
||||
// Pure (no host calls): RynthServerPack.Tests covers it.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace RynthCore.Plugin.ServerPack;
|
||||
|
||||
/// <summary>
|
||||
/// Live numbers a server plugin publishes in its profile ("values"), for other plugins that apply a
|
||||
/// server rule without knowing the server: e.g. RynthConquest's "voidDotDurationScale" (how much
|
||||
/// longer this character's Void damage-over-time lasts there), which RynthOracle's Void timers use.
|
||||
/// Set from the server's own code (ServerPackPlugin.SetProfileValue), read by the profile interface
|
||||
/// on any thread; <see cref="Revision"/> goes up on every change, so the JSON is rebuilt only then.
|
||||
/// </summary>
|
||||
internal sealed class ServerProfileValues
|
||||
{
|
||||
private readonly object _gate = new();
|
||||
private readonly List<KeyValuePair<string, double>> _values = new();
|
||||
private volatile int _revision;
|
||||
|
||||
/// <summary>Goes up whenever a value changes.</summary>
|
||||
public int Revision => _revision;
|
||||
|
||||
/// <summary>1-48 of letters, digits, '.', '_' and '-'.</summary>
|
||||
public static bool IsValidKey(string? key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key) || key.Length > 48) return false;
|
||||
foreach (char c in key)
|
||||
if (!(char.IsAsciiLetterOrDigit(c) || c is '.' or '_' or '-')) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Sets (or adds) a value; false for a bad key or a number that isn't finite. Any thread.</summary>
|
||||
public bool Set(string key, double value)
|
||||
{
|
||||
if (!IsValidKey(key) || !double.IsFinite(value)) return false;
|
||||
lock (_gate)
|
||||
{
|
||||
int i = _values.FindIndex(v => v.Key == key);
|
||||
if (i >= 0)
|
||||
{
|
||||
if (_values[i].Value.Equals(value)) return true;
|
||||
_values[i] = new KeyValuePair<string, double>(key, value);
|
||||
}
|
||||
else _values.Add(new KeyValuePair<string, double>(key, value));
|
||||
_revision++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Drops one value (true when it was there). Any thread.</summary>
|
||||
public bool Remove(string key)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
int i = _values.FindIndex(v => v.Key == key);
|
||||
if (i < 0) return false;
|
||||
_values.RemoveAt(i);
|
||||
_revision++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Drops every value (logout: the next character publishes its own). Any thread.</summary>
|
||||
public void Clear()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_values.Count == 0) return;
|
||||
_values.Clear();
|
||||
_revision++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A copy of the values and the revision it belongs to. Any thread.</summary>
|
||||
public KeyValuePair<string, double>[] Snapshot(out int revision)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
revision = _revision;
|
||||
return _values.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ServerPackProfile
|
||||
{
|
||||
/// <summary>The profile JSON's schema (RynthServerProfile.Schema).</summary>
|
||||
|
|
@ -29,9 +109,11 @@ internal static class ServerPackProfile
|
|||
|
||||
/// <summary>
|
||||
/// The profile for <paramref name="info"/>: <paramref name="active"/> is this plugin's verdict
|
||||
/// (RynthCore's when it pushed one), <paramref name="world"/> the world name the client reports.
|
||||
/// (RynthCore's when it pushed one), <paramref name="world"/> the world name the client reports,
|
||||
/// <paramref name="values"/> the live numbers the server's own code published (ServerProfileValues).
|
||||
/// </summary>
|
||||
public static string BuildJson(ServerPackInfo info, string pluginName, string pluginVersion, bool active, string? world)
|
||||
public static string BuildJson(ServerPackInfo info, string pluginName, string pluginVersion, bool active, string? world,
|
||||
IReadOnlyList<KeyValuePair<string, double>>? values = null)
|
||||
{
|
||||
var sb = new StringBuilder(1024);
|
||||
sb.Append("{\"schema\":").Append(Schema);
|
||||
|
|
@ -93,10 +175,35 @@ internal static class ServerPackProfile
|
|||
sb.Append('}');
|
||||
}
|
||||
sb.Append(']');
|
||||
// Added within schema 1 (2026-10-20), only when the server has trinkets.
|
||||
if (info.TrinketNames.Length > 0)
|
||||
{
|
||||
sb.Append(",\"trinkets\":{");
|
||||
sb.Append("\"names\":[");
|
||||
for (int i = 0; i < info.TrinketNames.Length; i++) { if (i > 0) sb.Append(','); Str(sb, info.TrinketNames[i]); }
|
||||
sb.Append("],\"except\":[");
|
||||
for (int i = 0; i < info.TrinketExcept.Length; i++) { if (i > 0) sb.Append(','); Str(sb, info.TrinketExcept[i]); }
|
||||
sb.Append("]}");
|
||||
}
|
||||
Field(sb, "discord", info.Discord);
|
||||
Field(sb, "website", info.Website);
|
||||
Field(sb, "wiki", info.Wiki);
|
||||
Field(sb, "source", info.Source);
|
||||
// Added within schema 1: live numbers for this character on this server ({} when none).
|
||||
sb.Append(",\"values\":{");
|
||||
if (values != null)
|
||||
{
|
||||
bool first = true;
|
||||
foreach (KeyValuePair<string, double> v in values)
|
||||
{
|
||||
if (!ServerProfileValues.IsValidKey(v.Key) || !double.IsFinite(v.Value)) continue;
|
||||
if (!first) sb.Append(',');
|
||||
first = false;
|
||||
Str(sb, v.Key);
|
||||
sb.Append(':').Append(v.Value.ToString("R", CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
sb.Append('}');
|
||||
sb.Append('}');
|
||||
return sb.ToString();
|
||||
}
|
||||
|
|
|
|||
88
Plugins/Shared/ServerPack/ServerPackRefresh.cs
Normal file
88
Plugins/Shared/ServerPack/ServerPackRefresh.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// ServerPackRefresh.cs - The Refresh button a server page starts with, and the status line beside it
|
||||
// (as RynthOracle's pages have it): the page's own command is asked for again, refused for a few
|
||||
// seconds after it went out (so the button can't spam the server), and the line waits for the reply
|
||||
// ("Waiting...", then "Updated hh:mm:ss", or "No reply yet" after a while).
|
||||
// Render thread: Draw runs inside the page's own lock; the page's refresh callback only decides and
|
||||
// queues what to send (ServerPackPlugin.RunOnTick).
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.ServerPack;
|
||||
|
||||
/// <summary>What a Refresh did, and (when it asked the server) how to tell the reply has landed.</summary>
|
||||
internal sealed record ServerRefreshResult(string What, Func<bool>? Done = null);
|
||||
|
||||
internal sealed class ServerRefreshRow
|
||||
{
|
||||
public const long CooldownMs = 3000;
|
||||
public const long ReplyWaitMs = 15_000;
|
||||
public const string TooSoon = "That was just asked for; wait a few seconds before asking again.";
|
||||
|
||||
private static readonly Vector4 Yellow = new(0.95f, 0.85f, 0.35f, 1f);
|
||||
private static readonly Vector4 Red = new(0.95f, 0.45f, 0.40f, 1f);
|
||||
|
||||
private readonly Dictionary<string, long> _sent = new();
|
||||
private string _scope = string.Empty, _what = string.Empty;
|
||||
private Func<bool>? _done;
|
||||
private bool _doneSeen;
|
||||
private long _atMs;
|
||||
private DateTime _atLocal, _doneLocal;
|
||||
|
||||
/// <summary>The same request (by <paramref name="key"/>) twice within <see cref="CooldownMs"/> is refused.</summary>
|
||||
public bool CoolingDown(string key, long nowMs)
|
||||
{
|
||||
if (_sent.TryGetValue(key, out long t) && nowMs - t < CooldownMs) return true;
|
||||
_sent[key] = nowMs;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Forgets the status line and the cooldowns (logout).</summary>
|
||||
public void Reset()
|
||||
{
|
||||
_sent.Clear();
|
||||
_scope = _what = string.Empty;
|
||||
_done = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The row: Refresh (tooltip <paramref name="help"/>) and, for the page that last refreshed
|
||||
/// (<paramref name="scope"/>), what happened.
|
||||
/// </summary>
|
||||
public void Draw(string scope, string help, Func<ServerRefreshResult> refresh)
|
||||
{
|
||||
long now = Environment.TickCount64;
|
||||
if (ImGui.SmallButton("Refresh##refresh_" + scope))
|
||||
{
|
||||
ServerRefreshResult r;
|
||||
try { r = refresh(); }
|
||||
catch (Exception ex) { r = new ServerRefreshResult("Couldn't refresh: " + ex.Message); }
|
||||
_scope = scope;
|
||||
_what = r.What;
|
||||
_done = r.Done;
|
||||
_doneSeen = false;
|
||||
_atMs = now;
|
||||
_atLocal = DateTime.Now;
|
||||
}
|
||||
if (help.Length > 0 && ImGui.IsItemHovered()) SafeImGui.SetTooltip(help);
|
||||
if (_scope != scope || _what.Length == 0) return;
|
||||
|
||||
ImGui.SameLine();
|
||||
if (_done != null && !_doneSeen && _done())
|
||||
{
|
||||
_doneSeen = true;
|
||||
_doneLocal = DateTime.Now;
|
||||
}
|
||||
if (_done != null && !_doneSeen)
|
||||
{
|
||||
if (now - _atMs > ReplyWaitMs) SafeImGui.TextColored(Red, "No reply yet. Press Refresh to ask again.");
|
||||
else SafeImGui.TextColored(Yellow, _what + " Waiting for the reply...");
|
||||
}
|
||||
else if (_done != null)
|
||||
SafeImGui.TextDisabled($"Updated {_doneLocal:HH:mm:ss}. {_what}");
|
||||
else
|
||||
SafeImGui.TextDisabled($"Refreshed {_atLocal:HH:mm:ss}. {_what}");
|
||||
}
|
||||
}
|
||||
158
Plugins/Shared/ServerPack/ServerPackSettings.cs
Normal file
158
Plugins/Shared/ServerPack/ServerPackSettings.cs
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
// ServerPackSettings.cs - A server plugin's own settings file, %APPDATA%\RynthCore\<plugin>.json
|
||||
// (rynthconquest.json, ...), for the server's features (ServerPackPlugin.Settings).
|
||||
//
|
||||
// Flat named values (true/false, text), written by hand and read with JsonDocument: plugin types
|
||||
// never go through System.Text.Json's serializer, which roots them across hot reloads. Values the
|
||||
// plugin doesn't ask for are kept as they were written, so an older or newer copy of the plugin
|
||||
// never drops another's. MigrateOnce imports settings that used to live elsewhere (another
|
||||
// plugin's file) exactly once, and remembers that it did.
|
||||
// Pure (file I/O only): RynthServerPack.Tests covers it. Pump thread only.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RynthCore.Plugin.ServerPack;
|
||||
|
||||
internal sealed class ServerPackSettings
|
||||
{
|
||||
// name -> the value's JSON text, in file order.
|
||||
private readonly List<KeyValuePair<string, string>> _values = new();
|
||||
|
||||
public ServerPackSettings(string path) => FilePath = path;
|
||||
|
||||
/// <summary>%APPDATA%\RynthCore\<plugin name, lower case>.json.</summary>
|
||||
public static string DefaultPath(string pluginName) => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore", pluginName.ToLowerInvariant() + ".json");
|
||||
|
||||
public string FilePath { get; }
|
||||
|
||||
/// <summary>Why the last Load or Save failed ("" when it didn't).</summary>
|
||||
public string LastError { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>Reads the file; a missing or broken one means defaults (the next save rewrites it).</summary>
|
||||
public void Load()
|
||||
{
|
||||
_values.Clear();
|
||||
LastError = string.Empty;
|
||||
try
|
||||
{
|
||||
if (!File.Exists(FilePath)) return;
|
||||
using JsonDocument doc = JsonDocument.Parse(File.ReadAllText(FilePath));
|
||||
if (doc.RootElement.ValueKind != JsonValueKind.Object) { LastError = "not a JSON object"; return; }
|
||||
foreach (JsonProperty p in doc.RootElement.EnumerateObject())
|
||||
Put(p.Name, p.Value.GetRawText());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_values.Clear();
|
||||
LastError = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Writes the file (through a temporary file, so a crash never leaves half of one). False on failure.</summary>
|
||||
public bool Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
var sb = new StringBuilder("{\n");
|
||||
for (int i = 0; i < _values.Count; i++)
|
||||
{
|
||||
sb.Append(" ").Append(Quote(_values[i].Key)).Append(": ").Append(_values[i].Value);
|
||||
sb.Append(i + 1 < _values.Count ? ",\n" : "\n");
|
||||
}
|
||||
sb.Append("}\n");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!);
|
||||
string tmp = FilePath + ".tmp";
|
||||
File.WriteAllText(tmp, sb.ToString());
|
||||
File.Move(tmp, FilePath, overwrite: true);
|
||||
LastError = string.Empty;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LastError = ex.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Has(string name) => Find(name) >= 0;
|
||||
|
||||
public bool GetBool(string name, bool fallback)
|
||||
{
|
||||
int i = Find(name);
|
||||
return i < 0 ? fallback : _values[i].Value switch { "true" => true, "false" => false, _ => fallback };
|
||||
}
|
||||
|
||||
/// <summary>Sets a value; true when it changed (the caller saves).</summary>
|
||||
public bool SetBool(string name, bool value) => Put(name, value ? "true" : "false");
|
||||
|
||||
public string GetString(string name, string fallback)
|
||||
{
|
||||
int i = Find(name);
|
||||
if (i < 0) return fallback;
|
||||
try
|
||||
{
|
||||
using JsonDocument doc = JsonDocument.Parse(_values[i].Value);
|
||||
return doc.RootElement.ValueKind == JsonValueKind.String ? doc.RootElement.GetString() ?? fallback : fallback;
|
||||
}
|
||||
catch (JsonException) { return fallback; }
|
||||
}
|
||||
|
||||
public bool SetString(string name, string value) => Put(name, Quote(value ?? string.Empty));
|
||||
|
||||
/// <summary>
|
||||
/// Runs <paramref name="migrate"/> once per settings file: unless <paramref name="marker"/> is
|
||||
/// already set, it runs, the marker is set and the file saved. True when it ran now.
|
||||
/// </summary>
|
||||
public bool MigrateOnce(string marker, Action<ServerPackSettings> migrate)
|
||||
{
|
||||
if (GetBool(marker, false)) return false;
|
||||
migrate(this);
|
||||
SetBool(marker, true);
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A true/false value from another JSON settings file (an old home of a moved setting), or null
|
||||
/// when the file, the value or its type isn't there. Never throws.
|
||||
/// </summary>
|
||||
public static bool? ReadBoolFrom(string path, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(path)) return null;
|
||||
using JsonDocument doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||
if (doc.RootElement.ValueKind != JsonValueKind.Object || !doc.RootElement.TryGetProperty(name, out JsonElement v)) return null;
|
||||
return v.ValueKind switch { JsonValueKind.True => true, JsonValueKind.False => false, _ => null };
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int Find(string name)
|
||||
{
|
||||
for (int i = 0; i < _values.Count; i++)
|
||||
if (string.Equals(_values[i].Key, name, StringComparison.Ordinal)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private bool Put(string name, string json)
|
||||
{
|
||||
int i = Find(name);
|
||||
if (i >= 0)
|
||||
{
|
||||
if (_values[i].Value == json) return false;
|
||||
_values[i] = new KeyValuePair<string, string>(name, json);
|
||||
return true;
|
||||
}
|
||||
_values.Add(new KeyValuePair<string, string>(name, json));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string Quote(string s) => "\"" + JsonEncodedText.Encode(s).ToString() + "\"";
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
// account limit, botting policy, its features), the commands it adds, its links, and how to set an
|
||||
// account up for it in the launcher. Render thread only.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
|
@ -24,6 +25,7 @@ internal sealed class ServerPackUi
|
|||
private readonly string _pluginLabel;
|
||||
private readonly Func<string?> _world;
|
||||
private readonly string _windowTitle;
|
||||
private readonly IReadOnlyList<ServerPage> _pages;
|
||||
private string _status = string.Empty;
|
||||
|
||||
/// <summary>The standalone window is open ("/rserver").</summary>
|
||||
|
|
@ -31,21 +33,42 @@ internal sealed class ServerPackUi
|
|||
|
||||
/// <param name="pluginLabel">"RynthColdeve 0.1.0", for the title and the card.</param>
|
||||
/// <param name="world">The world name the client reports now (null when unknown).</param>
|
||||
public ServerPackUi(ServerPackModel model, string pluginLabel, Func<string?> world)
|
||||
/// <param name="pages">The server's own pages: tabs of the window after the card.</param>
|
||||
public ServerPackUi(ServerPackModel model, string pluginLabel, Func<string?> world, IReadOnlyList<ServerPage>? pages = null)
|
||||
{
|
||||
_model = model;
|
||||
_pluginLabel = pluginLabel;
|
||||
_world = world;
|
||||
_pages = pages ?? Array.Empty<ServerPage>();
|
||||
_windowTitle = model.Info.Name + " server (" + pluginLabel + ")##server_" + model.Info.Id;
|
||||
}
|
||||
|
||||
/// <summary>The standalone window, while open.</summary>
|
||||
/// <summary>The standalone window, while open: the card, and the server's pages as tabs when it has some.</summary>
|
||||
public void RenderWindow()
|
||||
{
|
||||
if (!WindowOpen) return;
|
||||
ImGui.SetNextWindowSize(new Vector2(460, 520), ImGuiCond.FirstUseEver);
|
||||
ImGui.SetNextWindowSize(new Vector2(_pages.Count > 0 ? 560 : 460, 520), ImGuiCond.FirstUseEver);
|
||||
bool open = WindowOpen;
|
||||
if (ImGui.Begin(_windowTitle, ref open)) RenderBody();
|
||||
if (ImGui.Begin(_windowTitle, ref open))
|
||||
{
|
||||
if (_pages.Count == 0) RenderBody();
|
||||
else if (ImGui.BeginTabBar("##server_tabs_" + _model.Info.Id))
|
||||
{
|
||||
if (ImGui.BeginTabItem("Server##card"))
|
||||
{
|
||||
RenderBody();
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
foreach (ServerPage page in _pages)
|
||||
{
|
||||
if (!ImGui.BeginTabItem(page.Label + "##page_" + page.Id)) continue;
|
||||
if (ImGui.BeginChild("##page_body_" + page.Id)) page.Draw();
|
||||
ImGui.EndChild();
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
ImGui.EndTabBar();
|
||||
}
|
||||
}
|
||||
ImGui.End();
|
||||
WindowOpen = open;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
engine loads the plugin only for its server) and into RynthPluginInfo (the plugin's own use).
|
||||
|
||||
Server-specific features go in the project as more files, through the partial hooks in
|
||||
ServerPackPlugin.cs (ServerTick, ServerChatCommand, ...), so the shared code stays the same for all.
|
||||
ServerPackPlugin.cs (ServerTick, ServerChatCommand, ServerChatText, ServerPages, ...), so the
|
||||
shared code stays the same for all (the hooks and helpers are listed at the top of that file).
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
|
|
@ -44,6 +45,11 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)..\ImGuiNativeBinding.cs" Link="Shared\ImGuiNativeBinding.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackInfo.cs" Link="ServerPack\ServerPackInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackModel.cs" Link="ServerPack\ServerPackModel.cs" />
|
||||
<!-- The server's own pages, settings file, reply window and Refresh row (ServerPackPlugin.cs lists the hooks). -->
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackPages.cs" Link="ServerPack\ServerPackPages.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackSettings.cs" Link="ServerPack\ServerPackSettings.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerChatRequest.cs" Link="ServerPack\ServerChatRequest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackRefresh.cs" Link="ServerPack\ServerPackRefresh.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackUi.cs" Link="ServerPack\ServerPackUi.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackPlugin.cs" Link="ServerPack\ServerPackPlugin.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ServerPackExports.cs" Link="ServerPack\ServerPackExports.cs" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue