ServerPack: card actions, web open, usage lines #1
4 changed files with 49 additions and 9 deletions
ServerPack: ServerUsageLines, a server's own /rserver usage lines
An optional hook, collected once in the constructor. ServerPackCommands.Usage appends a server's lines (trimmed, blanks dropped) after the shared two, and "/rserver help" and an unknown word print them all. A server without the hook prints exactly the two lines it always has (pinned on Coldeve). ServerProjectsTests.PluginsDir is internal so other tests can share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit
8ceba81070
|
|
@ -46,12 +46,22 @@ internal static class ServerPackCommands
|
||||||
/// <summary>"/rserver [show|hide|toggle]": the window after it.</summary>
|
/// <summary>"/rserver [show|hide|toggle]": the window after it.</summary>
|
||||||
public static string Window(string serverName, bool shown) => CommandReply.Shown($"The {serverName} window", shown);
|
public static string Window(string serverName, bool shown) => CommandReply.Shown($"The {serverName} window", shown);
|
||||||
|
|
||||||
/// <summary>The usage, two lines.</summary>
|
/// <summary>
|
||||||
public static string[] Usage(string serverName) => new[]
|
/// The usage: two lines, then the server's own (ServerUsageLines), if any. With none, the two lines are
|
||||||
|
/// exactly what every server plugin has always printed.
|
||||||
|
/// </summary>
|
||||||
|
public static string[] Usage(string serverName, IReadOnlyList<string>? serverLines = null)
|
||||||
{
|
{
|
||||||
$"/rserver [show|hide|toggle] - the {serverName} server card (also in the Mini Remote's Char section).",
|
var lines = new List<string>
|
||||||
$"/rserver info - what is known about {serverName}; /rserver auto|on|off - this character's override.",
|
{
|
||||||
};
|
$"/rserver [show|hide|toggle] - the {serverName} server card (also in the Mini Remote's Char section).",
|
||||||
|
$"/rserver info - what is known about {serverName}; /rserver auto|on|off - this character's override.",
|
||||||
|
};
|
||||||
|
if (serverLines != null)
|
||||||
|
foreach (string l in serverLines)
|
||||||
|
if (!string.IsNullOrWhiteSpace(l)) lines.Add(l.Trim());
|
||||||
|
return lines.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
public static string Unknown(string word) => $"Unknown '/rserver {word}'.";
|
public static string Unknown(string word) => $"Unknown '/rserver {word}'.";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
// SetProfileValue(key, n) a live number in its "RynthServer.Profile" ("values"), for other
|
// SetProfileValue(key, n) a live number in its "RynthServer.Profile" ("values"), for other
|
||||||
// plugins that apply a server rule without knowing the server.
|
// plugins that apply a server rule without knowing the server.
|
||||||
// ServerCommandVerbs(list) its own "/rserver <verb>" words, handled in ServerChatCommand.
|
// ServerCommandVerbs(list) its own "/rserver <verb>" words, handled in ServerChatCommand.
|
||||||
|
// ServerUsageLines(add) the usage lines for those words, after the shared two (help, unknown word).
|
||||||
// RunOnTick(action) work for the next tick (a page's button, on the render thread).
|
// RunOnTick(action) work for the next tick (a page's button, on the render thread).
|
||||||
// ServerCardActions() the server's own buttons at the top of its card, under RynthCore's verdict
|
// ServerCardActions() the server's own buttons at the top of its card, under RynthCore's verdict
|
||||||
// (render thread: ImGui calls only; queue work with RunOnTick).
|
// (render thread: ImGui calls only; queue work with RunOnTick).
|
||||||
|
|
@ -87,6 +88,8 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
||||||
private readonly ConcurrentQueue<Action> _tickActions = new();
|
private readonly ConcurrentQueue<Action> _tickActions = new();
|
||||||
// The server's own "/rserver" verbs (ServerCommandVerbs).
|
// The server's own "/rserver" verbs (ServerCommandVerbs).
|
||||||
private readonly HashSet<string> _serverVerbs = new(StringComparer.OrdinalIgnoreCase);
|
private readonly HashSet<string> _serverVerbs = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
// The server's own "/rserver" usage lines (ServerUsageLines), after the shared two.
|
||||||
|
private readonly List<string> _usageLines = new();
|
||||||
private volatile bool _loginComplete;
|
private volatile bool _loginComplete;
|
||||||
private volatile string? _world;
|
private volatile string? _world;
|
||||||
private bool _wasActive;
|
private bool _wasActive;
|
||||||
|
|
@ -104,6 +107,7 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
||||||
var verbs = new List<string>();
|
var verbs = new List<string>();
|
||||||
ServerCommandVerbs(verbs);
|
ServerCommandVerbs(verbs);
|
||||||
foreach (string v in verbs) if (!string.IsNullOrWhiteSpace(v)) _serverVerbs.Add(v.Trim());
|
foreach (string v in verbs) if (!string.IsNullOrWhiteSpace(v)) _serverVerbs.Add(v.Trim());
|
||||||
|
ServerUsageLines(_usageLines.Add);
|
||||||
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages, DrawCardActions);
|
_ui = new ServerPackUi(_model, RynthPluginInfo.Name + " " + Marshal.PtrToStringAnsi(VersionPointer), () => _world, _pages, DrawCardActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,6 +139,11 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
||||||
/// instead of being read as another server's id. Called once, from the constructor.
|
/// instead of being read as another server's id. Called once, from the constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
partial void ServerCommandVerbs(List<string> verbs);
|
partial void ServerCommandVerbs(List<string> verbs);
|
||||||
|
/// <summary>
|
||||||
|
/// Usage lines for the server's own verbs, printed after the shared two by "/rserver help" and an
|
||||||
|
/// unknown word. Called once, from the constructor (no Host yet).
|
||||||
|
/// </summary>
|
||||||
|
partial void ServerUsageLines(Action<string> add);
|
||||||
/// <summary>Extra lines for "/rserver info".</summary>
|
/// <summary>Extra lines for "/rserver info".</summary>
|
||||||
partial void ServerInfoLines(Action<string> line);
|
partial void ServerInfoLines(Action<string> line);
|
||||||
/// <summary>The server's own pages (ServerPackPages.cs). Called once, from the constructor (no Host yet).</summary>
|
/// <summary>The server's own pages (ServerPackPages.cs). Called once, from the constructor (no Host yet).</summary>
|
||||||
|
|
@ -475,9 +484,10 @@ public sealed partial class ServerPackPlugin : RynthPluginBase
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
ServerChatCommand(parts, ref handled);
|
ServerChatCommand(parts, ref handled);
|
||||||
if (handled) return;
|
if (handled) return;
|
||||||
if (verb == ServerVerb.Unknown) Reply.Fail(ServerPackCommands.Unknown(parts[1]) + " " + ServerPackCommands.Usage(Info.Name)[0]);
|
string[] usage = ServerPackCommands.Usage(Info.Name, _usageLines);
|
||||||
else ChatLine(ServerPackCommands.Usage(Info.Name)[0]);
|
if (verb == ServerVerb.Unknown) Reply.Fail(ServerPackCommands.Unknown(parts[1]) + " " + usage[0]);
|
||||||
ChatLine(ServerPackCommands.Usage(Info.Name)[1]);
|
else ChatLine(usage[0]);
|
||||||
|
for (int i = 1; i < usage.Length; i++) ChatLine(usage[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrintInfo()
|
private void PrintInfo()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using RynthCore.Plugin.ServerPack;
|
using RynthCore.Plugin.ServerPack;
|
||||||
using RynthCore.Plugin.Shared;
|
using RynthCore.Plugin.Shared;
|
||||||
using RynthCore.RynthAiTests.Harness;
|
using RynthCore.RynthAiTests.Harness;
|
||||||
|
|
@ -50,6 +51,25 @@ internal static class ServerPackCommandsTests
|
||||||
Check.Eq(usage.Length, 2, "two usage lines");
|
Check.Eq(usage.Length, 2, "two usage lines");
|
||||||
Check.True(usage[0].Contains("/rserver [show|hide|toggle]") && usage[1].Contains("/rserver auto|on|off"), "the usage names every verb");
|
Check.True(usage[0].Contains("/rserver [show|hide|toggle]") && usage[1].Contains("/rserver auto|on|off"), "the usage names every verb");
|
||||||
Check.Eq(ServerPackCommands.Unknown("wobble"), "Unknown '/rserver wobble'.", "an unknown word");
|
Check.Eq(ServerPackCommands.Unknown("wobble"), "Unknown '/rserver wobble'.", "an unknown word");
|
||||||
|
|
||||||
|
// A server without ServerUsageLines (Coldeve) prints exactly the two shared lines, byte for byte.
|
||||||
|
string[] pinned =
|
||||||
|
{
|
||||||
|
"/rserver [show|hide|toggle] - the Coldeve server card (also in the Mini Remote's Char section).",
|
||||||
|
"/rserver info - what is known about Coldeve; /rserver auto|on|off - this character's override.",
|
||||||
|
};
|
||||||
|
Check.Eq(string.Join("\n", usage), string.Join("\n", pinned), "hookless usage is unchanged");
|
||||||
|
Check.Eq(string.Join("\n", ServerPackCommands.Usage("Coldeve", new List<string>())), string.Join("\n", pinned), "no own lines: unchanged");
|
||||||
|
Check.Eq(string.Join("\n", ServerPackCommands.Usage("Coldeve", new List<string> { "", " " })), string.Join("\n", pinned), "blank own lines are dropped");
|
||||||
|
string coldeve = string.Join("\n", System.IO.Directory.GetFiles(System.IO.Path.Combine(ServerProjectsTests.PluginsDir(), "RynthCore.Plugin.RynthColdeve"), "*.cs", System.IO.SearchOption.AllDirectories)
|
||||||
|
.Where(f => !f.Contains("\\obj\\") && !f.Contains("\\bin\\")).Select(System.IO.File.ReadAllText));
|
||||||
|
Check.False(coldeve.Contains("ServerUsageLines", StringComparison.Ordinal), "Coldeve has no ServerUsageLines (so the pin above is what it prints)");
|
||||||
|
|
||||||
|
// A server's own lines follow the shared two, which stay first and unchanged.
|
||||||
|
string[] own = ServerPackCommands.Usage("Coldeve", new List<string> { " /rserver x - one more line " });
|
||||||
|
Check.Eq(own.Length, 3, "an own line is appended");
|
||||||
|
Check.Eq(own[2], "/rserver x - one more line", "trimmed");
|
||||||
|
Check.True(own[0] == pinned[0] && own[1] == pinned[1], "the shared two come first, unchanged");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Queue()
|
private static void Queue()
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ internal static class ServerProjectsTests
|
||||||
"levistras",
|
"levistras",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static string PluginsDir()
|
internal static string PluginsDir()
|
||||||
{
|
{
|
||||||
string? dir = AppContext.BaseDirectory;
|
string? dir = AppContext.BaseDirectory;
|
||||||
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
|
while (dir != null && !Directory.Exists(Path.Combine(dir, "Plugins", "Shared", "ServerPack")))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue